mirror of
https://github.com/R0m1k3/CollectFlow.git
synced 2026-10-18 12:46:32 +02:00
feat: implement UI-driven database configuration
This commit is contained in:
1 parent
e54e679bd4
commit
0e4c276816
4 files changed
+248
-17
No files matched your search
+18
-2
@@ -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 });
|
||||
Reference in new issue
Block a user