From f58c14511b1ab0fab0eb48797a24fac28cb280ed Mon Sep 17 00:00:00 2001 From: alireza Date: Sat, 10 Oct 2026 00:58:27 +0330 Subject: [PATCH] fix(datacopy): pg_get_serial_sequence takes 1 arg (regclass), not table+column --- src/GreenHome.DataCopy/Program.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/GreenHome.DataCopy/Program.cs b/src/GreenHome.DataCopy/Program.cs index 66b8c31..aa7ee17 100644 --- a/src/GreenHome.DataCopy/Program.cs +++ b/src/GreenHome.DataCopy/Program.cs @@ -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}"); }