feat: refactor migration handling to ensure server waits for database migrations before starting

This commit is contained in:
Daniel Volz
2025-12-20 21:14:43 +01:00
parent 258c90a52c
commit 1c9950d29f
2 changed files with 8 additions and 3 deletions
+5
View File
@@ -10,6 +10,7 @@ import fastifyStatic from "@fastify/static";
import { resolve } from "path";
import { existsSync, mkdirSync } from "fs";
import { env } from "./plugins/env.js";
import { migrationsReady } from "./db/client.js";
import { healthRoutes } from "./routes/health.js";
import { authRoutes } from "./routes/auth.js";
import { medicationRoutes } from "./routes/medications.js";
@@ -17,6 +18,10 @@ import { settingsRoutes } from "./routes/settings.js";
import { plannerRoutes } from "./routes/planner.js";
import { startReminderScheduler } from "./services/reminder-scheduler.js";
// Wait for database migrations before anything else
await migrationsReady;
console.log("[DB] Migrations complete, starting server...");
// Ensure images directory exists
const imagesDir = resolve(process.cwd(), "data/images");
if (!existsSync(imagesDir)) {