BetterFrame/server/src/shared/db/db-adapter.ts
Mitchell R 9b4032ca8a
refactor: decommission SQLite + add UUIDv7 PK migration for existing PG
- Delete sqlite-adapter.ts and migrations.ts (SQLite path removed)
- Remove driver/sqlitePath from all config schemas + sec-config template
- init.ts now PG-only, no SQLite branch
- db-adapter.ts dialect narrowed to "postgres" only
- Add in-place UUIDv7 migration: detects INTEGER PKs in existing PG
  databases, drops FK constraints, ALTER COLUMN TYPE to TEXT for all
  15 entity tables + their FK columns, re-adds FK constraints. Idempotent
  (skips if already TEXT). Existing integer IDs become string "1", "2"
  etc — new inserts use proper UUIDv7 from repository.ts.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-05-26 13:22:29 +02:00

28 lines
1,004 B
TypeScript

/**
* Backend-agnostic DB adapter. Repository talks to this; PG adapter implements it.
*
* Design choices:
* - All methods return Promises (real async I/O with PG pool).
* - `?` is the canonical placeholder in SQL strings. The PG adapter
* rewrites them to `$1, $2, ...` at execute time so repository code stays
* dialect-neutral.
*/
export type SqlValue = string | number | bigint | boolean | null | Uint8Array;
export type Row = Record<string, unknown>;
export interface RunResult {
lastInsertRowid: bigint;
changes: number;
}
export interface DbAdapter {
run(sql: string, params?: ReadonlyArray<SqlValue>): Promise<RunResult>;
get<T = Row>(sql: string, params?: ReadonlyArray<SqlValue>): Promise<T | undefined>;
all<T = Row>(sql: string, params?: ReadonlyArray<SqlValue>): Promise<T[]>;
exec(sql: string): Promise<void>;
transaction<T>(fn: () => Promise<T>): Promise<T>;
dialect(): "postgres";
setSearchPath(schema: string): Promise<void>;
close(): Promise<void>;
}