-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathknexfile.js
76 lines (71 loc) · 1.86 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
require('./loadEnv')();
const config = {
debug: false,
client: 'pg',
version: process.env.PG_VERSION,
connection: {
host: process.env.PG_HOST,
port: parseInt(process.env.PG_PORT, 10),
user: process.env.PG_USER,
password: process.env.PG_PASSWORD,
database: process.env.PG_DB_NAME,
},
pool: {
min: parseInt(process.env.PG_POOL_MIN, 10) || 2,
max: parseInt(process.env.PG_POOL_MAX, 10) || 10,
},
migrations: {
directory: './src/postgres/migrations',
},
// seeds: { directory: './data/seeds' },
};
if (process.env.NODE_ENV !== 'migrate' && process.env.NODE_ENV !== 'migrate_docker') {
// eslint-disable-next-line global-require
const logger = require('./src/lib/logger')(module);
config.log = {
warn(message) {
logger.warn('knexWarn', { customInput: { message } });
},
error(message) {
logger.error('knexError', { customInput: { message } });
},
deprecate(message) {
logger.knex('knexDeprecate', { customInput: { message } });
},
debug(message) {
logger.knex('knexDebug', { customInput: { message } });
},
};
}
if (process.env.NODE_ENV === 'migrate_docker') {
config.connection = {
host: 'localhost',
port: 5477,
user: process.env.PG_USER,
password: process.env.PG_PASSWORD,
database: process.env.PG_DB_NAME,
};
}
if (process.env.NODE_ENV === 'test') {
config.connection = {
host: process.env.TEST_PG_HOST,
port: process.env.TEST_PG_PORT,
user: process.env.PG_USER,
password: process.env.PG_PASSWORD,
database: process.env.TEST_PG_DB_NAME,
};
}
module.exports = {
config,
migrate: config,
migrate_docker: config,
dev: config,
test: config,
production: config,
onUpdateTrigger: table => `
CREATE TRIGGER ${table}_updated_at
BEFORE UPDATE ON ${table}
FOR EACH ROW
EXECUTE PROCEDURE on_update_timestamp();
`,
};