db-migrate 1.0.0-beta.3 → 1.0.0-beta.30

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 (49) hide show
  1. package/LICENSE +26 -0
  2. package/README.md +1 -5
  3. package/api.js +25 -7
  4. package/connect.js +27 -10
  5. package/lib/chain.js +70 -12
  6. package/lib/commands/check.js +3 -3
  7. package/lib/commands/create-migration.js +28 -3
  8. package/lib/commands/down.js +1 -1
  9. package/lib/commands/dump.js +22 -0
  10. package/lib/commands/fix.js +53 -0
  11. package/lib/commands/generated.js +2 -1
  12. package/lib/commands/helper/register-events.js +2 -0
  13. package/lib/commands/run.js +5 -6
  14. package/lib/commands/set-default-argv.js +7 -2
  15. package/lib/commands/sync.js +3 -3
  16. package/lib/commands/up.js +3 -3
  17. package/lib/driver/index.js +37 -11
  18. package/lib/executors/versioned/v2.js +50 -6
  19. package/lib/learn.js +47 -14
  20. package/lib/methods/v2/statetravel.js +16 -13
  21. package/lib/methods/v2/translatestate.js +53 -16
  22. package/lib/state.js +97 -13
  23. package/lib/template.js +4 -1
  24. package/lib/templates/v2.js +12 -0
  25. package/lib/walker.js +83 -7
  26. package/package.json +20 -17
  27. package/tttt.js +2 -0
  28. package/.eslintignore +0 -1
  29. package/.eslintrc +0 -11
  30. package/.jscsrc +0 -0
  31. package/.jshintignore +0 -2
  32. package/.jshintrc +0 -14
  33. package/.labrc.js +0 -10
  34. package/.prettierrc +0 -3
  35. package/.tern-project +0 -7
  36. package/.travis.yml +0 -47
  37. package/CHANGELOG.md +0 -487
  38. package/CODE_OF_CONDUCT.md +0 -46
  39. package/CONTRIBUTING.md +0 -81
  40. package/commitlint.config.js +0 -1
  41. package/coverage.html +0 -17232
  42. package/generateLoader.js +0 -36
  43. package/lib/commands/transition.js +0 -5
  44. package/lib/transitions/1.js +0 -30
  45. package/lib/transitions/ask.js +0 -22
  46. package/lib/transitions/snippets/setup.sjs +0 -8
  47. package/lib/transitions/transitioner.js +0 -78
  48. package/lib/transitions/try-require.js +0 -113
  49. package/lib/transitions/update-version.js +0 -48
package/lib/walker.js CHANGED
@@ -24,13 +24,27 @@ const INTERFACES = {
24
24
  'static-seed': require('./interface/seederInterface.js')
25
25
  };
26
26
 
27
- const Walker = function (driver, directory, mode, intern, prefix) {
27
+ const Walker = function (driver, directory, mode, intern, prefix, opts = {}) {
28
28
  this.driver = dbmUtil.reduceToInterface(driver, INTERFACES[prefix]);
29
29
  this._driver = driver;
30
+ this._pdriver = opts.db2;
30
31
  Promise.promisifyAll(this._driver);
32
+ Promise.promisifyAll(this._pdriver);
31
33
  this.directory = directory;
32
34
  this.internals = intern;
33
- this.internals.schema = { i: {}, c: {}, f: {} };
35
+ /**
36
+ * i: index
37
+ * c: schema
38
+ * f: foreignKey
39
+ * e: extra items for the schema (like ENUM tyes)
40
+ */
41
+ this.internals.schema = { i: {}, c: {}, f: {}, e: {} };
42
+ /**
43
+ * s: commands
44
+ * i: index
45
+ * f: foreignKey
46
+ * c: schema
47
+ */
34
48
  this.internals.modSchema = { i: {}, c: {}, f: {}, s: [] };
35
49
  this.mode = mode;
36
50
 
@@ -47,12 +61,12 @@ const Walker = function (driver, directory, mode, intern, prefix) {
47
61
  };
48
62
 
49
63
  Walker.prototype = {
50
- createTables: async function () {
51
- await State.init(this._driver, this.internals);
64
+ createTables: async function (options) {
65
+ await State.init(this._pdriver, this.internals, options);
52
66
  return this._driver._createList(this.internals.migrationTable);
53
67
  },
54
68
 
55
- createMigrationsTable: function () {
69
+ createMigrationsTable: function (options = {}) {
56
70
  if (
57
71
  typeof this._driver._createList !== 'function' ||
58
72
  typeof this._driver._getList !== 'function' ||
@@ -73,7 +87,7 @@ Walker.prototype = {
73
87
  }
74
88
  }
75
89
 
76
- return this.createTables();
90
+ return this.createTables(options);
77
91
  },
78
92
 
79
93
  writeMigrationRecord: function (migration, callback) {
@@ -227,6 +241,65 @@ Walker.prototype = {
227
241
  .nodeify(callback);
228
242
  },
229
243
 
244
+ fix: function (options, callback) {
245
+ const partialName = options.destination;
246
+ const count = options.count;
247
+ const sortFn = function (a, b) {
248
+ a = a.name.slice(0, a.name.indexOf('-'));
249
+ b = b.name.slice(0, b.name.indexOf('-'));
250
+
251
+ if (!isNaN(a)) {
252
+ return a - b;
253
+ }
254
+
255
+ return a.localeCompare(b);
256
+ };
257
+
258
+ const files = File.loadFromDatabase(
259
+ this.directory,
260
+ this.prefix,
261
+ this._driver,
262
+ this.internals
263
+ ).then(completedFiles => {
264
+ const toRun = dbmUtil.filterDown(completedFiles, partialName, count).sort(sortFn);
265
+
266
+ if (toRun.length === 0) {
267
+ log.info(this.title + 'Nothing to run');
268
+ }
269
+
270
+ if (this.internals.check) {
271
+ const toRunNames = toRun.map(migration => migration.name);
272
+ log.info(this.title + 'run:', toRunNames);
273
+ return toRunNames;
274
+ }
275
+
276
+ return toRun;
277
+ });
278
+
279
+ if (this.internals.check) {
280
+ return files.nodeify(callback);
281
+ }
282
+
283
+ return files
284
+ .each(file => {
285
+ log.verbose(this.title + 'preparing to run fix:', file.name);
286
+ const _meta = file.get()._meta || {};
287
+ const version = _meta.version || 1;
288
+ if (version < 2) {
289
+ log.warn(`${this.title} skipping "${file.name}" as v1 migrations do not maintain a schema`);
290
+ return Promise.resolve();
291
+ }
292
+
293
+ this.internals.modSchema = { i: {}, c: {}, f: {}, s: [] };
294
+ return require(`./executors/versioned/v${version}`).fix(
295
+ this,
296
+ this.driver,
297
+ file
298
+ );
299
+ })
300
+ .nodeify(callback);
301
+ },
302
+
230
303
  check: function (options, callback) {
231
304
  return Promise.all([
232
305
  File.loadFromDatabase(
@@ -241,7 +314,10 @@ Walker.prototype = {
241
314
  // Requires pr to export filterCompleted from db-migrate-shared
242
315
  const toRun = dbmUtil.filterCompleted(allFiles, completedFiles);
243
316
 
244
- log.info('Files to run:', toRun.map(migration => migration.name));
317
+ log.info(
318
+ 'Files to run:',
319
+ toRun.map(migration => migration.name)
320
+ );
245
321
  return toRun;
246
322
  })
247
323
  .nodeify(callback);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "db-migrate",
3
3
  "description": "Database migration framework for node.js",
4
- "author": "Tobias Gurtick",
4
+ "author": "Tobias Gurtzick",
5
5
  "bin": "./bin/db-migrate",
6
6
  "keywords": [
7
7
  "database",
@@ -31,7 +31,7 @@
31
31
  "programable",
32
32
  "api"
33
33
  ],
34
- "version": "1.0.0-beta.3",
34
+ "version": "1.0.0-beta.30",
35
35
  "engines": {
36
36
  "node": ">=8.0.0"
37
37
  },
@@ -44,38 +44,41 @@
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
- "dotenv": "^5.0.1",
50
+ "dotenv": "^16.3.1",
52
51
  "final-fs": "^1.6.0",
53
52
  "inflection": "^1.10.0",
54
53
  "mkdirp": "~0.5.0",
55
54
  "parse-database-url": "~0.3.0",
56
- "prompt": "^1.0.0",
57
55
  "rc": "^1.2.8",
58
- "resolve": "^1.1.6",
59
- "semver": "^5.3.0",
56
+ "resolve": "^1.19.0",
60
57
  "tunnel-ssh": "^4.0.0",
61
- "yargs": "^15.3.1"
58
+ "yargs": "^17.5.1"
62
59
  },
63
60
  "devDependencies": {
64
- "@hapi/code": "5.x",
65
- "@hapi/lab": "18.x",
61
+ "@babel/eslint-parser": "^7.21.8",
62
+ "@hapi/code": "9.x",
63
+ "@hapi/eslint-plugin": "^6.0.0",
64
+ "@hapi/lab": "25.x",
66
65
  "db-migrate-base": "^2.1.1",
67
- "db-migrate-mysql": "^2.1.1",
68
- "db-migrate-sqlite3": "^0.4.0",
69
- "eslint": "^6.8.0",
66
+ "db-migrate-mysql": "^2.2.0",
67
+ "db-migrate-sqlite3": "^0.5.0",
68
+ "eslint": "^7.32.0",
70
69
  "eslint-config-standard": "^14.1.1",
71
- "eslint-plugin-import": "^2.20.2",
70
+ "eslint-plugin-import": "^2.26.0",
72
71
  "eslint-plugin-node": "^11.1.0",
73
- "eslint-plugin-promise": "^4.2.1",
74
- "eslint-plugin-standard": "^4.0.1",
72
+ "eslint-plugin-promise": "^4.3.1",
73
+ "eslint-plugin-standard": "^4.1.0",
75
74
  "proxyquire": "^1.4.0",
76
75
  "rimraf": "^3.0.2",
77
76
  "sinon": "^9.0.2"
78
77
  },
78
+ "funding": {
79
+ "type": "opencollective",
80
+ "url": "https://opencollective.com/node-db-migrate"
81
+ },
79
82
  "scripts": {
80
83
  "prepublishOnly": "node generateLoader.js",
81
84
  "pretest": "eslint *.js lib/*.js",
package/tttt.js ADDED
@@ -0,0 +1,2 @@
1
+
2
+
package/.eslintignore DELETED
@@ -1 +0,0 @@
1
- test/migrations
package/.eslintrc DELETED
@@ -1,11 +0,0 @@
1
- {
2
- "extends": "standard",
3
- "parserOptions": {
4
- "ecmaVersion": 2019
5
- },
6
- "rules": {
7
- "semi": ["error", "always"],
8
- "no-unused-vars": "warn",
9
- "quotes": ["error", "single", { "avoidEscape": true, "allowTemplateLiterals": true }]
10
- }
11
- }
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/.labrc.js DELETED
@@ -1,10 +0,0 @@
1
- module.exports = {
2
- coverage: true,
3
- threshold: 74,
4
- lint: false,
5
- globals:
6
- 'verbose,dryRun,SharedArrayBuffer,Atomics,BigUint64Array,BigInt64Array,BigInt,URL,URLSearchParams,TextEncoder,TextDecoder,queueMicrotask',
7
- assert: '@hapi/code',
8
- verbose: true,
9
- 'coverage-exclude': ['lib/interface', 'lib/transitions']
10
- };
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