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:
24
server/db/repositories/defects.ts
Normal file
24
server/db/repositories/defects.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { desc } from 'drizzle-orm'
|
||||
import type { NodePgDatabase } from 'drizzle-orm/node-postgres'
|
||||
import type * as schema from '../schema'
|
||||
import { defects } from '../schema'
|
||||
|
||||
type Db = NodePgDatabase<typeof schema>
|
||||
|
||||
export interface NewDefect {
|
||||
sectionId: string
|
||||
projectId: string
|
||||
verbatim: string
|
||||
reporterEmail: string
|
||||
}
|
||||
|
||||
/** Persist a filed defect and return the stored row. */
|
||||
export async function createDefect(db: Db, input: NewDefect) {
|
||||
const [row] = await db.insert(defects).values(input).returning()
|
||||
return row
|
||||
}
|
||||
|
||||
/** Recent defects, newest first — the dashboard feed (F5/F6). */
|
||||
export async function listRecentDefects(db: Db, limit = 100) {
|
||||
return db.select().from(defects).orderBy(desc(defects.createdAt)).limit(limit)
|
||||
}
|
||||
Reference in New Issue
Block a user