2022-06-29 20:39:58 +02:00
|
|
|
import { PostgresConnectionOptions } from 'typeorm/driver/postgres/PostgresConnectionOptions';
|
2022-07-16 17:54:00 +02:00
|
|
|
import { DataSource } from 'typeorm';
|
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 }
|
|
|
|
: {
|
|
|
|
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 = {
|
2022-02-03 17:06:44 +01:00
|
|
|
type: 'postgres',
|
|
|
|
entities: [__dirname + '/../**/*.entity.{js,ts}'],
|
2022-02-20 05:42:10 +01:00
|
|
|
synchronize: false,
|
2022-06-11 23:12:06 +02:00
|
|
|
migrations: [__dirname + '/../migrations/*.{js,ts}'],
|
2022-02-20 05:42:10 +01:00
|
|
|
migrationsRun: true,
|
2023-01-14 16:06:59 +01:00
|
|
|
connectTimeoutMS: 10000, // 10 seconds
|
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
|
|
|
|
2022-07-04 21:20:43 +02:00
|
|
|
export const dataSource = new DataSource(databaseConfig);
|