fix(db): migrator introspects only the target schema

Kysely's Migrator checks for its tables via introspection.getTables(),
which reflects every schema and calls has_schema_privilege /
pg_get_serial_sequence per schema. When another test file drops its schema
at the same moment those functions fail with "schema … does not exist" —
the intermittent server PG test failures on the shared dev database.
createMigrator now hands the Migrator a proxy whose introspection only
looks at the migration schema (or current_schema()). A regression test
churns schemas while migrating; it fails on the old migrator.

Also samples EngineRunQuery's comma-separated status/triggeredBy in the
contracts schema test.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
rootandClaude Opus 5.5 committed 2026-09-28 17:15:04 +08:00
1 parent 082c556a67
commit f6063af12d
3 files changed
+70 -2

No files matched your search

+21
View File
@@ -384,4 +384,25 @@ describe.skipIf(skip)("schema migrations (real PG)", () => {
expect(up.error).toBeUndefined();
expect(await tables()).toEqual(EXPECTED_TABLES);
}, 60_000);
it("迁移器只内省目标 schema:别处同时建删 schema 不影响(并行测试共用库)", async () => {
const migrator = createMigrator(db, { migrationTableSchema: schema });
let stop = false;
const churn = (async () => {
for (let i = 0; !stop && i < 200; i++) {
const tmp = `${schema}_churn_${i}`;
await sql.raw(`create schema ${tmp}; create table ${tmp}.t (id serial primary key)`).execute(admin);
await sql.raw(`drop schema ${tmp} cascade`).execute(admin);
}
})();
try {
for (let i = 0; i < 20; i++) {
const r = await migrator.migrateToLatest();
expect(r.error).toBeUndefined();
}
} finally {
stop = true;
await churn;
}
}, 60_000);
});