knex 1.0.6 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/bin/cli.js +58 -45
- package/bin/utils/cli-config-utils.js +13 -10
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/bin/cli.js
CHANGED
|
@@ -16,6 +16,7 @@ const {
|
|
|
16
16
|
exit,
|
|
17
17
|
success,
|
|
18
18
|
checkLocalModule,
|
|
19
|
+
checkConfigurationOptions,
|
|
19
20
|
getMigrationExtension,
|
|
20
21
|
getSeedExtension,
|
|
21
22
|
getStubPath,
|
|
@@ -42,7 +43,7 @@ async function openKnexfile(configPath) {
|
|
|
42
43
|
return config;
|
|
43
44
|
}
|
|
44
45
|
|
|
45
|
-
async function initKnex(env, opts,
|
|
46
|
+
async function initKnex(env, opts, useDefaultClientIfNotSpecified) {
|
|
46
47
|
checkLocalModule(env);
|
|
47
48
|
if (process.cwd() !== env.cwd) {
|
|
48
49
|
process.chdir(env.cwd);
|
|
@@ -52,29 +53,35 @@ async function initKnex(env, opts, noClientOverride) {
|
|
|
52
53
|
);
|
|
53
54
|
}
|
|
54
55
|
|
|
56
|
+
if (!useDefaultClientIfNotSpecified) {
|
|
57
|
+
checkConfigurationOptions(env, opts);
|
|
58
|
+
}
|
|
59
|
+
|
|
55
60
|
env.configuration = env.configPath
|
|
56
61
|
? await openKnexfile(env.configPath)
|
|
57
|
-
: mkConfigObj(opts
|
|
62
|
+
: mkConfigObj(opts);
|
|
58
63
|
|
|
59
|
-
|
|
64
|
+
const resolvedConfig = resolveEnvironmentConfig(
|
|
60
65
|
opts,
|
|
61
66
|
env.configuration,
|
|
62
67
|
env.configPath
|
|
63
68
|
);
|
|
64
69
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const optionsConfig = parseConfigObj(opts, noClientOverride);
|
|
68
|
-
resolvedConfig = merge(resolvedConfig, optionsConfig);
|
|
69
|
-
}
|
|
70
|
+
const optionsConfig = parseConfigObj(opts);
|
|
71
|
+
const config = merge(resolvedConfig, optionsConfig);
|
|
70
72
|
|
|
71
73
|
// Migrations directory gets defaulted if it is undefined.
|
|
72
|
-
if (!env.configPath && !
|
|
73
|
-
|
|
74
|
+
if (!env.configPath && !config.migrations.directory) {
|
|
75
|
+
config.migrations.directory = null;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Client gets defaulted if undefined and it's allowed
|
|
79
|
+
if (useDefaultClientIfNotSpecified && config.client === undefined) {
|
|
80
|
+
config.client = 'sqlite3';
|
|
74
81
|
}
|
|
75
82
|
|
|
76
83
|
const knex = require(env.modulePath);
|
|
77
|
-
return knex(
|
|
84
|
+
return knex(config);
|
|
78
85
|
}
|
|
79
86
|
|
|
80
87
|
function invoke() {
|
|
@@ -209,23 +216,26 @@ function invoke() {
|
|
|
209
216
|
'Specify the migration stub to use. If using <name> the file must be located in config.migrations.directory'
|
|
210
217
|
)
|
|
211
218
|
.action(async (name) => {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
219
|
+
try {
|
|
220
|
+
const opts = commander.opts();
|
|
221
|
+
const instance = await initKnex(env, opts, true); // Skip config check, we don't really care about client when creating migrations
|
|
222
|
+
const ext = getMigrationExtension(env, opts);
|
|
223
|
+
const configOverrides = { extension: ext };
|
|
224
|
+
|
|
225
|
+
const stub = getStubPath('migrations', env, opts);
|
|
226
|
+
if (stub) {
|
|
227
|
+
configOverrides.stub = stub;
|
|
228
|
+
}
|
|
222
229
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
230
|
+
instance.migrate
|
|
231
|
+
.make(name, configOverrides)
|
|
232
|
+
.then((name) => {
|
|
233
|
+
success(color.green(`Created Migration: ${name}`));
|
|
234
|
+
})
|
|
235
|
+
.catch(exit);
|
|
236
|
+
} catch(err) {
|
|
237
|
+
exit(err);
|
|
238
|
+
}
|
|
229
239
|
});
|
|
230
240
|
|
|
231
241
|
commander
|
|
@@ -376,26 +386,29 @@ function invoke() {
|
|
|
376
386
|
false
|
|
377
387
|
)
|
|
378
388
|
.action(async (name) => {
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
389
|
+
try {
|
|
390
|
+
const opts = commander.opts();
|
|
391
|
+
const instance = await initKnex(env, opts, true); // Skip config check, we don't really care about client when creating seeds
|
|
392
|
+
const ext = getSeedExtension(env, opts);
|
|
393
|
+
const configOverrides = { extension: ext };
|
|
394
|
+
const stub = getStubPath('seeds', env, opts);
|
|
395
|
+
if (stub) {
|
|
396
|
+
configOverrides.stub = stub;
|
|
397
|
+
}
|
|
388
398
|
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
399
|
+
if (opts.timestampFilenamePrefix) {
|
|
400
|
+
configOverrides.timestampFilenamePrefix = opts.timestampFilenamePrefix;
|
|
401
|
+
}
|
|
392
402
|
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
403
|
+
instance.seed
|
|
404
|
+
.make(name, configOverrides)
|
|
405
|
+
.then((name) => {
|
|
406
|
+
success(color.green(`Created seed file: ${name}`));
|
|
407
|
+
})
|
|
408
|
+
.catch(exit);
|
|
409
|
+
} catch(err) {
|
|
410
|
+
exit(err);
|
|
411
|
+
}
|
|
399
412
|
});
|
|
400
413
|
|
|
401
414
|
commander
|
|
@@ -6,10 +6,10 @@ const tildify = require('tildify');
|
|
|
6
6
|
const color = require('colorette');
|
|
7
7
|
const argv = require('getopts')(process.argv.slice(2));
|
|
8
8
|
|
|
9
|
-
function parseConfigObj(opts
|
|
9
|
+
function parseConfigObj(opts) {
|
|
10
10
|
const config = { migrations: {} };
|
|
11
11
|
|
|
12
|
-
if (opts.client
|
|
12
|
+
if (opts.client) {
|
|
13
13
|
config.client = opts.client;
|
|
14
14
|
}
|
|
15
15
|
|
|
@@ -28,17 +28,11 @@ function parseConfigObj(opts, noClientOverride) {
|
|
|
28
28
|
return config;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
function mkConfigObj(opts
|
|
32
|
-
if (!opts.client) {
|
|
33
|
-
throw new Error(
|
|
34
|
-
`No configuration file found and no commandline connection parameters passed`
|
|
35
|
-
);
|
|
36
|
-
}
|
|
37
|
-
|
|
31
|
+
function mkConfigObj(opts) {
|
|
38
32
|
const envName = opts.env || process.env.NODE_ENV || 'development';
|
|
39
33
|
const resolvedClientName = resolveClientNameWithAliases(opts.client);
|
|
40
34
|
const useNullAsDefault = resolvedClientName === 'sqlite3';
|
|
41
|
-
const parsedConfig = parseConfigObj(opts
|
|
35
|
+
const parsedConfig = parseConfigObj(opts);
|
|
42
36
|
|
|
43
37
|
return {
|
|
44
38
|
ext: DEFAULT_EXT,
|
|
@@ -105,6 +99,14 @@ function checkLocalModule(env) {
|
|
|
105
99
|
}
|
|
106
100
|
}
|
|
107
101
|
|
|
102
|
+
function checkConfigurationOptions(env, opts) {
|
|
103
|
+
if (!env.configPath && !opts.client) {
|
|
104
|
+
throw new Error(
|
|
105
|
+
`No configuration file found and no commandline connection parameters passed`
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
108
110
|
function getMigrationExtension(env, opts) {
|
|
109
111
|
const config = resolveEnvironmentConfig(
|
|
110
112
|
opts,
|
|
@@ -199,6 +201,7 @@ module.exports = {
|
|
|
199
201
|
exit,
|
|
200
202
|
success,
|
|
201
203
|
checkLocalModule,
|
|
204
|
+
checkConfigurationOptions,
|
|
202
205
|
getSeedExtension,
|
|
203
206
|
getMigrationExtension,
|
|
204
207
|
getStubPath,
|