-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathknexfile.js
90 lines (85 loc) · 1.85 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import config from '#config';
export const generateKnexConfig = (conf, id = 0) => {
id = '_' + id;
switch (conf.client) {
case 'mysql':
case 'mysql2':
return getMysqlConfig(conf, id);
case 'sqlite3':
case 'better-sqlite3':
return getSqlite3Config(conf, id);
case 'pg':
return getPostgreConfig(conf, id);
default:
throw Error(`Unknown database client : ${conf.client}`);
}
};
const getMysqlConfig = (conf, id) => {
return {
client: conf.client,
debug: conf.debug || false,
connection: {
host: conf.host,
port: conf.port,
user: conf.user,
password: conf.pass,
database: conf.db,
timezone: 'Z',
},
pool: {
min: conf.poolMin || 2,
max: conf.poolMax || 10,
},
userParams: {
client: conf.client + id,
},
};
};
const getPostgreConfig = (conf, id) => {
return {
client: conf.client,
debug: conf.debug || false,
connection: conf.connectionString,
pool: {
min: conf.poolMin || 2,
max: conf.poolMax || 10,
},
userParams: {
client: conf.client + id,
},
};
};
const getSqlite3Config = (conf, id) => {
return {
client: conf.client,
debug: conf.debug || false,
connection: {
filename: conf.name,
flags: conf.flags ? conf.flags.split(',') : [],
timezone: 'Z',
},
pool: {
min: 1,
max: 1,
},
userParams: {
client: conf.client + id,
},
};
};
export default () => {
const autoConf = config.db[config.d];
return {
[config.NODE_ENV]: {
...generateKnexConfig(autoConf),
migrations: {
tableName: '__knex_migrations',
directory: `./database/migrations/${config.d}/`,
stub: `./database/migrations/stub`,
},
seeds: {
directory: `./database/seeds/${config.d}/`,
},
},
};
};