-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathormconfig.ts
54 lines (48 loc) · 1.66 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
import { DefaultNamingStrategy } from 'typeorm/naming-strategy/DefaultNamingStrategy';
import { NamingStrategyInterface } from 'typeorm/naming-strategy/NamingStrategyInterface';
import { snakeCase } from 'typeorm/util/StringUtils';
import { config } from './config';
export class CustomNamingStrategy
extends DefaultNamingStrategy
implements NamingStrategyInterface
{
tableName(targetName: string, userSpecifiedName: string): string {
return userSpecifiedName ? userSpecifiedName : snakeCase(targetName) + 's';
}
columnName(
propertyName: string,
customName: string,
embeddedPrefixes: string[],
): string {
return snakeCase(
embeddedPrefixes.concat(customName ? customName : propertyName).join('_'),
);
}
columnNameCustomized(customName: string): string {
return customName;
}
relationName(propertyName: string): string {
return snakeCase(propertyName);
}
}
export const SOURCE_PATH = config.ENV === 'production' ? 'dist/src' : 'src';
export const options = {
type: config.PROJECTION_DB_SETTINGS.type,
host: config.PROJECTION_DB_SETTINGS.hostname,
port: config.PROJECTION_DB_SETTINGS.port,
username: config.PROJECTION_DB_SETTINGS.credentials.username,
password: config.PROJECTION_DB_SETTINGS.credentials.password,
database: config.PROJECTION_DB_SETTINGS.database,
migrationsTableName: 'migration',
entities: [`${SOURCE_PATH}/**/*.entity{.ts,.js}`],
migrations: [`${SOURCE_PATH}/migrations/*{.ts,.js}`],
namingStrategy: new CustomNamingStrategy(),
synchronize: false,
logging: false,
ssl: config.ENV === 'production' && {
rejectUnauthorized: false,
},
cli: {
migrationsDir: 'src/migrations',
},
};