diff --git a/backend/db/index.ts b/backend/db/index.ts index eeb9f5b..20dc9c7 100644 --- a/backend/db/index.ts +++ b/backend/db/index.ts @@ -1,10 +1,11 @@ import { drizzle } from "drizzle-orm/node-postgres" import { Pool } from "pg" import {secrets} from "../src/utils/secrets"; +import * as schema from "./schema" const pool = new Pool({ connectionString: secrets.DATABASE_URL, max: 10, // je nach Last }) -export const db = drizzle(pool) \ No newline at end of file +export const db = drizzle(pool , {schema}) \ No newline at end of file diff --git a/backend/drizzle.config.ts b/backend/drizzle.config.ts index d2b0225..f0a8843 100644 --- a/backend/drizzle.config.ts +++ b/backend/drizzle.config.ts @@ -6,6 +6,6 @@ export default defineConfig({ schema: "./db/schema", out: "./db/migrations", dbCredentials: { - url: secrets.DATABASE_URL || process.env.DATABASE_URL, + url: secrets.DATABASE_URL, }, }) \ No newline at end of file diff --git a/backend/src/index.ts b/backend/src/index.ts index d4155be..222f969 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -146,6 +146,7 @@ async function main() { app.ready(async () => { try { + console.log("Testing DB Connection:") const result = await app.db.execute("SELECT NOW()"); console.log("✓ DB connection OK: " + JSON.stringify(result.rows[0])); } catch (err) { diff --git a/backend/src/plugins/db.ts b/backend/src/plugins/db.ts index c1d6131..fbe41ce 100644 --- a/backend/src/plugins/db.ts +++ b/backend/src/plugins/db.ts @@ -1,21 +1,9 @@ import fp from "fastify-plugin" import {drizzle, NodePgDatabase} from "drizzle-orm/node-postgres" import { Pool } from "pg" -import * as schema from "../../db/schema" +import { db } from "../../db" export default fp(async (server, opts) => { - const pool = new Pool({ - host: "10.10.20.10", - port: Number(process.env.DB_PORT || 5432), - user: "postgres", - password: "wJw7aNpEBJdcxgoct6GXNpvY4Cn6ECqu", - database: "fedeo", - ssl: process.env.DB_DISABLE_SSL === "true" ? false : undefined, - }) - - // Drizzle instance - const db = drizzle(pool, { schema }) - // Dekorieren -> überall server.db server.decorate("db", db)