File size: 987 Bytes
0e14acb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/**
 * 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);
}