3.0.0 #220

Merged
flfeders merged 676 commits from dev into main 2026-09-20 16:10:48 +00:00
Showing only changes of commit cb4917c536 - Show all commits

View File

@@ -1,31 +1,25 @@
import fp from "fastify-plugin"
import {drizzle, NodePgDatabase} from "drizzle-orm/node-postgres"
import * as schema from "../../db/schema"
import {secrets} from "../utils/secrets";
import { Pool } from "pg"
// src/plugins/db.ts
import fp from "fastify-plugin";
import { NodePgDatabase } from "drizzle-orm/node-postgres";
import * as schema from "../../db/schema";
import { db, pool } from "../../db"; // <--- Importiert jetzt die globale Instanz
export default fp(async (server, opts) => {
const pool = new Pool({
connectionString: secrets.DATABASE_URL,
max: 10, // je nach Last
})
// Wir nutzen die db, die wir in src/db/index.ts erstellt haben
server.decorate("db", db);
const db = drizzle(pool , {schema})
// Dekorieren -> überall server.db
server.decorate("db", db)
// Graceful Shutdown
// Graceful Shutdown: Wenn Fastify ausgeht, schließen wir den Pool
server.addHook("onClose", async () => {
await pool.end()
})
console.log("[DB] Closing connection pool...");
await pool.end();
});
console.log("Drizzle database connected")
})
console.log("[Fastify] Database attached from shared instance");
});
declare module "fastify" {
interface FastifyInstance {
db:NodePgDatabase<typeof schema>
db: NodePgDatabase<typeof schema>
}
}
}