Apply pending migrations during development reloads

This commit is contained in:
syntaxbullet
2026-09-04 19:01:16 +02:00
parent 865bdd1328
commit 392deb9cbe
3 changed files with 65 additions and 2 deletions

View File

@@ -6,6 +6,13 @@ import { createApi } from "./api";
import { readAuthConfig } from "./auth/config";
import { readDiscordSharingConfig } from "./sharing/config";
import index from "./index.html";
import { migrate } from "drizzle-orm/bun-sqlite/migrator";
// Hot reloads skip the package script's migration step. Apply pending changes
// before the reloaded development server accepts requests.
if (process.env.NODE_ENV !== "production") {
migrate(db, { migrationsFolder: "./drizzle" });
}
const backups = process.env.NODE_ENV === "production" ? startBackups(sqlite, backupConfig(databasePath)) : undefined;
if (import.meta.hot) import.meta.hot.dispose(() => backups?.stop());