2024-03-21 12:59:49 +01:00
|
|
|
import { DatabaseExtension } from 'src/interfaces/database.interface';
|
2023-12-21 17:06:26 +01:00
|
|
|
import { DataSource } from 'typeorm';
|
2024-01-31 00:23:33 +01:00
|
|
|
import { PostgresConnectionOptions } from 'typeorm/driver/postgres/PostgresConnectionOptions.js';
|
2022-02-03 17:06:44 +01:00
|
|
|
|
2023-01-27 03:52:13 +01:00
|
|
|
const url = process.env.DB_URL;
|
|
|
|
const urlOrParts = url
|
|
|
|
? { url }
|
|
|
|
: {
|
2024-04-27 19:43:45 +02:00
|
|
|
host: process.env.DB_HOSTNAME || 'database',
|
2024-02-02 04:18:00 +01:00
|
|
|
port: Number.parseInt(process.env.DB_PORT || '5432'),
|
2023-01-27 21:50:07 +01:00
|
|
|
username: process.env.DB_USERNAME || 'postgres',
|
|
|
|
password: process.env.DB_PASSWORD || 'postgres',
|
|
|
|
database: process.env.DB_DATABASE_NAME || 'immich',
|
2023-01-27 03:52:13 +01:00
|
|
|
};
|
|
|
|
|
2024-02-02 04:18:00 +01:00
|
|
|
/* eslint unicorn/prefer-module: "off" -- We can fix this when migrating to ESM*/
|
2023-01-27 03:52:13 +01:00
|
|
|
export const databaseConfig: PostgresConnectionOptions = {
|
2022-02-03 17:06:44 +01:00
|
|
|
type: 'postgres',
|
2024-03-21 04:15:09 +01:00
|
|
|
entities: [__dirname + '/entities/*.entity.{js,ts}'],
|
|
|
|
migrations: [__dirname + '/migrations/*.{js,ts}'],
|
|
|
|
subscribers: [__dirname + '/subscribers/*.{js,ts}'],
|
2023-12-21 17:06:26 +01:00
|
|
|
migrationsRun: false,
|
2024-03-20 22:02:51 +01:00
|
|
|
synchronize: false,
|
2024-02-02 04:18:00 +01:00
|
|
|
connectTimeoutMS: 10_000, // 10 seconds
|
2023-12-29 19:41:33 +01:00
|
|
|
parseInt8: true,
|
2023-01-27 03:52:13 +01:00
|
|
|
...urlOrParts,
|
2022-02-03 17:06:44 +01:00
|
|
|
};
|
2022-06-06 18:16:03 +02:00
|
|
|
|
2024-04-27 19:43:45 +02:00
|
|
|
/**
|
|
|
|
* @deprecated - DO NOT USE THIS
|
|
|
|
*
|
|
|
|
* this export is ONLY to be used for TypeORM commands in package.json#scripts
|
|
|
|
*/
|
|
|
|
export const dataSource = new DataSource({ ...databaseConfig, host: 'localhost' });
|
2024-02-07 03:46:38 +01:00
|
|
|
|
2024-05-21 02:31:36 +02:00
|
|
|
export const getVectorExtension = () =>
|
2024-02-20 03:32:55 +01:00
|
|
|
process.env.DB_VECTOR_EXTENSION === 'pgvector' ? DatabaseExtension.VECTOR : DatabaseExtension.VECTORS;
|