fix(GRO-2672): use drizzle-kit migrate in reset.ts (dev→uat) #229

Merged
Flea Flicker merged 1 commits from dev into uat 2026-08-06 09:33:46 +00:00
+11 -4
View File
@@ -32,7 +32,7 @@
*/ */
import postgres from "postgres"; import postgres from "postgres";
import { drizzle } from "drizzle-orm/postgres-js"; 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 { fileURLToPath } from "node:url";
import { dirname, resolve } from "node:path"; import { dirname, resolve } from "node:path";
import * as schema from "./schema.js"; import * as schema from "./schema.js";
@@ -46,7 +46,6 @@ import {
const __filename = fileURLToPath(import.meta.url); const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename); const __dirname = dirname(__filename);
const MIGRATIONS_FOLDER = resolve(__dirname, "../migrations");
async function reset() { async function reset() {
const url = process.env.DATABASE_URL; const url = process.env.DATABASE_URL;
@@ -73,7 +72,7 @@ async function reset() {
// across processes regardless of how many connections the work uses — // across processes regardless of how many connections the work uses —
// it does NOT require the work to share the lock's session. // 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 // the work. `max: 1` would let `reserve()` consume the only connection
// and every query inside the callback would block forever waiting for // and every query inside the callback would block forever waiting for
// a connection that never frees (connection-starvation deadlock). We // 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("✓ All tables and enums dropped\n");
console.log("Running migrations..."); 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("✓ Migrations applied\n");
console.log("Seeding database..."); console.log("Seeding database...");