diff --git a/server/src/interfaces/config.interface.ts b/server/src/interfaces/config.interface.ts index cf1bc18e3edcd..f221b7ee4fa92 100644 --- a/server/src/interfaces/config.interface.ts +++ b/server/src/interfaces/config.interface.ts @@ -3,7 +3,7 @@ import { QueueOptions } from 'bullmq'; import { RedisOptions } from 'ioredis'; import { OpenTelemetryModuleOptions } from 'nestjs-otel/lib/interfaces'; import { ImmichEnvironment, ImmichTelemetry, ImmichWorker, LogLevel } from 'src/enum'; -import { VectorExtension } from 'src/interfaces/database.interface'; +import { DatabaseConnectionParams, VectorExtension } from 'src/interfaces/database.interface'; import { PostgresConnectionOptions } from 'typeorm/driver/postgres/PostgresConnectionOptions.js'; export const IConfigRepository = 'IConfigRepository'; @@ -37,7 +37,7 @@ export interface EnvData { }; database: { - config: PostgresConnectionOptions; + config: PostgresConnectionOptions & DatabaseConnectionParams; skipMigrations: boolean; vectorExtension: VectorExtension; }; diff --git a/server/src/interfaces/database.interface.ts b/server/src/interfaces/database.interface.ts index da0938c8b7e1b..7745f54a32b7a 100644 --- a/server/src/interfaces/database.interface.ts +++ b/server/src/interfaces/database.interface.ts @@ -7,6 +7,22 @@ export enum DatabaseExtension { export type VectorExtension = DatabaseExtension.VECTOR | DatabaseExtension.VECTORS; +export type DatabaseConnectionURL = { + connectionType: 'url'; + url: string; +}; + +export type DatabaseConnectionParts = { + connectionType: 'parts'; + host: string; + port: number; + username: string; + password: string; + database: string; +}; + +export type DatabaseConnectionParams = DatabaseConnectionURL | DatabaseConnectionParts; + export enum VectorIndex { CLIP = 'clip_index', FACE = 'face_index', diff --git a/server/src/repositories/config.repository.ts b/server/src/repositories/config.repository.ts index 077a19175e88f..3cb1ada4126be 100644 --- a/server/src/repositories/config.repository.ts +++ b/server/src/repositories/config.repository.ts @@ -132,8 +132,9 @@ const getEnv = (): EnvData => { connectTimeoutMS: 10_000, // 10 seconds parseInt8: true, ...(databaseUrl - ? { url: databaseUrl } + ? { connectionType: 'url', url: databaseUrl } : { + connectionType: 'parts', host: process.env.DB_HOSTNAME || 'database', port: Number(process.env.DB_PORT) || 5432, username: process.env.DB_USERNAME || 'postgres', diff --git a/server/src/services/database.service.spec.ts b/server/src/services/database.service.spec.ts index 79845e4297793..958fb158a079f 100644 --- a/server/src/services/database.service.spec.ts +++ b/server/src/services/database.service.spec.ts @@ -61,6 +61,7 @@ describe(DatabaseService.name, () => { mockEnvData({ database: { config: { + connectionType: 'parts', type: 'postgres', host: 'database', port: 5432, @@ -290,6 +291,7 @@ describe(DatabaseService.name, () => { mockEnvData({ database: { config: { + connectionType: 'parts', type: 'postgres', host: 'database', port: 5432, @@ -313,6 +315,7 @@ describe(DatabaseService.name, () => { mockEnvData({ database: { config: { + connectionType: 'parts', type: 'postgres', host: 'database', port: 5432, diff --git a/server/test/repositories/config.repository.mock.ts b/server/test/repositories/config.repository.mock.ts index 08c2394e85a00..ba85cc7d0952f 100644 --- a/server/test/repositories/config.repository.mock.ts +++ b/server/test/repositories/config.repository.mock.ts @@ -17,6 +17,8 @@ const envData: EnvData = { database: { config: { + connectionType: 'parts', + database: 'immich', type: 'postgres', host: 'database', port: 5432,