-
Notifications
You must be signed in to change notification settings - Fork 0
/
knexfile.js
47 lines (40 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
require('dotenv').config({ path: __dirname+'/.env' });
const getConnstring = () => {
const {DATABASE_URL} = process.env
if (process.env.NODE_ENV === "production") {
if (!DATABASE_URL?.length) {
throw new Error("DATABASE_URL is not set!")
}
return process.env.DATABASE_URL
} else {
const {POSTGRES_1_0_POSTGRES_SERVICE_HOST, POSTGRES_1_0_POSTGRES_SERVICE_PORT, DB_PASS, DB_USER} = process.env
if (POSTGRES_1_0_POSTGRES_SERVICE_HOST && POSTGRES_1_0_POSTGRES_SERVICE_PORT) {
return `postgres://${DB_USER}:${DB_PASS}@${POSTGRES_1_0_POSTGRES_SERVICE_HOST}:${POSTGRES_1_0_POSTGRES_SERVICE_PORT}/fk`
}
if(!DATABASE_URL?.length) {
throw new Error("DATABASE_URL is not set!")
}
return DATABASE_URL
}
}
module.exports = {
test: {
client: "pg",
connection: process.env.DATABASE_TEST_URL,
migrations: {
stub: "migration.stub.js",
},
},
client: "pg",
connection: getConnstring(),
migrations: {
stub: "migration.stub.js",
},
postgres: {
client: "pg",
connection: getConnstring(),
migrations: {
stub: "migration.stub.js",
},
}
}