db: drizzle schema matching spec 02, initial migrations, settings service
Migration 0000 enables citext; 0001 creates all 39 tables. DB tests use a throwaway database per file (TEST_DATABASE_URL, derived from .env in dev, a postgres service in CI). Decision 0002: pg driver and @fastify/cookie. Task: M1-T1
This commit is contained in:
1 parent
63a03b4185
commit
15b8a20751
29 files changed
+6649
-25
No files matched your search
@@ -0,0 +1,21 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { drizzle } from 'drizzle-orm/node-postgres';
|
||||
import { migrate } from 'drizzle-orm/node-postgres/migrator';
|
||||
import pg from 'pg';
|
||||
import * as schema from './schema.ts';
|
||||
|
||||
// Next to this file in src/ and in the image (the Dockerfile copies them to dist/db/migrations).
|
||||
const MIGRATIONS_DIR = fileURLToPath(new URL('./migrations', import.meta.url));
|
||||
|
||||
export function createDb(url: string) {
|
||||
const pool = new pg.Pool({ connectionString: url, max: 10 });
|
||||
const db = drizzle({ client: pool, schema, casing: 'snake_case' });
|
||||
return { db, pool };
|
||||
}
|
||||
|
||||
export type Db = ReturnType<typeof createDb>['db'];
|
||||
|
||||
export async function runMigrations(db: Db): Promise<void> {
|
||||
await migrate(db, { migrationsFolder: MIGRATIONS_DIR });
|
||||
}
|
||||
Reference in new issue
Block a user