migrate-cli.js (749B)
1 // src/lib/db/migrate-cli.js - apply pending migrations 2 // 3 // Usage: npm run migrate 4 // 5 // The conductor also migrates on startup. This exists for deployments that 6 // want the schema change to be a separate, reviewable step. 7 8 import { loadConfig, ensureStateDirs } from '../config.js'; 9 import { openDatabase } from './index.js'; 10 import { runMigrations } from './migrate.js'; 11 12 const cfg = loadConfig(); 13 ensureStateDirs(cfg); 14 15 const db = await openDatabase(cfg); 16 try { 17 console.log(`[migrate] dialect ${db.dialect}`); 18 const result = await runMigrations(db); 19 if (result.applied.length === 0) console.log('[migrate] nothing to do'); 20 } catch (e) { 21 console.error(`[migrate] ${e.message}`); 22 process.exitCode = 1; 23 } finally { 24 await db.close(); 25 }