mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-22 14:08:24 +00:00
42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
import { PostgreSqlContainer } from '@testcontainers/postgresql'
|
|
import { exec } from 'node:child_process'
|
|
import { promisify } from 'node:util'
|
|
import { Wait } from 'testcontainers'
|
|
|
|
const execAsync = promisify(exec)
|
|
|
|
let dbContainer: import('@testcontainers/postgresql').StartedPostgreSqlContainer
|
|
|
|
export async function globalTestSetup() {
|
|
console.log('Starting Testcontainers for global setup...')
|
|
dbContainer = await new PostgreSqlContainer('pgvector/pgvector:pg18')
|
|
.withWaitStrategy(
|
|
// casting to any due to testcontainers wait strategy type mismatch
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
Wait.forLogMessage('database system is ready to accept connections', 1) as any,
|
|
)
|
|
.start()
|
|
|
|
const databaseUrl = dbContainer.getConnectionUri()
|
|
console.log('Database started at:', databaseUrl)
|
|
|
|
process.env.DATABASE_URL = databaseUrl
|
|
|
|
console.log('Applying Prisma Migrations...')
|
|
await execAsync('bun run prisma migrate deploy', {
|
|
env: {
|
|
...process.env,
|
|
DATABASE_URL: databaseUrl,
|
|
},
|
|
})
|
|
console.log('Prisma Migrations completed.')
|
|
}
|
|
|
|
export async function setup() {
|
|
await globalTestSetup()
|
|
}
|
|
|
|
export async function teardown() {
|
|
await dbContainer?.stop()
|
|
}
|