-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathormconfig.ts
More file actions
44 lines (37 loc) · 1.4 KB
/
ormconfig.ts
File metadata and controls
44 lines (37 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { existsSync } from 'fs';
import {DataSource, DataSourceOptions} from 'typeorm';
import { SnakeNamingStrategy } from 'typeorm-naming-strategies';
import './src/util/dotenv';
const entities = process.env.NODE_ENV !== 'development' ? ['dist/**/*.entity.js'] : ['src/**/*.entity.ts'];
const migrations = process.env.NODE_ENV !== 'development' ? ['dist/src/migration/*.js'] : ['src/migration/*.ts'];
/**
* The typeorm config
*
* @type {DataSourceOptions}
* @author theS1LV3R
* @since 6.0.0
* @see {@link DataSourceOptions}
*/
let ormConfig: DataSourceOptions = {
type: 'postgres',
host: process.env.DB_HOST ?? 'localhost',
port: parseInt(process.env.DB_PORT ?? '5432', 10),
username: process.env.DB_USER ?? 'postgres',
password: process.env.DB_PASS ?? 'postgres',
database: process.env.DB_NAME ?? 'discord_bot',
synchronize: false,
logging: ['error'],
namingStrategy: new SnakeNamingStrategy(),
entities,
migrations
};
// If ormconfig.local.ts exists, merge these defaults with the values from it
if (existsSync('./ormconfig.local.ts'))
{
// eslint-disable-next-line @typescript-eslint/no-var-requires
const localConfig = require('./ormconfig.local.ts');
ormConfig = Object.assign(ormConfig, localConfig);
}
export default ormConfig;
// Also export the data source as an object for use with the typeorm cli
export const dataSource = new DataSource(ormConfig);