Skip to content

Commit

Permalink
Handle another error code when concurrently creating the migrations h…
Browse files Browse the repository at this point in the history
…istory table (#3301)
  • Loading branch information
roji authored Sep 27, 2024
1 parent d316b35 commit 58608e8
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/EFCore.PG/Migrations/Internal/NpgsqlHistoryRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ bool IHistoryRepository.CreateIfNotExists()
GetCreateIfNotExistsCommands(), Dependencies.Connection, new MigrationExecutionState(), commitTransaction: true)
!= 0;
}
catch (PostgresException e) when (e.SqlState is "23505" or "42P07")
catch (PostgresException e) when (e.SqlState is PostgresErrorCodes.UniqueViolation
or PostgresErrorCodes.DuplicateTable
or PostgresErrorCodes.DuplicateObject)
{
return false;
}
Expand All @@ -116,7 +118,9 @@ async Task<bool> IHistoryRepository.CreateIfNotExistsAsync(CancellationToken can
cancellationToken: cancellationToken).ConfigureAwait(false))
!= 0;
}
catch (PostgresException e) when (e.SqlState is "23505" or "42P07")
catch (PostgresException e) when (e.SqlState is PostgresErrorCodes.UniqueViolation
or PostgresErrorCodes.DuplicateTable
or PostgresErrorCodes.DuplicateObject)
{
return false;
}
Expand Down Expand Up @@ -192,7 +196,7 @@ public override IReadOnlyList<HistoryRow> GetAppliedMigrations()
{
return base.GetAppliedMigrations();
}
catch (PostgresException e) when (e.SqlState is "3D000" or "42P01")
catch (PostgresException e) when (e.SqlState is PostgresErrorCodes.InvalidCatalogName or PostgresErrorCodes.UndefinedTable)
{
return [];
}
Expand All @@ -210,7 +214,7 @@ public override async Task<IReadOnlyList<HistoryRow>> GetAppliedMigrationsAsync(
{
return await base.GetAppliedMigrationsAsync(cancellationToken).ConfigureAwait(false);
}
catch (PostgresException e) when (e.SqlState is "3D000" or "42P01")
catch (PostgresException e) when (e.SqlState is PostgresErrorCodes.InvalidCatalogName or PostgresErrorCodes.UndefinedTable)
{
return [];
}
Expand Down

0 comments on commit 58608e8

Please sign in to comment.