2022-06-29 13:39:58 -05:00
|
|
|
import { PostgresConnectionOptions } from 'typeorm/driver/postgres/PostgresConnectionOptions';
|
2022-07-16 10:54:00 -05:00
|
|
|
import { DataSource } from 'typeorm';
|
2022-02-03 10:06:44 -06:00
|
|
|
|
2023-01-26 21:52:13 -05:00
|
|
|
const url = process.env.DB_URL;
|
|
|
|
const urlOrParts = url
|
|
|
|
? { url }
|
|
|
|
: {
|
2023-01-27 20:50:07 +00:00
|
|
|
host: process.env.DB_HOSTNAME || 'localhost',
|
2023-01-26 21:52:13 -05:00
|
|
|
port: parseInt(process.env.DB_PORT || '5432'),
|
2023-01-27 20:50:07 +00:00
|
|
|
username: process.env.DB_USERNAME || 'postgres',
|
|
|
|
password: process.env.DB_PASSWORD || 'postgres',
|
|
|
|
database: process.env.DB_DATABASE_NAME || 'immich',
|
2023-01-26 21:52:13 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
export const databaseConfig: PostgresConnectionOptions = {
|
2022-02-03 10:06:44 -06:00
|
|
|
type: 'postgres',
|
|
|
|
entities: [__dirname + '/../**/*.entity.{js,ts}'],
|
2022-02-19 22:42:10 -06:00
|
|
|
synchronize: false,
|
2022-06-11 16:12:06 -05:00
|
|
|
migrations: [__dirname + '/../migrations/*.{js,ts}'],
|
2022-02-19 22:42:10 -06:00
|
|
|
migrationsRun: true,
|
2023-01-14 16:06:59 +01:00
|
|
|
connectTimeoutMS: 10000, // 10 seconds
|
2023-01-26 21:52:13 -05:00
|
|
|
...urlOrParts,
|
2022-02-03 10:06:44 -06:00
|
|
|
};
|
2022-06-06 18:16:03 +02:00
|
|
|
|
2022-07-04 20:20:43 +01:00
|
|
|
export const dataSource = new DataSource(databaseConfig);
|