efcore.pg icon indicating copy to clipboard operation
efcore.pg copied to clipboard

Migrations called twice

Open depler opened this issue 6 months ago • 3 comments

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

depler avatar Dec 25 '23 14:12 depler