fix(datacopy): pg_get_serial_sequence takes 1 arg (regclass), not table+column

This commit is contained in:
2026-10-10 00:58:27 +03:30
parent 5cd80dbf34
commit f58c14511b

View File

@@ -168,12 +168,11 @@ internal static class Program
var max = (int)(await ScalarAsync(pg, $"SELECT COALESCE(MAX(\"{pkName}\"), 0) FROM \"{table}\""))!;
if (max > 0)
{
// Keep the identity sequence above the copied max so new rows don't collide
// %I quotes each identifier so pg_get_serial_sequence keeps the
// exact case EF created the table/column with (unquoted literals
// get folded to lowercase -> 42P01 "relation does not exist")
// Keep the identity sequence above the copied max so new rows don't collide.
// pg_get_serial_sequence takes one regclass; %I keeps the exact case EF
// used (unquoted literals fold to lowercase -> 42P01)
await target.Database.ExecuteSqlRawAsync(
$"SELECT setval(pg_get_serial_sequence(format('%I.%I', '{table}', '{pkName}')), {max})");
$"SELECT setval(pg_get_serial_sequence(format('%I', '{table}')), {max})");
}
Console.WriteLine($"\n[done ] {table}: copied={copied}, maxId={max}");
}