From 2f7b8357cec8cbc48e71ccdb8a8288ae169c7896 Mon Sep 17 00:00:00 2001 From: Maurice Date: Sat, 21 Nov 2026 11:30:06 +0100 Subject: [PATCH] fix(server): schema-qualify the table the move asks Postgres for its sequence Server Postgres 18 3/3 was red on dev: PGMOVENUL-007 failed with relation "information_schema_catalog_name" does not exist. readTargetSchema called pg_get_serial_sequence(format('%I', table_name), ...) over information_schema.columns, and Postgres does not promise to apply the table_schema filter first, so the call could see rows of information_schema itself, whose bare names do not resolve on the search path. The name now carries its schema, so the call answers for every row whatever the plan. The fake Postgres of the move tests matches the new text. --- server/src/db/engine/postgres/sqlite-move/catalog.ts | 8 ++++++-- server/tests/helpers/fake-postgres-move.ts | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) 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,