1
0
mirror of https://github.com/immich-app/immich.git synced 2024-11-24 08:52:28 +02:00

refactor: better postgres connection param typing (#13800)

This commit is contained in:
Zack Pollard 2024-10-29 15:11:34 +00:00 committed by GitHub
parent e74ddca6c0
commit 68a4cc25dc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 25 additions and 3 deletions

View File

@ -3,7 +3,7 @@ import { QueueOptions } from 'bullmq';
import { RedisOptions } from 'ioredis'; import { RedisOptions } from 'ioredis';
import { OpenTelemetryModuleOptions } from 'nestjs-otel/lib/interfaces'; import { OpenTelemetryModuleOptions } from 'nestjs-otel/lib/interfaces';
import { ImmichEnvironment, ImmichTelemetry, ImmichWorker, LogLevel } from 'src/enum'; 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'; import { PostgresConnectionOptions } from 'typeorm/driver/postgres/PostgresConnectionOptions.js';
export const IConfigRepository = 'IConfigRepository'; export const IConfigRepository = 'IConfigRepository';
@ -37,7 +37,7 @@ export interface EnvData {
}; };
database: { database: {
config: PostgresConnectionOptions; config: PostgresConnectionOptions & DatabaseConnectionParams;
skipMigrations: boolean; skipMigrations: boolean;
vectorExtension: VectorExtension; vectorExtension: VectorExtension;
}; };

View File

@ -7,6 +7,22 @@ export enum DatabaseExtension {
export type VectorExtension = DatabaseExtension.VECTOR | DatabaseExtension.VECTORS; 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 { export enum VectorIndex {
CLIP = 'clip_index', CLIP = 'clip_index',
FACE = 'face_index', FACE = 'face_index',

View File

@ -132,8 +132,9 @@ const getEnv = (): EnvData => {
connectTimeoutMS: 10_000, // 10 seconds connectTimeoutMS: 10_000, // 10 seconds
parseInt8: true, parseInt8: true,
...(databaseUrl ...(databaseUrl
? { url: databaseUrl } ? { connectionType: 'url', url: databaseUrl }
: { : {
connectionType: 'parts',
host: process.env.DB_HOSTNAME || 'database', host: process.env.DB_HOSTNAME || 'database',
port: Number(process.env.DB_PORT) || 5432, port: Number(process.env.DB_PORT) || 5432,
username: process.env.DB_USERNAME || 'postgres', username: process.env.DB_USERNAME || 'postgres',

View File

@ -61,6 +61,7 @@ describe(DatabaseService.name, () => {
mockEnvData({ mockEnvData({
database: { database: {
config: { config: {
connectionType: 'parts',
type: 'postgres', type: 'postgres',
host: 'database', host: 'database',
port: 5432, port: 5432,
@ -290,6 +291,7 @@ describe(DatabaseService.name, () => {
mockEnvData({ mockEnvData({
database: { database: {
config: { config: {
connectionType: 'parts',
type: 'postgres', type: 'postgres',
host: 'database', host: 'database',
port: 5432, port: 5432,
@ -313,6 +315,7 @@ describe(DatabaseService.name, () => {
mockEnvData({ mockEnvData({
database: { database: {
config: { config: {
connectionType: 'parts',
type: 'postgres', type: 'postgres',
host: 'database', host: 'database',
port: 5432, port: 5432,

View File

@ -17,6 +17,8 @@ const envData: EnvData = {
database: { database: {
config: { config: {
connectionType: 'parts',
database: 'immich',
type: 'postgres', type: 'postgres',
host: 'database', host: 'database',
port: 5432, port: 5432,