forked from ZeppelinBot/Zeppelin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathormconfig.js
60 lines (51 loc) · 1.61 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
const fs = require('fs');
const path = require('path');
try {
fs.accessSync(path.resolve(__dirname, 'bot.env'));
require('dotenv').config({ path: path.resolve(__dirname, 'bot.env') });
} catch (e) {
try {
fs.accessSync(path.resolve(__dirname, 'api.env'));
require('dotenv').config({ path: path.resolve(__dirname, 'api.env') });
} catch (e) {
throw new Error("bot.env or api.env required");
}
}
const moment = require('moment-timezone');
moment.tz.setDefault('UTC');
const entities = process.env.NODE_ENV === 'production'
? path.relative(process.cwd(), path.resolve(__dirname, 'dist/data/entities/*.js'))
: path.relative(process.cwd(), path.resolve(__dirname, 'src/data/entities/*.ts'));
const migrations = process.env.NODE_ENV === 'production'
? path.relative(process.cwd(), path.resolve(__dirname, 'dist/migrations/*.js'))
: path.relative(process.cwd(), path.resolve(__dirname, 'src/migrations/*.ts'));
module.exports = {
type: "mysql",
host: process.env.DB_HOST,
username: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_DATABASE,
charset: 'utf8mb4',
supportBigNumbers: true,
bigNumberStrings: true,
dateStrings: true,
synchronize: false,
connectTimeout: 2000,
// Entities
entities: [entities],
// Pool options
extra: {
typeCast(field, next) {
if (field.type === 'DATETIME') {
const val = field.string();
return val != null ? moment(val).format('YYYY-MM-DD HH:mm:ss') : null;
}
return next();
}
},
// Migrations
migrations: [migrations],
cli: {
migrationsDir: path.dirname(migrations)
},
};