import { execSync } from 'node:child_process'; import pg from 'pg'; const url = process.env.TEST_DATABASE_URL ?? 'postgresql://postgres:postgres@localhost:55432/prevision_api_test'; /** A fresh database with the real Prisma migrations. */ export default async function setup() { const database = new URL(url).pathname.slice(1); const admin = new pg.Client({ connectionString: Object.assign(new URL(url), { pathname: '/postgres' }).toString() }); await admin.connect(); await admin.query(`DROP DATABASE IF EXISTS "${database}" WITH (FORCE)`); await admin.query(`CREATE DATABASE "${database}"`); await admin.end(); execSync('pnpm exec prisma migrate deploy', { env: { ...process.env, PREVISION_DATABASE_URL: url }, stdio: 'pipe' }); }