prevision / apps /prevision-api /test /global-setup.ts
github-actions[bot]
Automated Deploy: 23110475c742a5d4f03930b55bca09042215c1dd
1fe7075
Raw History Blame Contribute Delete
750 Bytes
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' });
}