|
|
|
|
@ -373,18 +373,23 @@ function* newPngFactory() {
|
|
|
|
|
|
|
|
|
|
const pngFactory = newPngFactory();
|
|
|
|
|
|
|
|
|
|
const withDatabase = (url: string, name: string) => url.replace('/immich', `/${name}`);
|
|
|
|
|
const templateName = 'mich';
|
|
|
|
|
|
|
|
|
|
const withDatabase = (url: string, name: string) => url.replace(`/${templateName}`, `/${name}`);
|
|
|
|
|
|
|
|
|
|
export const getKyselyDB = async (suffix?: string): Promise<Kysely<DB>> => {
|
|
|
|
|
const testUrl = process.env.IMMICH_TEST_POSTGRES_URL!;
|
|
|
|
|
const sql = postgres({
|
|
|
|
|
...asPostgresConnectionConfig({ connectionType: 'url', url: withDatabase(testUrl, 'postgres') }),
|
|
|
|
|
...asPostgresConnectionConfig({
|
|
|
|
|
connectionType: 'url',
|
|
|
|
|
url: withDatabase(testUrl, 'postgres'),
|
|
|
|
|
}),
|
|
|
|
|
max: 1,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const randomSuffix = Math.random().toString(36).slice(2, 7);
|
|
|
|
|
const dbName = `immich_${suffix ?? randomSuffix}`;
|
|
|
|
|
await sql.unsafe(`CREATE DATABASE ${dbName} WITH TEMPLATE immich OWNER postgres;`);
|
|
|
|
|
await sql.unsafe(`CREATE DATABASE ${dbName} WITH TEMPLATE ${templateName} OWNER postgres;`);
|
|
|
|
|
|
|
|
|
|
return new Kysely<DB>(getKyselyConfig({ connectionType: 'url', url: withDatabase(testUrl, dbName) }));
|
|
|
|
|
};
|
|
|
|
|
|