feat: automate verified SQLite backups and safe recovery

This commit is contained in:
syntaxbullet
2026-09-04 18:28:28 +02:00
parent 32002151e0
commit 661bc6c346
10 changed files with 227 additions and 2 deletions

View File

@@ -1,7 +1,13 @@
import { backupConfig, createBackup } from "../src/ops/backups";
import { databasePath } from "../src/db/config";
import { migrate } from "drizzle-orm/bun-sqlite/migrator";
import { db, sqlite } from "../src/db";
try {
if (process.env.NODE_ENV === "production" && sqlite.query("SELECT name FROM sqlite_master WHERE name = 'habits'").get()) {
// Fail before migrations if the safety snapshot cannot be created.
createBackup(sqlite, backupConfig(databasePath));
}
migrate(db, { migrationsFolder: "./drizzle" });
console.log("Database migrations applied.");
} finally {