2024-10-03 17:48:40 -04:00
|
|
|
import { ConfigRepository } from 'src/repositories/config.repository';
|
2023-12-21 11:06:26 -05:00
|
|
|
import { DataSource } from 'typeorm';
|
2024-01-30 15:23:33 -08:00
|
|
|
import { PostgresConnectionOptions } from 'typeorm/driver/postgres/PostgresConnectionOptions.js';
|
2022-02-03 10:06:44 -06:00
|
|
|
|
2024-10-03 17:48:40 -04:00
|
|
|
const { database } = new ConfigRepository().getEnv();
|
|
|
|
const { url, host, port, username, password, name } = database;
|
2023-01-26 21:52:13 -05:00
|
|
|
const urlOrParts = url
|
|
|
|
? { url }
|
|
|
|
: {
|
2024-10-03 17:48:40 -04:00
|
|
|
host,
|
|
|
|
port,
|
|
|
|
username,
|
|
|
|
password,
|
|
|
|
database: name,
|
2023-01-26 21:52:13 -05:00
|
|
|
};
|
|
|
|
|
2024-02-02 04:18:00 +01:00
|
|
|
/* eslint unicorn/prefer-module: "off" -- We can fix this when migrating to ESM*/
|
2023-01-26 21:52:13 -05:00
|
|
|
export const databaseConfig: PostgresConnectionOptions = {
|
2022-02-03 10:06:44 -06:00
|
|
|
type: 'postgres',
|
2024-03-20 22:15:09 -05:00
|
|
|
entities: [__dirname + '/entities/*.entity.{js,ts}'],
|
|
|
|
migrations: [__dirname + '/migrations/*.{js,ts}'],
|
|
|
|
subscribers: [__dirname + '/subscribers/*.{js,ts}'],
|
2023-12-21 11:06:26 -05:00
|
|
|
migrationsRun: false,
|
2024-03-20 16:02:51 -05:00
|
|
|
synchronize: false,
|
2024-02-02 04:18:00 +01:00
|
|
|
connectTimeoutMS: 10_000, // 10 seconds
|
2023-12-29 18:41:33 +00:00
|
|
|
parseInt8: true,
|
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
|
|
|
|
2024-04-27 13:43:45 -04: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' });
|