forked from gothinkster/koa-knex-realworld-example
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathknexfile.js
59 lines (50 loc) · 1.12 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
require("./src/lib/bootstrap")
const config = require("config")
const fs = require("fs")
if (config.get("db.client") === "sqlite3") {
try {
fs.mkdirSync("data")
} catch (err) {
if (err.code !== "EEXIST") {
throw err
}
}
}
const dbClient = config.get("db.client")
const dbConnection = config.has("db.connection") && config.get("db.connection")
const options = {
client: dbClient,
connection: dbConnection || {
filename: "data/dev.sqlite3",
},
migrations: {
directory: "src/migrations",
tableName: "migrations",
},
debug: false,
seeds: {
directory: "src/seeds",
},
useNullAsDefault: dbClient === "sqlite3",
}
if (dbClient !== "sqlite3") {
options.pool = {
min: 2,
max: 10,
}
}
const configs = {
development: Object.assign({}, options),
test: Object.assign({}, options, {
connection: dbConnection || {
filename: "data/test.sqlite3",
},
}),
production: Object.assign({}, options, {
connection: dbConnection || {
filename: "data/prod.sqlite3",
},
}),
}
Object.assign(configs, configs[process.env.NODE_ENV])
module.exports = configs