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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # Master (Unreleased)
2
2
 
3
+ # 1.0.7 - 13 March, 2022
4
+
5
+ ### Bug fixes:
6
+
7
+ - CLI: Fix cli migrate:make SQLite dependency #5106
8
+
3
9
  # 1.0.6 - 12 March, 2022
4
10
 
5
11
  ### Bug fixes:
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, noClientOverride) {
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, noClientOverride);
62
+ : mkConfigObj(opts);
58
63
 
59
- let resolvedConfig = resolveEnvironmentConfig(
64
+ const resolvedConfig = resolveEnvironmentConfig(
60
65
  opts,
61
66
  env.configuration,
62
67
  env.configPath
63
68
  );
64
69
 
65
- // In the other case, config is already override in mkConfigObj.
66
- if (env.configPath) {
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 && !resolvedConfig.migrations.directory) {
73
- resolvedConfig.migrations.directory = null;
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(resolvedConfig);
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
- const opts = commander.opts();
213
- opts.client = opts.client || 'sqlite3'; // We don't really care about client when creating migrations
214
- const instance = await initKnex(env, opts, true);
215
- const ext = getMigrationExtension(env, opts);
216
- const configOverrides = { extension: ext };
217
-
218
- const stub = getStubPath('migrations', env, opts);
219
- if (stub) {
220
- configOverrides.stub = stub;
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
- instance.migrate
224
- .make(name, configOverrides)
225
- .then((name) => {
226
- success(color.green(`Created Migration: ${name}`));
227
- })
228
- .catch(exit);
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
- const opts = commander.opts();
380
- opts.client = opts.client || 'sqlite3'; // We don't really care about client when creating seeds
381
- const instance = await initKnex(env, opts);
382
- const ext = getSeedExtension(env, opts);
383
- const configOverrides = { extension: ext };
384
- const stub = getStubPath('seeds', env, opts);
385
- if (stub) {
386
- configOverrides.stub = stub;
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
- if (opts.timestampFilenamePrefix) {
390
- configOverrides.timestampFilenamePrefix = opts.timestampFilenamePrefix;
391
- }
399
+ if (opts.timestampFilenamePrefix) {
400
+ configOverrides.timestampFilenamePrefix = opts.timestampFilenamePrefix;
401
+ }
392
402
 
393
- instance.seed
394
- .make(name, configOverrides)
395
- .then((name) => {
396
- success(color.green(`Created seed file: ${name}`));
397
- })
398
- .catch(exit);
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, noClientOverride) {
9
+ function parseConfigObj(opts) {
10
10
  const config = { migrations: {} };
11
11
 
12
- if (opts.client && (!noClientOverride || !config.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, noClientOverride) {
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, noClientOverride);
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,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knex",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "A batteries-included SQL query & schema builder for PostgresSQL, MySQL, CockroachDB, MSSQL and SQLite3",
5
5
  "main": "knex",
6
6
  "types": "types/index.d.ts",