Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

fix(server): schema-qualify the table the move asks Postgres for its sequence

Maurice2f7b8357cec8
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<TargetSchema> {
"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,