- Add lib/db (Drizzle schema: 7 tables + 6 enums + relations, postgres.js client), drizzle.config.ts, lib/db/enums.ts (Prisma-compatible enum objects) - Rewrite all 14 app consumers + 4 admin components to Drizzle - Move the test DB layer to Drizzle + in-process PGlite; convert all 8 integration test files + factories (371 tests green) - Remove Prisma: deps, prisma/ schema+migrations, lib/prisma.ts, Dockerfile prisma generate; wire db:generate/migrate/push/studio to drizzle-kit; update Makefile - Preserve the old seed as scripts/legacy-prisma-seed.cjs (needs a Drizzle rewrite)
36 lines
1.1 KiB
TypeScript
36 lines
1.1 KiB
TypeScript
import { readFileSync, readdirSync } from "fs";
|
|
import path from "path";
|
|
|
|
/**
|
|
* Global integration setup.
|
|
*
|
|
* Only needed when running against a real Postgres via TEST_DATABASE_URL: reset the
|
|
* schema and apply every Drizzle migration once before the workers start. When
|
|
* TEST_DATABASE_URL is not set, each worker spins up its own in-process PGlite
|
|
* database (see tests/helpers/integration-setup.ts) and this is a no-op.
|
|
*/
|
|
|
|
const MIGRATIONS_DIR = path.resolve(process.cwd(), "lib", "db", "migrations");
|
|
|
|
export default async function setup() {
|
|
const connectionString = process.env.TEST_DATABASE_URL?.trim();
|
|
if (!connectionString) {
|
|
return;
|
|
}
|
|
|
|
const pg = (await import("pg")).default;
|
|
const client = new pg.Client({ connectionString });
|
|
await client.connect();
|
|
try {
|
|
await client.query("DROP SCHEMA IF EXISTS public CASCADE; CREATE SCHEMA public;");
|
|
const files = readdirSync(MIGRATIONS_DIR)
|
|
.filter((entry) => entry.endsWith(".sql"))
|
|
.sort();
|
|
for (const file of files) {
|
|
await client.query(readFileSync(path.join(MIGRATIONS_DIR, file), "utf8"));
|
|
}
|
|
} finally {
|
|
await client.end();
|
|
}
|
|
}
|