feat: initial commit
This commit is contained in:
21
tests/setup/setup-db.ts
Normal file
21
tests/setup/setup-db.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { configAppDataSource } from '@/lib/db/data-source';
|
||||
import { PostgreSqlContainer } from '@testcontainers/postgresql';
|
||||
import 'reflect-metadata';
|
||||
|
||||
const runMigrations = async (url: string) => {
|
||||
const dataSource = configAppDataSource(url);
|
||||
|
||||
if (!dataSource.isInitialized) {
|
||||
await dataSource.initialize();
|
||||
}
|
||||
|
||||
await dataSource.runMigrations();
|
||||
};
|
||||
|
||||
export const startTestDB = async () => {
|
||||
const container = await new PostgreSqlContainer('postgres:16').start();
|
||||
|
||||
await runMigrations(container.getConnectionUri());
|
||||
|
||||
return container;
|
||||
};
|
||||
Reference in New Issue
Block a user