Spaces:
Paused
Paused
Download apps/prevision-api/test/global-setup.ts from modventures/prevision: direct link, hf CLI and curl.
- Browser
- Download file 750 Bytes
-
https://huggingface.co/spaces/modventures/prevision/resolve/main/apps/prevision-api/test/global-setup.ts
- Command line
-
hf download hf://spaces/modventures/prevision/apps/prevision-api/test/global-setup.ts
-
curl -L -o global-setup.ts https://huggingface.co/spaces/modventures/prevision/resolve/main/apps/prevision-api/test/global-setup.ts
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' }); | |
| } | |