Skip to content

Call Npgsql's ReloadTypes as needed from programmatic Migrate()#2951

Merged
roji merged 1 commit intonpgsql:mainfrom
roji:ReloadTypes
Nov 16, 2023
Merged

Call Npgsql's ReloadTypes as needed from programmatic Migrate()#2951
roji merged 1 commit intonpgsql:mainfrom
roji:ReloadTypes

Conversation

@roji
Copy link
Member

@roji roji commented Nov 16, 2023

Closes #292

/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public override void Migrate(string? targetMigration = null)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bricelam look at this lovely thing... I refused to override Migrator for years (because it's internal) but I finally did it.

Basically certain AlterDatabaseOperations create new PG types in the database (e.g. when you add an extension), and then if you're applying migrations within the process with Migrate(), you need to tell Npgsql to reload the types at the ADO.NET layer. This has been implemented cleanly for a long time in NpgsqlDatabaseCreator (so EnsuredCreated worked), but not Migrate().

Ideally there would be some hooks after the migrations are applied, which would be called both from EnsureCreated() and Migrate(); they'd need to receive the migration operations in order to inspect them etc. Here I have to calculate the applied migrations and the ones to be applied (so once here just for this reload, once in Migrator for real).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like a good scenario we should cover as part of dotnet/efcore#24710

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Types not being reloaded properly after adding extension and running Migrate()

2 participants