Call Npgsql's ReloadTypes as needed from programmatic Migrate()#2951
Call Npgsql's ReloadTypes as needed from programmatic Migrate()#2951roji merged 1 commit intonpgsql:mainfrom
Conversation
| /// 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) |
There was a problem hiding this comment.
@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).
There was a problem hiding this comment.
Sounds like a good scenario we should cover as part of dotnet/efcore#24710
Closes #292