-
Notifications
You must be signed in to change notification settings - Fork 0
/
ormconfig.ts
29 lines (25 loc) · 981 Bytes
/
ormconfig.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
import { DataSource } from 'typeorm';
import * as fs from 'fs';
import { ConfigService } from '@nestjs/config';
import * as dotenv from 'dotenv';
const configService = new ConfigService(dotenv.config());
let ssl_extra = {};
if (configService.get('database_ssl_cert_path')) {
ssl_extra = {
ca: fs.readFileSync(configService.get('database_ssl_cert_path').toString()),
rejectUnauthorized: configService.get('ENV_NAME') == 'prod',
};
}
export const dataSource = new DataSource({
type: 'postgres',
host: configService.get('database_host'),
port: configService.get('database_port'),
username: configService.get('database_username'),
password: configService.get('database_password'),
database: configService.get('database_name'),
entities: [[__dirname, '**', '*.entity.{ts,js}'].join('/')],
migrations: [[__dirname, 'migrations', '*.{ts,js}'].join('/')],
autoLoadEntities: true,
synchronize: true,
} as any);
configService.set('database', dataSource);