feat: implement UI-driven database configuration

This commit is contained in:
Michael committed 2026-02-21 12:09:21 +01:00
1 parent e54e679bd4
commit 0e4c276816
4 files changed
+248 -17

No files matched your search

+18 -2
View File
@@ -1,10 +1,26 @@
import { drizzle } from "drizzle-orm/pg-proxy"; // Or node-postgres if using directly
import { drizzle as nodeDrizzle } from "drizzle-orm/node-postgres";
import { Pool } from "pg";
import * as schema from "./schema";
import fs from "fs";
import path from "path";
let connectionString = process.env.DATABASE_URL;
// On tente de lire la config sauvegardée via l'UI
try {
const CONFIG_PATH = path.join(process.cwd(), ".db-config.json");
if (fs.existsSync(CONFIG_PATH)) {
const config = JSON.parse(fs.readFileSync(CONFIG_PATH, "utf-8"));
if (config.url) {
connectionString = config.url;
}
}
} catch (err) {
console.error("Error reading database config file:", err);
}
const pool = new Pool({
connectionString: process.env.DATABASE_URL,
connectionString,
});
export const db = nodeDrizzle(pool, { schema });