-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata-source.ts
46 lines (42 loc) · 1.25 KB
/
data-source.ts
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
45
46
import 'reflect-metadata';
import { DataSource, DataSourceOptions } from 'typeorm';
import * as dotenv from 'dotenv';
dotenv.config();
const getDataSourceOptions = (): DataSourceOptions => {
return process.env.DATABASE_URL
? {
type: 'postgres',
url: process.env.DATABASE_URL,
ssl: {
rejectUnauthorized: false,
},
}
: {
type: 'postgres',
host: process.env.DB_HOST || 'localhost',
port: Number(process.env.DB_PORT) || 5432,
username: process.env.DB_USERNAME || 'postgres',
password: process.env.DB_PASSWORD || 'postgres',
database: process.env.DB_DATABASE || 'wallet',
};
};
const getSslRejectUnauthorized = () => {
return process.env.DB_SSL_REJECT_UNAUTHORIZED === 'false'
? {}
: {
ssl: {
rejectUnauthorized: false,
},
};
};
const DataSourceConfig = new DataSource({
...getDataSourceOptions(),
...getSslRejectUnauthorized(),
synchronize: false,
migrationsRun: true,
logging: process.env.NODE_ENV !== 'production',
entities: [`${__dirname}/src/modules/**/*.entity{.ts,.js}`],
migrations: [`${__dirname}/src/migrations/*{.ts,.js}`],
migrationsTableName: 'migrations_hype_pool',
} as DataSourceOptions);
export default DataSourceConfig;