Migrations called twice
NpgsqlMigrator.cs contains method MigrateAsync with following code:
await base.MigrateAsync(targetMigration, cancellationToken).ConfigureAwait(false);
...
var reloadTypes = migrations
.SelectMany(m => m.UpOperations)
.OfType<AlterDatabaseOperation>()
.Any(o => o.GetPostgresExtensions().Any() || o.GetPostgresEnums().Any() || o.GetPostgresRanges().Any());
Access to m.UpOperations forces to call BuildOperations:
public virtual IReadOnlyList<MigrationOperation> UpOperations
=> _upOperations ??= BuildOperations(Up);
So all migrations will call Up() - that would second call for each migration, because MigrateAsync is already called in the beginning. This logic can potentially break some migrations, if they relying on "call once" logic
the same issue reported below: https://github.com/dotnet/efcore/issues/33279
@depler thanks for reporting... This code was introduced in #2951 to make trigger type reloading after new types are created in the database.
Let's have this looked at on the EF side to see how best to solve it.
Until fix, if you need a work around you can do that for each migration scripts:
public partial class InitPostGre : Migration
{
static bool alreadyExecuted = false;
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
if (alreadyExecuted) return;
alreadyExecuted = true;