Spaces:
Paused
Paused
File size: 750 Bytes
1fe7075 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | 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' });
}
|