From 55d883925f1d2499a9eeb71aeb95ca74dc1ac127 Mon Sep 17 00:00:00 2001 From: Jason Rasmussen Date: Thu, 26 Jan 2023 21:52:13 -0500 Subject: [PATCH] chore(server): rename database connection variables (#1437) --- .../infra/src/db/config/database.config.ts | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/server/libs/infra/src/db/config/database.config.ts b/server/libs/infra/src/db/config/database.config.ts index b98f16d71..84765d0af 100644 --- a/server/libs/infra/src/db/config/database.config.ts +++ b/server/libs/infra/src/db/config/database.config.ts @@ -1,26 +1,25 @@ import { PostgresConnectionOptions } from 'typeorm/driver/postgres/PostgresConnectionOptions'; import { DataSource } from 'typeorm'; -const baseDatabaseConfig: PostgresConnectionOptions = { +const url = process.env.DB_URL; +const urlOrParts = url + ? { url } + : { + host: process.env.DB_HOSTNAME || 'immich_postgres', + port: parseInt(process.env.DB_PORT || '5432'), + username: process.env.DB_USERNAME, + password: process.env.DB_PASSWORD, + database: process.env.DB_DATABASE_NAME, + }; + +export const databaseConfig: PostgresConnectionOptions = { type: 'postgres', entities: [__dirname + '/../**/*.entity.{js,ts}'], synchronize: false, migrations: [__dirname + '/../migrations/*.{js,ts}'], migrationsRun: true, connectTimeoutMS: 10000, // 10 seconds + ...urlOrParts, }; -const envBasedDatabaseConfig = { - host: process.env.DB_HOSTNAME || 'immich_postgres', - port: parseInt(process.env.DB_PORT || '5432'), - username: process.env.DB_USERNAME, - password: process.env.DB_PASSWORD, - database: process.env.DB_DATABASE_NAME, -}; - -const url = process.env.DB_URL; -const additionalSSLDatabaseConfig = url ? { url } : envBasedDatabaseConfig; - -export const databaseConfig: PostgresConnectionOptions = { ...baseDatabaseConfig, ...additionalSSLDatabaseConfig }; - export const dataSource = new DataSource(databaseConfig);