import dataSource from "./data-source"; /** * Applies pending migrations to the database at DB_PATH, then exits. Runs * before the server in the Docker image (`node dist/database/migrate`). */ async function migrate(): Promise { await dataSource.initialize(); try { const applied = await dataSource.runMigrations({ transaction: "each" }); console.log( applied.length > 0 ? `Applied ${applied.length} migration(s): ${applied.map((m) => m.name).join(", ")}` : "Database schema is up to date", ); } finally { await dataSource.destroy(); } } migrate().catch((err: unknown) => { console.error("Migration failed:", err); process.exit(1); });