/** * Standalone DB migration runner used in Docker / HF Spaces startup. * Pulls SQLite schema via drizzle-kit push then ensures the DB is up to date. * Called by the Dockerfile CMD before the Express server boots. */ import { execSync } from "child_process"; import path from "path"; import { fileURLToPath } from "url"; const __dirname = path.dirname(fileURLToPath(import.meta.url)); const dbPath = process.env.DB_PATH || "/data/raqim.db"; const drizzleConfig = path.join(__dirname, "../lib/db/drizzle.config.ts"); console.log("[migrate] Running schema push to:", dbPath); console.log("[migrate] Config:", drizzleConfig); try { execSync( `npx drizzle-kit push --config "${drizzleConfig}"`, { stdio: "inherit", env: { ...process.env, DB_PATH: dbPath }, cwd: path.join(__dirname, ".."), } ); console.log("[migrate] ✓ Schema up to date."); } catch (err) { console.error("[migrate] ✗ Migration failed:", err.message); process.exit(1); }