-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathknexfile.js
59 lines (54 loc) · 1.74 KB
/
knexfile.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
var nconf = require('nconf');
var conf_file = './config/config.json';
var logger = require('./log');
var loglevel = nconf.get('global:loglevel');
if(loglevel = 'debug') {
var debugon = true
} else {
var debugon = false
}
var dbtype = nconf.get('database:type');
//in order to create migration files, client must be hardcoded to 'sqlite3' otherwise it won't work.
var dbconfig = {
client: dbtype,
connection: {},
useNullAsDefault: true,
debug: debugon,
migrations: {
tableName: 'knex_migrations',
directory: __dirname + '/knex/migrations'
},
log: {
warn(message) {
logger.db.info(JSON.stringify(message))
},
error(message) {
logger.db.error(JSON.stringify(message))
},
deprecate(message) {
logger.db.info(JSON.stringify(message))
},
debug(message) {
logger.db.debug(JSON.stringify(message))
},
}
}
if (dbtype == 'sqlite3') {
dbconfig.connection.filename = nconf.get('database:file');
} else if (dbtype == 'mysql') {
dbconfig.connection.host = nconf.get('database:server');
dbconfig.connection.user = nconf.get('database:username');
dbconfig.connection.password = nconf.get('database:password');
dbconfig.connection.database = nconf.get('database:database');
} else if (dbtype == 'oracledb') {
dbconfig.connection.connectString = nconf.get('database:connectString');
dbconfig.connection.user = nconf.get('database:username');
dbconfig.connection.password = nconf.get('database:password');
dbconfig.fetchAsString = ['clob'];
}
//this is required because of the silly way knex migrations handle environments
module.exports = Object.assign({}, dbconfig, {
development: dbconfig,
staging: dbconfig,
production: dbconfig,
});