forked from Hylozoic/hylo-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
knexfile.js
75 lines (71 loc) · 2 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
const merge = require('lodash/merge')
require('dotenv').load()
if (!process.env.DATABASE_URL) {
throw new Error('process.env.DATABASE_URL must be set')
}
const url = require('url').parse(process.env.DATABASE_URL)
var user, password
if (url.auth) {
const i = url.auth.indexOf(':')
user = url.auth.slice(0, i)
password = url.auth.slice(i + 1)
}
const defaults = {
client: 'pg',
connection: {
host: url.hostname,
port: url.port,
user: user || 'postgres',
password: password,
database: url.pathname.substring(1)
},
pool: {
// https://github.com/Vincit/objection.js/issues/1137
min: 5, // default 2
max: 30, // default 10
// https://github.com/knex/knex/issues/2820#issuecomment-481710112
propagateCreateError: false // default true (false NOT recommended)
},
migrations: {
tableName: 'knex_migrations'
}
}
module.exports = {
test: defaults,
development: defaults,
dummy: Object.assign({}, defaults, { seeds: { directory: './seeds/dummy' } }),
farmdev: Object.assign({}, defaults, { seeds: { directory: './seeds/farm-dev' } }),
farmdemo: Object.assign({}, defaults, { seeds: { directory: './seeds/farm-demo' } }),
staging: defaults,
production: merge({connection: {ssl: { rejectUnauthorized: false }}}, defaults),
docker: Object.assign({},
defaults,
{
connection: Object.assign({},
defaults.connection,
{ user: 'hylo', password: 'hylo', port: '5300' }
)
}
),
createUpdateTrigger: table => `
CREATE TRIGGER ${table}_updated_at
BEFORE UPDATE ON ${table}
FOR EACH ROW
EXECUTE PROCEDURE on_update_timestamp();
`,
dropUpdateTrigger: table => `
DROP TRIGGER IF EXISTS ${table}_updated_at ON ${table}
`,
createUpdateFunction: () => `
CREATE OR REPLACE FUNCTION on_update_timestamp()
RETURNS trigger AS $$
BEGIN
NEW.updated_at = now();
RETURN NEW;
END;
$$ language 'plpgsql';
`,
dropUpdateFunction: () => `
DROP FUNCTION IF EXISTS on_update_timestamp()
`
}