db-migrate 1.0.0-beta.2 → 1.0.0-beta.21

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.
Files changed (50) hide show
  1. package/LICENSE +26 -0
  2. package/README.md +1 -15
  3. package/api.js +22 -15
  4. package/connect.js +6 -6
  5. package/index.js +10 -13
  6. package/lib/chain.js +66 -11
  7. package/lib/commands/check.js +3 -3
  8. package/lib/commands/create-migration.js +121 -28
  9. package/lib/commands/db.js +2 -0
  10. package/lib/commands/down.js +1 -1
  11. package/lib/commands/dump.js +22 -0
  12. package/lib/commands/generated.js +32 -0
  13. package/lib/commands/helper/register-events.js +2 -0
  14. package/lib/commands/run.js +4 -9
  15. package/lib/commands/set-default-argv.js +13 -15
  16. package/lib/commands/sync.js +3 -3
  17. package/lib/commands/up.js +3 -3
  18. package/lib/config.js +2 -2
  19. package/lib/driver/index.js +37 -11
  20. package/lib/executors/versioned/v2.js +13 -3
  21. package/lib/file.js +2 -4
  22. package/lib/learn.js +64 -31
  23. package/lib/methods/v2/conventions.js +47 -0
  24. package/lib/methods/v2/statetravel.js +11 -9
  25. package/lib/methods/v2/translatestate.js +45 -12
  26. package/lib/state.js +5 -5
  27. package/lib/template.js +34 -4
  28. package/lib/templates/v2.js +12 -0
  29. package/lib/temputils.js +8 -0
  30. package/lib/walker.js +17 -2
  31. package/package.json +29 -24
  32. package/.eslintrc +0 -8
  33. package/.jscsrc +0 -0
  34. package/.jshintignore +0 -2
  35. package/.jshintrc +0 -14
  36. package/.prettierrc +0 -3
  37. package/.tern-project +0 -7
  38. package/.travis.yml +0 -47
  39. package/CHANGELOG.md +0 -474
  40. package/CODE_OF_CONDUCT.md +0 -46
  41. package/CONTRIBUTING.md +0 -81
  42. package/Makefile +0 -8
  43. package/commitlint.config.js +0 -1
  44. package/lib/commands/transition.js +0 -5
  45. package/lib/transitions/1.js +0 -30
  46. package/lib/transitions/ask.js +0 -22
  47. package/lib/transitions/snippets/setup.sjs +0 -8
  48. package/lib/transitions/transitioner.js +0 -78
  49. package/lib/transitions/try-require.js +0 -113
  50. package/lib/transitions/update-version.js +0 -48
package/lib/template.js CHANGED
@@ -1,9 +1,14 @@
1
1
  'use strict';
2
2
 
3
3
  const File = require('./file.js');
4
- const dbmUtil = require('db-migrate-shared').util;
4
+ const { util: dbmUtil, log } = require('db-migrate-shared');
5
5
 
6
6
  const Template = function () {
7
+ if (arguments[4] && typeof arguments[4].overwrite === 'function') {
8
+ this.plugins = arguments[4];
9
+ arguments[4] = undefined;
10
+ arguments.length--;
11
+ }
7
12
  this.templateType = arguments[3];
8
13
  // this is a tweak for node 4 this can be translated
9
14
  // to ...arguments instead in upcoming node versions
@@ -253,10 +258,13 @@ Template.TemplateType = {
253
258
  SQL_FILE_LOADER: 2,
254
259
  DEFAULT_COFFEE: 3,
255
260
  COFFEE_SQL_FILE_LOADER: 4,
256
- SQL_FILE_LOADER_IGNORE_ON_INIT: 5
261
+ SQL_FILE_LOADER_IGNORE_ON_INIT: 5,
262
+ V2_DEFAULT: 6
257
263
  };
258
264
 
259
265
  Template.prototype.getTemplate = function () {
266
+ let plugin = false;
267
+
260
268
  switch (this.templateType) {
261
269
  case Template.TemplateType.DEFAULT_SQL:
262
270
  return this.defaultSqlTemplate();
@@ -269,9 +277,31 @@ Template.prototype.getTemplate = function () {
269
277
  case Template.TemplateType.SQL_FILE_LOADER_IGNORE_ON_INIT:
270
278
  return this.sqlFileLoaderIgnoreOnInitTemplate();
271
279
  case Template.TemplateType.DEFAULT_JS:
272
- /* falls through */
273
- default:
274
280
  return this.defaultJsTemplate();
281
+ case Template.TemplateType.V2_DEFAULT:
282
+ return require('./templates/v2.js')();
283
+ default:
284
+ if (this.plugins) {
285
+ plugin = this.plugins.overwrite(
286
+ `template:overwrite:provider:${this.templateType}`
287
+ );
288
+ }
289
+
290
+ if (plugin !== false) {
291
+ try {
292
+ return plugin[`template:overwrite:provider:${this.templateType}`]({
293
+ file: {
294
+ name: this.file.name
295
+ }
296
+ });
297
+ } catch (ex) {
298
+ log.error('Plugin failure "' + plugin.name + '", arborting!');
299
+
300
+ throw ex;
301
+ }
302
+ } else {
303
+ return this.defaultJsTemplate();
304
+ }
275
305
  }
276
306
  };
277
307
 
@@ -0,0 +1,12 @@
1
+ 'use strict';
2
+
3
+ module.exports = () => `'use strict';
4
+
5
+ exports.migrate = async (db, opt) => {
6
+ const type = opt.dbm.dataType;
7
+ return null;
8
+ };
9
+
10
+ exports._meta = {
11
+ version: 2
12
+ };`;
package/lib/temputils.js CHANGED
@@ -10,6 +10,14 @@ function isPromise (probe) {
10
10
  );
11
11
  }
12
12
 
13
+ /**
14
+ * Backwards compatibility function.
15
+ *
16
+ * This ensures old migrations can still be executed by allowing them
17
+ * to still use callbacks or promises. This function ensures that every
18
+ * execution context may be returned only once (since callbacks can be called
19
+ * multiple times) and is basically FI(-only-)FO function.
20
+ */
13
21
  function maybePromised (context, action, params) {
14
22
  let cbExecuted = false;
15
23
 
package/lib/walker.js CHANGED
@@ -30,7 +30,19 @@ const Walker = function (driver, directory, mode, intern, prefix) {
30
30
  Promise.promisifyAll(this._driver);
31
31
  this.directory = directory;
32
32
  this.internals = intern;
33
- this.internals.schema = { i: {}, c: {}, f: {} };
33
+ /**
34
+ * i: index
35
+ * c: schema
36
+ * f: foreignKey
37
+ * e: extra items for the schema (like ENUM tyes)
38
+ */
39
+ this.internals.schema = { i: {}, c: {}, f: {}, e: {} };
40
+ /**
41
+ * s: commands
42
+ * i: index
43
+ * f: foreignKey
44
+ * c: schema
45
+ */
34
46
  this.internals.modSchema = { i: {}, c: {}, f: {}, s: [] };
35
47
  this.mode = mode;
36
48
 
@@ -241,7 +253,10 @@ Walker.prototype = {
241
253
  // Requires pr to export filterCompleted from db-migrate-shared
242
254
  const toRun = dbmUtil.filterCompleted(allFiles, completedFiles);
243
255
 
244
- log.info('Files to run:', toRun.map(migration => migration.name));
256
+ log.info(
257
+ 'Files to run:',
258
+ toRun.map(migration => migration.name)
259
+ );
245
260
  return toRun;
246
261
  })
247
262
  .nodeify(callback);
package/package.json CHANGED
@@ -31,9 +31,9 @@
31
31
  "programable",
32
32
  "api"
33
33
  ],
34
- "version": "1.0.0-beta.2",
34
+ "version": "1.0.0-beta.21",
35
35
  "engines": {
36
- "node": ">=0.6.0"
36
+ "node": ">=8.0.0"
37
37
  },
38
38
  "bugs": {
39
39
  "url": "https://github.com/db-migrate/node-db-migrate/issues"
@@ -44,41 +44,46 @@
44
44
  "url": "https://github.com/db-migrate/node-db-migrate.git"
45
45
  },
46
46
  "dependencies": {
47
- "balanced-match": "^1.0.0",
48
- "bluebird": "^3.1.1",
47
+ "bluebird": "^3.7.2",
49
48
  "db-migrate-shared": "^1.2.0",
50
49
  "deep-extend": "^0.6.0",
51
50
  "dotenv": "^5.0.1",
52
51
  "final-fs": "^1.6.0",
53
52
  "inflection": "^1.10.0",
54
53
  "mkdirp": "~0.5.0",
55
- "optimist": "~0.6.1",
56
54
  "parse-database-url": "~0.3.0",
57
- "pkginfo": "^0.4.0",
58
- "prompt": "^1.0.0",
59
55
  "rc": "^1.2.8",
60
- "resolve": "^1.1.6",
56
+ "resolve": "^1.19.0",
61
57
  "semver": "^5.3.0",
62
- "tunnel-ssh": "^4.0.0"
58
+ "tunnel-ssh": "^4.0.0",
59
+ "yargs": "^17.5.1"
63
60
  },
64
61
  "devDependencies": {
65
- "code": "^4.1.0",
66
- "db-migrate-base": "^1.2.5",
67
- "db-migrate-mysql": "^1.1.10",
68
- "db-migrate-sqlite3": "^0.3.1",
69
- "eslint": "^5.12.0",
70
- "eslint-config-standard": "^12.0.0",
71
- "eslint-plugin-import": "^2.14.0",
72
- "eslint-plugin-node": "^8.0.1",
73
- "eslint-plugin-promise": "^4.0.1",
74
- "eslint-plugin-standard": "^4.0.0",
75
- "lab": "^14.3.1",
62
+ "@babel/eslint-parser": "^7.21.8",
63
+ "@hapi/code": "9.x",
64
+ "@hapi/eslint-plugin": "^6.0.0",
65
+ "@hapi/lab": "25.x",
66
+ "db-migrate-base": "^2.1.1",
67
+ "db-migrate-mysql": "^2.1.1",
68
+ "db-migrate-sqlite3": "^0.4.0",
69
+ "eslint": "^7.32.0",
70
+ "eslint-config-standard": "^14.1.1",
71
+ "eslint-plugin-import": "^2.26.0",
72
+ "eslint-plugin-node": "^11.1.0",
73
+ "eslint-plugin-promise": "^4.3.1",
74
+ "eslint-plugin-standard": "^4.1.0",
76
75
  "proxyquire": "^1.4.0",
77
- "rimraf": "^2.6.2",
78
- "sinon": "^7.2.2"
76
+ "rimraf": "^3.0.2",
77
+ "sinon": "^9.0.2"
78
+ },
79
+ "funding": {
80
+ "type": "opencollective",
81
+ "url": "https://opencollective.com/node-db-migrate"
79
82
  },
80
83
  "scripts": {
81
- "pretest": "eslint *.js lib/*.js test/*.js bin/*",
82
- "test": "make test-cov"
84
+ "prepublishOnly": "node generateLoader.js",
85
+ "pretest": "eslint *.js lib/*.js",
86
+ "test": "lab",
87
+ "test:coverage": "lab -r html -o coverage.html"
83
88
  }
84
89
  }
package/.eslintrc DELETED
@@ -1,8 +0,0 @@
1
- {
2
- "extends": "standard",
3
- "rules": {
4
- "semi": ["error", "always"],
5
- "no-unused-vars": "warn",
6
- "quotes": ["error", "single", { "avoidEscape": true, "allowTemplateLiterals": true }]
7
- }
8
- }
package/.jscsrc DELETED
File without changes
package/.jshintignore DELETED
@@ -1,2 +0,0 @@
1
- node_modules
2
- lib/inflection.js
package/.jshintrc DELETED
@@ -1,14 +0,0 @@
1
- {
2
- "expr": true,
3
- "-W092": false,
4
- "quotmark": true,
5
- "curly": false,
6
- "bitwise": false,
7
- "eqeqeq": true,
8
- "funcscope": true,
9
- "futurehostile": true,
10
- "nonew": true,
11
- "unused": true,
12
- "shadow": true,
13
- "loopfunc": true
14
- }
package/.prettierrc DELETED
@@ -1,3 +0,0 @@
1
- {
2
- "singleQuote": true
3
- }
package/.tern-project DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "plugins": {
3
- "node": {},
4
- "lint": {},
5
- "node-extension": {}
6
- }
7
- }
package/.travis.yml DELETED
@@ -1,47 +0,0 @@
1
- language: node_js
2
-
3
- node_js:
4
- - 8
5
- - 10
6
- - node
7
-
8
- notifications:
9
- email:
10
- recipients:
11
- - magic@wizardtales.com
12
- webhooks:
13
- urls:
14
- - https://webhooks.gitter.im/e/509c88551a18006fe93f
15
- on_success: change
16
- on_failure: always
17
- on_start: false
18
-
19
- os:
20
- - linux
21
-
22
- matrix:
23
- allow_failures:
24
- - node_js: node
25
- fast_finish: true
26
-
27
- sudo: false
28
-
29
- cache:
30
- npm: true
31
- directories:
32
- - node_modules
33
-
34
- addons:
35
- apt:
36
- sources:
37
- - ubuntu-toolchain-r-test
38
- packages:
39
- - g++-4.8
40
-
41
- before_install:
42
- - export CXX=g++-4.8; export CC=gcc-4.8;
43
-
44
- install: npm install
45
-
46
- before_script:
47
- - cp test/db.config.ci test/db.config.json