Repository navigation
Expand file tree
/
Copy pathknexfile.js
More file actions
59 lines (50 loc) · 1.67 KB
/
Copy pathknexfile.js
File metadata and controls
59 lines (50 loc) · 1.67 KB
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
'use strict';
/**
* Knex configuration (issue #252).
*
* Migration files already existed under src/db/migrations, but there was no
* knexfile and knex was not a dependency, so nothing could actually run
* them. This wires them up and points knex at the same DATABASE_URL the
* rest of the service uses.
*
* `migrations.tableName` is left at knex's default (`knex_migrations`);
* the dedicated status tracking the issue asks for lives in a separate
* table written by src/db/migrationSafety.js, so knex's own bookkeeping
* stays untouched and recoverable.
*/
require('dotenv').config();
const path = require('path');
const migrations = {
directory: path.join(__dirname, 'src', 'db', 'migrations'),
extension: 'js',
disableTransactions: false,
};
function connectionFor(fallback) {
return process.env.DATABASE_URL || fallback;
}
// Issue #494 — migrations and ad-hoc knex CLI queries must render timestamps
// in UTC too, not in the database server's local zone. Runs per pooled
// connection.
function afterCreateUtcConnection(conn, done) {
conn.query("SET TIME ZONE 'UTC'", (err) => done(err, conn));
}
module.exports = {
development: {
client: 'pg',
connection: connectionFor('postgres://localhost/smartdrop'),
pool: { min: 2, max: 10, afterCreate: afterCreateUtcConnection },
migrations,
},
test: {
client: 'pg',
connection: connectionFor('postgres://localhost/smartdrop_test'),
pool: { min: 2, max: 10, afterCreate: afterCreateUtcConnection },
migrations,
},
production: {
client: 'pg',
connection: connectionFor(undefined),
pool: { min: 2, max: 10, afterCreate: afterCreateUtcConnection },
migrations,
},
};