feat(db): Postgres schema, migrations and defects repository (T3)
Drizzle schema for projects, defects, push_subscriptions (C8); generated migration; a defects repository (createDefect / listRecentDefects); a programmatic migrator; and a db:verify script. section_id is a plain string referencing in-code board ids, no FK (ADR 0001). Verified against real Postgres: migration applies, a defect round-trips, /api/health reports db up.
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
import pg from 'pg'
|
||||
import { drizzle, type NodePgDatabase } from 'drizzle-orm/node-postgres'
|
||||
import * as schema from './schema'
|
||||
|
||||
let pool: pg.Pool | undefined
|
||||
let db: NodePgDatabase<typeof schema> | undefined
|
||||
|
||||
/** Lazily-created shared Postgres connection pool. */
|
||||
export function getPool(): pg.Pool {
|
||||
@@ -10,6 +13,14 @@ export function getPool(): pg.Pool {
|
||||
return pool
|
||||
}
|
||||
|
||||
/** Lazily-created Drizzle client bound to the shared pool. */
|
||||
export function getDb(): NodePgDatabase<typeof schema> {
|
||||
if (!db) {
|
||||
db = drizzle(getPool(), { schema })
|
||||
}
|
||||
return db
|
||||
}
|
||||
|
||||
/** Liveness probe for the database, used by /api/health. */
|
||||
export async function checkDb(): Promise<'up' | 'down'> {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user