-
Notifications
You must be signed in to change notification settings - Fork 1
/
ormconfig.js
78 lines (70 loc) · 2.06 KB
/
ormconfig.js
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
const DefaultNamingStrategy = require('typeorm').DefaultNamingStrategy;
const snakeCase = require('typeorm/util/StringUtils').snakeCase;
const pluralize = require('pluralize');
class TypeOrmNamingStrategy extends DefaultNamingStrategy {
tableName(className, customName) {
return customName || pluralize(snakeCase(className));
}
columnName(propertyName, customName, embeddedPrefixes) {
return (
snakeCase(embeddedPrefixes.join('_')) +
(customName || snakeCase(propertyName))
);
}
relationName(propertyName) {
return snakeCase(propertyName);
}
joinColumnName(relationName, referencedColumnName) {
return snakeCase(
pluralize.singular(relationName) + '_' + referencedColumnName,
);
}
joinTableName(
firstTableName,
secondTableName,
firstPropertyName,
secondPropertyName,
) {
return snakeCase(firstTableName + '_' + secondTableName);
}
joinTableColumnName(tableName, propertyName, columnName) {
return snakeCase(
pluralize.singular(tableName) + '_' + (columnName || propertyName),
);
}
classTableInheritanceParentColumnName(
parentTableName,
parentTableIdPropertyName,
) {
return snakeCase(
pluralize.singular(parentTableName) + '_' + parentTableIdPropertyName,
);
}
}
// subscribersはDIを使うためコード内から投入する
module.exports = {
type: 'mysql',
port: 3306,
host: process.env.DB_HOST,
username: process.env.DB_USERNAME,
password: process.env.DB_PASSWORD,
database: process.env.DB_DATABASE,
entities: ['dist/**/*.model{.ts,.js}'],
synchronize: process.env.DB_SYNCHRONIZE === 'true' ? true : false,
migrationsTableName: 'migrations',
migrations: ['dist/migrations/*{.ts,.js}'],
cli: {
migrationsDir: 'src/migrations',
},
namingStrategy: new TypeOrmNamingStrategy(),
logging: false,
//logging: process.env.SQL_LOG ? !!process.env.SQL_LOG : false,
extra: {
connectionLimit:
process.env.NODE_ENV === 'production'
? 125
: process.env.NODE_ENV === 'staging'
? 100
: 10,
},
};