Skip to content

Commit

Permalink
Use alter and rename commands when migrating primary key constraint n…
Browse files Browse the repository at this point in the history
…ames
  • Loading branch information
tonykaralis authored and oskardudycz committed Oct 24, 2021
1 parent 2527dea commit 5a73995
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Weasel.Postgresql/Tables/TableDelta.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ public override void WriteUpdate(DdlRules rules, TextWriter writer)
{
case SchemaPatchDifference.Invalid:
case SchemaPatchDifference.Update:
if (Expected.PrimaryKeyColumns.SequenceEqual(Actual?.PrimaryKeyColumns))
{
//for when PK constraint name changes only
writer.WriteLine($"alter table {Expected.Identifier} rename constraint {Actual!.PrimaryKeyName} to {Expected.PrimaryKeyName};");
break;
}
writer.WriteLine($"alter table {Expected.Identifier} drop constraint {Actual!.PrimaryKeyName};");
writer.WriteLine($"alter table {Expected.Identifier} add {Expected.PrimaryKeyDeclaration()};");
break;
Expand Down

0 comments on commit 5a73995

Please sign in to comment.