This repository has been archived by the owner on Aug 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
knexfile.js
85 lines (76 loc) · 1.98 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
77
78
79
80
81
82
83
84
85
import path from 'path';
import pg from 'pg';
import range from 'pg-range';
range.install(pg);
const __dirname = path.resolve();
const BASE_PATH = path.normalize(path.join(__dirname, 'src', 'backend'));
const DB_PATH = path.join(BASE_PATH, 'db');
const COMMON_MIGRATIONS_PATH = path.join(DB_PATH, 'migrations', 'common');
const MIGRATIONS_TABLE = 'knex_migrations';
import config from './src/backend/config.js';
const _migrations_pg = {
tableName: MIGRATIONS_TABLE,
directory: [path.join(DB_PATH, 'migrations', 'pg'), COMMON_MIGRATIONS_PATH],
};
const _migrations_sqlite3 = {
tableName: MIGRATIONS_TABLE,
directory: COMMON_MIGRATIONS_PATH,
};
const _seeds = {
directory: path.normalize(path.join(DB_PATH, 'seeds', config.env)),
};
var env;
if (config.isDev) {
console.log('Loading development database settings...');
env = {
client: 'sqlite3',
connection: {
filename: './dev.sqlite3',
},
debug: true,
migrations: _migrations_sqlite3,
seeds: _seeds,
useNullAsDefault: true,
};
} else if (config.isTest) {
console.log('Loading testing database settings...');
env = {
client: 'sqlite3',
connection: ':memory:',
debug: false,
migrations: _migrations_sqlite3,
seeds: _seeds,
useNullAsDefault: true,
};
} else {
console.log('Loading database settings...');
const isDebug = config.log_level === 'debug';
// Needed sometimes when connecting to Heroku locally
// Tip from https://www.shanestillwell.com/2018/06/29/setting-up-knex-project/
if (/sslmode=require/.test(config.dbUrl)) {
pg.defaults.ssl = true;
}
env = {
client: 'pg',
connection: config.dbUrl,
pool: {
min: config.dbPoolMin,
max: config.dbPoolMax,
},
acquireConnectionTimeout: config.dbTimeout,
debug: isDebug,
migrations: _migrations_pg,
seeds: _seeds,
useNullAsDefault: false,
};
}
export const {
client,
connection,
pool,
acquireConnectionTimeout,
debug,
migrations,
seeds,
useNullAsDefault,
} = env;