Skip to content

Commit 7bd5524

Browse files
authored
fix(db): deterministic per-file search_path in migration runner (#112)
Found by the wizard's fresh-project e2e: the pg_dump baseline empties the session `search_path` (its own statements are fully qualified), and because migration files share one connection, 0001's unqualified `v2_entitlements` reference failed on a fresh project. Production never executed the baseline (ledgered), so this only bites fresh installs. One line in the runner: `SET LOCAL search_path = public, pg_catalog` at the top of each per-file transaction — deterministic environment per file, reverted at commit. ## Verification notes - [x] `pnpm lint` / `pnpm typecheck` / `pnpm turbo build --force` / `pnpm deadcode` / `pnpm architecture:check` - Post-merge: wizard resume on the half-migrated fresh project (0000 ledgered, 0001-0003 pending) must complete 0001→0003 + target assertion — the exact failed scenario.
1 parent 13a8f2f commit 7bd5524

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

packages/db/src/drizzle-migrations.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ async function applyDrizzleMigration(
4242
): Promise<void> {
4343
await client.query("begin");
4444
try {
45+
// Migration files share one session, and the pg_dump baseline empties the
46+
// session search_path for correctness of its own qualified statements.
47+
// Give every file a deterministic search_path scoped to its transaction so
48+
// no file inherits another file's session mutations.
49+
await client.query("set local search_path = public, pg_catalog");
4550
for (const statement of migration.statements) {
4651
if (statement.trim()) {
4752
await client.query(statement);

0 commit comments

Comments
 (0)