export async function setupDockerTestDb({ logger = false } = {}) {
const container = await new PostgreSqlContainer('pg_uuidv7')
.withEnvironment({
POSTGRES_USER: POSTGRES_USER,
POSTGRES_PASSWORD: POSTGRES_PASSWORD,
POSTGRES_DB: POSTGRES_DB,
})
.start()
const connectionString = ...
const client = postgres(connectionString)
const db: PostgresJsDatabase<typeof schema> = drizzle(client, {
logger: logger,
})
await db.execute(sql`CREATE EXTENSION IF NOT EXISTS pg_uuidv7`)
const migrationPath = path.join(process.cwd(), 'src/db/migrations')
try {
// Set client_min_messages to WARNING to suppress NOTICE messages
await db.execute(sql`SET client_min_messages TO WARNING`)
await migrate(db, {
migrationsFolder: migrationPath,
})
} catch (error) {
console.error('An error occurred during migration:', error)
// Handle the error appropriately, e.g., by re-throwing it or exiting the process
throw error
} finally {
// Reset client_min_messages to its default value
await db.execute(sql`RESET client_min_messages`)
}
// Populate Database
await up(db)
return { container, db, confirmDatabaseReady, client }
}
export async function setupDockerTestDb({ logger = false } = {}) {
const container = await new PostgreSqlContainer('pg_uuidv7')
.withEnvironment({
POSTGRES_USER: POSTGRES_USER,
POSTGRES_PASSWORD: POSTGRES_PASSWORD,
POSTGRES_DB: POSTGRES_DB,
})
.start()
const connectionString = ...
const client = postgres(connectionString)
const db: PostgresJsDatabase<typeof schema> = drizzle(client, {
logger: logger,
})
await db.execute(sql`CREATE EXTENSION IF NOT EXISTS pg_uuidv7`)
const migrationPath = path.join(process.cwd(), 'src/db/migrations')
try {
// Set client_min_messages to WARNING to suppress NOTICE messages
await db.execute(sql`SET client_min_messages TO WARNING`)
await migrate(db, {
migrationsFolder: migrationPath,
})
} catch (error) {
console.error('An error occurred during migration:', error)
// Handle the error appropriately, e.g., by re-throwing it or exiting the process
throw error
} finally {
// Reset client_min_messages to its default value
await db.execute(sql`RESET client_min_messages`)
}
// Populate Database
await up(db)
return { container, db, confirmDatabaseReady, client }
}