Add development command to reset the database and rerun migrations

This commit is contained in:
2026-01-24 15:12:11 -06:00
parent 960f78a1ad
commit 474420ac1e
4 changed files with 93 additions and 3 deletions

View File

@@ -137,6 +137,8 @@ async function runMigration(filename: string): Promise<void> {
const filepath = path.join(MIGRATIONS_DIR, filename);
const content = fs.readFileSync(filepath, "utf-8");
process.stdout.write(` Migration: ${filename}...`);
// Run migration in a transaction
const client = await pool.connect();
try {
@@ -147,8 +149,11 @@ async function runMigration(filename: string): Promise<void> {
[filename],
);
await client.query("COMMIT");
console.log(`Applied migration: ${filename}`);
console.log(" ✓");
} catch (err) {
console.log(" ✗");
const message = err instanceof Error ? err.message : String(err);
console.error(` Error: ${message}`);
await client.query("ROLLBACK");
throw err;
} finally {
@@ -169,11 +174,10 @@ async function migrate(): Promise<void> {
return;
}
console.log(`Running ${pending.length} migration(s)...`);
console.log(`Applying ${pending.length} migration(s):`);
for (const file of pending) {
await runMigration(file);
}
console.log("Migrations complete");
}
// List migration status