diff --git a/packages/db/src/reset.ts b/packages/db/src/reset.ts index fb88e20..7f12970 100644 --- a/packages/db/src/reset.ts +++ b/packages/db/src/reset.ts @@ -32,7 +32,7 @@ */ import postgres from "postgres"; import { drizzle } from "drizzle-orm/postgres-js"; -import { migrate } from "drizzle-orm/postgres-js/migrator"; +import { execSync } from "node:child_process"; import { fileURLToPath } from "node:url"; import { dirname, resolve } from "node:path"; import * as schema from "./schema.js"; @@ -46,7 +46,6 @@ import { const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); -const MIGRATIONS_FOLDER = resolve(__dirname, "../migrations"); async function reset() { const url = process.env.DATABASE_URL; @@ -73,7 +72,7 @@ async function reset() { // across processes regardless of how many connections the work uses — // it does NOT require the work to share the lock's session. // - // Therefore `max` must be ≥ 2: 1 reserved for the lock + ≥1 free for + // Therefore `max` must be >= 2: 1 reserved for the lock + >=1 free for // the work. `max: 1` would let `reserve()` consume the only connection // and every query inside the callback would block forever waiting for // a connection that never frees (connection-starvation deadlock). We @@ -122,7 +121,15 @@ async function reset() { console.log("✓ All tables and enums dropped\n"); console.log("Running migrations..."); - await migrate(db, { migrationsFolder: MIGRATIONS_FOLDER }); + // GRO-2672: drizzle-orm's migrate() has a high-water-mark bug that skips + // migrations with stale `when` timestamps (0001, 0003, 0010, 0011). Use + // drizzle-kit instead -- it applies migrations by hash, matching the K8s + // migrate Job behaviour exactly. + execSync("pnpm exec drizzle-kit migrate", { + stdio: "inherit", + env: { ...process.env }, + cwd: resolve(__dirname, ".."), + }); console.log("✓ Migrations applied\n"); console.log("Seeding database...");