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:
parent
e74ddca6c0
commit
68a4cc25dc
@ -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;
|
||||||
};
|
};
|
||||||
|
@ -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',
|
||||||
|
@ -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',
|
||||||
|
@ -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,
|
||||||
|
@ -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,
|
||||||
|
Loading…
Reference in New Issue
Block a user