1
0
mirror of https://github.com/immich-app/immich.git synced 2025-07-06 06:07:29 +02:00
Files
immich/server/test/medium/globalSetup.ts

53 lines
1.7 KiB
TypeScript
Raw Normal View History

import { Kysely } from 'kysely';
import { ConfigRepository } from 'src/repositories/config.repository';
import { DatabaseRepository } from 'src/repositories/database.repository';
import { LoggingRepository } from 'src/repositories/logging.repository';
2025-06-30 13:19:16 -04:00
import { DB } from 'src/schema';
import { getKyselyConfig } from 'src/utils/database';
import { GenericContainer, Wait } from 'testcontainers';
const globalSetup = async () => {
const templateName = 'mich';
const postgresContainer = await new GenericContainer('ghcr.io/immich-app/postgres:14-vectorchord0.4.3')
.withExposedPorts(5432)
.withEnvironment({
POSTGRES_PASSWORD: 'postgres',
POSTGRES_USER: 'postgres',
POSTGRES_DB: templateName,
})
.withCommand([
'postgres',
'-c',
'shared_preload_libraries=vchord.so',
'-c',
'max_wal_size=2GB',
'-c',
'shared_buffers=512MB',
'-c',
'fsync=off',
'-c',
'full_page_writes=off',
'-c',
'synchronous_commit=off',
'-c',
'config_file=/var/lib/postgresql/data/postgresql.conf',
])
.withWaitStrategy(Wait.forAll([Wait.forLogMessage('database system is ready to accept connections', 2)]))
.start();
2025-03-29 09:26:24 -04:00
const postgresPort = postgresContainer.getMappedPort(5432);
const postgresUrl = `postgres://postgres:postgres@localhost:${postgresPort}/${templateName}`;
2025-03-29 09:26:24 -04:00
process.env.IMMICH_TEST_POSTGRES_URL = postgresUrl;
2025-03-29 09:26:24 -04:00
const db = new Kysely<DB>(getKyselyConfig({ connectionType: 'url', url: postgresUrl }));
2025-03-29 09:26:24 -04:00
const configRepository = new ConfigRepository();
2025-05-02 13:34:35 -04:00
const logger = LoggingRepository.create();
await new DatabaseRepository(db, logger, configRepository).runMigrations();
2025-03-29 09:26:24 -04:00
await db.destroy();
};
export default globalSetup;