Something went wrong. Try again.
Reference implementation for the Phoenix Architecture. Work in progress. aicoding.leaflet.pub
Something went wrong. Try again.
123456789101112131415161718192021222324252627import Database from 'better-sqlite3';import { existsSync, mkdirSync } from 'node:fs';import { dirname } from 'node:path';
const DB_PATH = process.env.DB_PATH ?? 'data/app.db';
const dir = dirname(DB_PATH);if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
const db = new Database(DB_PATH);db.pragma('journal_mode = WAL');db.pragma('foreign_keys = ON');
const migrations: Array<{ name: string; sql: string }> = [];
export function registerMigration(name: string, sql: string): void { migrations.push({ name, sql });}
export function runMigrations(): void { for (const m of migrations) { db.exec(m.sql); }}
export { db };