diff --git a/server/src/db/engine/postgres/sqlite-move/catalog.ts b/server/src/db/engine/postgres/sqlite-move/catalog.ts index 129d3427c..a9018914d 100644 --- a/server/src/db/engine/postgres/sqlite-move/catalog.ts +++ b/server/src/db/engine/postgres/sqlite-move/catalog.ts @@ -52,11 +52,15 @@ export async function readTargetSchema(trx: Trx): Promise { "where c.connamespace = current_schema()::regnamespace and c.contype in ('p', 'f') " + 'group by c.oid, c.contype, src.relname, dst.relname', ); + // The name handed to pg_get_serial_sequence carries its schema: Postgres may evaluate the call before the + // table_schema filter, on rows of information_schema itself, whose bare names do not resolve. const sequences = await run<{ table_name: string; column_name: string; sequence: string }>( trx, - "select table_name, column_name, pg_get_serial_sequence(format('%I', table_name), column_name) as sequence " + + 'select table_name, column_name, ' + + "pg_get_serial_sequence(format('%I.%I', table_schema, table_name), column_name) as sequence " + 'from information_schema.columns where table_schema = current_schema() ' + - "and pg_get_serial_sequence(format('%I', table_name), column_name) is not null order by table_name, column_name", + "and pg_get_serial_sequence(format('%I.%I', table_schema, table_name), column_name) is not null " + + 'order by table_name, column_name', ); // A unique constraint is backed by an index of its name, so the index names what a refusal reports. Its key diff --git a/server/tests/helpers/fake-postgres-move.ts b/server/tests/helpers/fake-postgres-move.ts index 4b0a1eb0e..4bbe268b4 100644 --- a/server/tests/helpers/fake-postgres-move.ts +++ b/server/tests/helpers/fake-postgres-move.ts @@ -153,7 +153,7 @@ export class FakePostgres { })), ]); } - if (sql.includes("pg_get_serial_sequence(format('%I'")) { + if (sql.includes("pg_get_serial_sequence(format('%I.%I'")) { return this.schema.flatMap((table) => (table.serial ?? []).map((column) => ({ table_name: table.name,