All checks were successful
Validation applicative / TypeScript, tests et build (push) Successful in 4m45s
25 lines
834 B
TypeScript
25 lines
834 B
TypeScript
import { migrate } from "drizzle-orm/mysql2/migrator";
|
|
import { drizzle } from "drizzle-orm/mysql2";
|
|
import { createPool } from "mysql2/promise";
|
|
|
|
/**
|
|
* Synchronise la base avec les migrations versionnées avant d'exposer l'API.
|
|
* Une base sans DATABASE_URL reste utilisable en développement statique, mais
|
|
* un déploiement connecté échoue explicitement si la migration ne peut aboutir.
|
|
*/
|
|
export async function runDatabaseMigrations() {
|
|
const databaseUrl = process.env.DATABASE_URL;
|
|
if (!databaseUrl) {
|
|
console.warn("[Database] DATABASE_URL absent : migrations ignorées.");
|
|
return;
|
|
}
|
|
|
|
const pool = createPool(databaseUrl);
|
|
try {
|
|
await migrate(drizzle(pool), { migrationsFolder: "./drizzle" });
|
|
console.log("[Database] Migrations Drizzle synchronisées.");
|
|
} finally {
|
|
await pool.end();
|
|
}
|
|
}
|