-
Notifications
You must be signed in to change notification settings - Fork 0
/
ormconfig.ts
56 lines (51 loc) · 1.51 KB
/
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { ConnectionOptions } from 'typeorm';
import {
TYPEORM_HOST,
TYPEORM_USERNAME,
TYPEORM_PASSWORD,
TYPEORM_DATABASE,
TYPEORM_PORT,
TYPEORM_SYNCHRONIZE,
TYPEORM_LOGGING,
TYPEORM_MIGRATIONS_RUN,
PRODUCTION_ENV,
TYPEORM_TYPE,
IS_COT_DEPENDENT_SERVICE,
log4TSProvider
} from '@config';
// TODO: import ECEntity from key-manager
import { DidEntity, ECEntity } from 'lacchain-identity';
const log = log4TSProvider.getLogger('ormConfig');
const config: ConnectionOptions = {
type: TYPEORM_TYPE as 'mysql' | 'postgres' | 'mongodb',
host: TYPEORM_HOST,
username: TYPEORM_USERNAME,
password: TYPEORM_PASSWORD,
database: TYPEORM_DATABASE,
port: Number.parseInt(TYPEORM_PORT || '5432'),
synchronize: TYPEORM_SYNCHRONIZE === 'true',
logging: TYPEORM_LOGGING === 'true' ? ['error'] : false,
entities: [
PRODUCTION_ENV ? 'dist/src/entities/**/*.js' : 'src/entities/**/*.ts'
],
migrations: [
PRODUCTION_ENV
? 'dist/src/database/migrations/**/*.js'
: 'src/database/migrations/**/*.ts'
],
migrationsRun: TYPEORM_MIGRATIONS_RUN === 'true',
cli: {
migrationsDir: PRODUCTION_ENV
? 'dist/src/database/migrations'
: 'src/database/migrations',
entitiesDir: PRODUCTION_ENV ? 'dist/src/entities' : 'src/entities'
}
};
if (IS_COT_DEPENDENT_SERVICE !== 'true') {
log.info('Importing entities from external components');
config.entities?.push(DidEntity);
config.entities?.push(ECEntity);
} else {
log.info('Initializing with local entities');
}
export = config;