Skip to content

Commit 1a90fc8

Browse files
authored
feat: test for non-standard database name (#19386)
1 parent c707f9c commit 1a90fc8

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

server/test/medium/globalSetup.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ import { getKyselyConfig } from 'src/utils/database';
77
import { GenericContainer, Wait } from 'testcontainers';
88

99
const globalSetup = async () => {
10+
const templateName = 'mich';
1011
const postgresContainer = await new GenericContainer('ghcr.io/immich-app/postgres:14-vectorchord0.4.3')
1112
.withExposedPorts(5432)
1213
.withEnvironment({
1314
POSTGRES_PASSWORD: 'postgres',
1415
POSTGRES_USER: 'postgres',
15-
POSTGRES_DB: 'immich',
16+
POSTGRES_DB: templateName,
1617
})
1718
.withCommand([
1819
'postgres',
@@ -35,7 +36,7 @@ const globalSetup = async () => {
3536
.start();
3637

3738
const postgresPort = postgresContainer.getMappedPort(5432);
38-
const postgresUrl = `postgres://postgres:postgres@localhost:${postgresPort}/immich`;
39+
const postgresUrl = `postgres://postgres:postgres@localhost:${postgresPort}/${templateName}`;
3940

4041
process.env.IMMICH_TEST_POSTGRES_URL = postgresUrl;
4142

server/test/utils.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,18 +373,23 @@ function* newPngFactory() {
373373

374374
const pngFactory = newPngFactory();
375375

376-
const withDatabase = (url: string, name: string) => url.replace('/immich', `/${name}`);
376+
const templateName = 'mich';
377+
378+
const withDatabase = (url: string, name: string) => url.replace(`/${templateName}`, `/${name}`);
377379

378380
export const getKyselyDB = async (suffix?: string): Promise<Kysely<DB>> => {
379381
const testUrl = process.env.IMMICH_TEST_POSTGRES_URL!;
380382
const sql = postgres({
381-
...asPostgresConnectionConfig({ connectionType: 'url', url: withDatabase(testUrl, 'postgres') }),
383+
...asPostgresConnectionConfig({
384+
connectionType: 'url',
385+
url: withDatabase(testUrl, 'postgres'),
386+
}),
382387
max: 1,
383388
});
384389

385390
const randomSuffix = Math.random().toString(36).slice(2, 7);
386391
const dbName = `immich_${suffix ?? randomSuffix}`;
387-
await sql.unsafe(`CREATE DATABASE ${dbName} WITH TEMPLATE immich OWNER postgres;`);
392+
await sql.unsafe(`CREATE DATABASE ${dbName} WITH TEMPLATE ${templateName} OWNER postgres;`);
388393

389394
return new Kysely<DB>(getKyselyConfig({ connectionType: 'url', url: withDatabase(testUrl, dbName) }));
390395
};

0 commit comments

Comments
 (0)