Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix serial to identity in idempotent migrations #1479

Merged
merged 2 commits into from
Aug 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/EFCore.PG/Migrations/NpgsqlMigrationsSqlGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,10 @@ protected override void Generate(AlterColumnOperation operation, IModel model, M
.AppendLine($"ALTER SEQUENCE {sequence} RENAME TO {oldSequenceWithoutSchema};")
.AppendLine($"{alterBase}DROP DEFAULT;")
.AppendLine($"{alterBase}ADD GENERATED {identityTypeClause} AS IDENTITY;")
.AppendLine($"SELECT * FROM setval('{sequence}', nextval('{oldSequence}'), false);")
// When generating idempotent scripts, migration DDL is enclosed in anonymous DO blocks,
// where PERFORM must be used instead of SELECT
.Append(Options.HasFlag(MigrationsSqlGenerationOptions.Idempotent) ? "PERFORM" : "SELECT")
.AppendLine($" * FROM setval('{sequence}', nextval('{oldSequence}'), false);")
.AppendLine($"DROP SEQUENCE {oldSequence};");
break;
default:
Expand Down
Loading