46 lines
1.3 KiB
TypeScript
46 lines
1.3 KiB
TypeScript
// migrate.ts
|
|
// CLI script for running database migrations
|
|
|
|
import { migrate, migrationStatus, pool } from "./database";
|
|
|
|
async function main(): Promise<void> {
|
|
const command = process.argv[2] || "run";
|
|
|
|
try {
|
|
switch (command) {
|
|
case "run":
|
|
await migrate();
|
|
break;
|
|
|
|
case "status": {
|
|
const status = await migrationStatus();
|
|
console.log("Applied migrations:");
|
|
for (const name of status.applied) {
|
|
console.log(` ✓ ${name}`);
|
|
}
|
|
if (status.pending.length > 0) {
|
|
console.log("\nPending migrations:");
|
|
for (const name of status.pending) {
|
|
console.log(` • ${name}`);
|
|
}
|
|
} else {
|
|
console.log("\nNo pending migrations");
|
|
}
|
|
break;
|
|
}
|
|
|
|
default:
|
|
console.error(`Unknown command: ${command}`);
|
|
console.error("Usage: migrate [run|status]");
|
|
process.exit(1);
|
|
}
|
|
} finally {
|
|
await pool.end();
|
|
}
|
|
}
|
|
|
|
main().catch((err) => {
|
|
console.error("Migration failed:", err);
|
|
process.exit(1);
|
|
});
|