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/generateLoader.js DELETED
@@ -1,36 +0,0 @@
1
- 'use strict';
2
-
3
- const path = require('path');
4
- const recursive = require('final-fs').readdirRecursive;
5
- const start = path.join(__dirname, 'lib/commands');
6
- const fs = require('fs');
7
-
8
- (async () => {
9
- const files = await recursive(start, true);
10
- const template = `
11
- 'use strict';
12
-
13
- const path = require('path');
14
-
15
- const files = {
16
- ${files
17
- .map(x => ` "${x.substring(0, x.indexOf('.js'))}": require('./${x}')`)
18
- .join(',\n')}
19
- }
20
-
21
- function register (module) {
22
- return files[module];
23
- }
24
-
25
- module.exports = register;
26
- `;
27
-
28
- fs.writeFile(
29
- path.join(__dirname, 'lib/commands/generated.js'),
30
- template,
31
- 'utf8',
32
- err => {
33
- if (err) throw err;
34
- }
35
- );
36
- })();
@@ -1,5 +0,0 @@
1
- 'use strict';
2
-
3
- module.exports = function (internals) {
4
- require('../transitions/transitioner.js')(internals);
5
- };
@@ -1,30 +0,0 @@
1
- /**
2
- * Our first transition is actually the removal of globals and
3
- * introducing the setup routine.
4
- * Thus the body of this transition is just an empty function, but displays
5
- * as all transitions an explanation to the user.
6
- */
7
- module.exports = {
8
- transition: function () {},
9
-
10
- message: function () {
11
- console.log(
12
- 'Congratulations!\n\n' +
13
- 'You just migrated from protocol 0 to 1!\n' +
14
- 'What does that mean for you?\n' +
15
- 'Quite simple, from 0 to 1 we introduced the setup function and we ' +
16
- 'deprecated some globals, like async or dbm. What this transition does is' +
17
- ' grabbing your migrations, replacing the async and dbm definitions and ' +
18
- 'inserting the setup body if not present.\n' +
19
- 'It might be possible, that you still run into errors, for example if ' +
20
- 'you already have had a setup body, it wont be replaced and you might ' +
21
- 'be missing the default routine of the setup, which provides for example ' +
22
- 'the dataTypes to your migration.\n\n' +
23
- 'What do I need to do now?\n' +
24
- 'Try to rexecute all of your migrations and watch if you run into any ' +
25
- 'Errors, if you encounter any, you need to manually fix those ' +
26
- "problems. But don't worry, this protocol transitions happen very " +
27
- 'rarely!\n'
28
- );
29
- }
30
- };
@@ -1,22 +0,0 @@
1
- var prompt = require('prompt');
2
-
3
- function ask (schema, callback) {
4
- console.log('Starting transition helper...\n');
5
-
6
- prompt.start();
7
-
8
- prompt.get(schema, function (err, result) {
9
- if (err) {
10
- return callback(err);
11
- }
12
-
13
- if (result.safe === 'n') {
14
- console.log('Aborted transition helper!');
15
- callback(new Error('Aborted transition.'));
16
- } else {
17
- callback(null, result);
18
- }
19
- });
20
- }
21
-
22
- module.exports = ask;
@@ -1,8 +0,0 @@
1
- /**
2
- * We receive the dbmigrate dependency from dbmigrate initially.
3
- * This enables us to not have to rely on NODE_PATH.
4
- */
5
- exports.setup = function(options, seedLink) {
6
- dbm = options.dbmigrate;
7
- type = dbm.dataType;
8
- };
@@ -1,78 +0,0 @@
1
- var Migration = require('../file.js');
2
- var tryRequire = require('./try-require.js');
3
- var updateVersion = require('./update-version.js');
4
- var ask = require('./ask.js');
5
- var log = require('db-migrate-shared').log;
6
-
7
- module.exports = function (internals) {
8
- ask(
9
- {
10
- properties: {
11
- safe: {
12
- description:
13
- 'This process is going to alter your migrations. We ' +
14
- 'highly recommend you to backup your migrations or even better safe ' +
15
- "the current state with git versioning.\nPlease make sure you don't " +
16
- 'blow up yourself.\n\nDo you want to continue? [y/n]',
17
- message: 'Invalid answer! Do you want to continue? [y/n]',
18
- type: 'string',
19
- default: 'n',
20
- conform: function (value) {
21
- return value === 'y' || value === 'n';
22
- }
23
- }
24
- }
25
- },
26
- function (err) {
27
- if (err) {
28
- return;
29
- }
30
-
31
- internals.parser = {
32
- filesRegEx: /\.js$/
33
- };
34
-
35
- Migration.loadFromFilesystem('migrations/', internals, function (
36
- err,
37
- migrations
38
- ) {
39
- var messages = [];
40
- if (err) {
41
- return;
42
- }
43
-
44
- migrations.forEach(function (migration) {
45
- var required = tryRequire(migration, internals);
46
- var version =
47
- required._meta && required._meta.version
48
- ? required._meta.version
49
- : 0;
50
-
51
- if (version !== internals.migrationProtocol) {
52
- var i;
53
-
54
- for (i = 0; i < internals.migrationProtocol; ++i) {
55
- var transition = require('./' + (i + 1));
56
- transition.transition();
57
- messages[i + 1] = transition.message;
58
-
59
- updateVersion(required, migration, internals, i + 1);
60
- log.info('Transitioned ' + migration.name + '.');
61
- }
62
- } else {
63
- log.verbose(
64
- migration.name,
65
- 'was already transitioned to version ' +
66
- internals.migrationProtocol +
67
- '.'
68
- );
69
- }
70
- });
71
-
72
- messages.forEach(function (message) {
73
- message();
74
- });
75
- });
76
- }
77
- );
78
- };
@@ -1,113 +0,0 @@
1
- var log = require('db-migrate-shared').log;
2
- var path = require('path');
3
- var fs = require('fs');
4
- var cp = require('child_process');
5
-
6
- var handled = false;
7
- var installed = false;
8
- var removedGlobals = {
9
- 'dbm is not defined': globalHandler,
10
- 'async is not defined': globalHandler,
11
- "Cannot find module 'db-migrate'": missingDBMigrate,
12
- "Cannot find module 'async'": installAsync
13
- };
14
-
15
- function missingDBMigrate (migration, retry) {
16
- return globalHandler(migration.path, retry);
17
- }
18
-
19
- function installAsync (migration, retry) {
20
- var cmd = ['install', '--save', 'async'];
21
-
22
- if (installed) {
23
- retry();
24
- } else {
25
- installed = true;
26
- }
27
-
28
- log.info('Installing async...');
29
- cp.spawnSync('npm', cmd, {
30
- cwd: migration.internals.cwd,
31
- stdio: 'inherit'
32
- });
33
-
34
- return retry();
35
- }
36
-
37
- function globalHandler (migration, retry) {
38
- var data = fs.readFileSync(migration, 'utf8');
39
- data = data.replace(
40
- /^dbm = dbm \|\| require\((?!\s)?'db-migrate'(?!\s)?\)/m,
41
- 'var dbm'
42
- );
43
-
44
- data = data.replace(
45
- /^var dbm = global\.dbm \|\| require\((?!\s)?'db-migrate'(?!\s)?\)/m,
46
- 'var dbm'
47
- );
48
-
49
- if (data.indexOf('async = async || require') !== -1) {
50
- handled = true;
51
- data = data.replace(
52
- /^async = async \|\| require\((?!\s)?'async'(?!\s)?\)/m,
53
- "var async = require( 'async' )"
54
- );
55
- }
56
- data = data.replace(/^var type = dbm.dataType/m, 'var type');
57
-
58
- if (data.indexOf('exports.setup = ') === -1) {
59
- var snippet = fs.readFileSync(
60
- path.join(__dirname, '/snippets/setup.sjs'),
61
- 'utf8'
62
- );
63
- data = data.replace(/exports.up/, snippet + '\nexports.up');
64
- }
65
-
66
- fs.writeFileSync(migration, data, 'utf8');
67
-
68
- return retry();
69
- }
70
-
71
- function tryRequire (migration) {
72
- try {
73
- if (handled && !installed) {
74
- return installAsync(migration, tryRequire.bind(this, migration));
75
- }
76
-
77
- return require(migration.internals.cwd + '/' + migration.path);
78
- } catch (ex) {
79
- if (ex instanceof ReferenceError) {
80
- if (removedGlobals[ex.message]) {
81
- log.info(ex.message, 'Initiating removal of old globals...');
82
- return removedGlobals[ex.message](
83
- migration.path,
84
- tryRequire.bind(this, migration)
85
- );
86
- } else {
87
- log.error(
88
- ex.stack,
89
- 'Unknown failure, please check your file',
90
- migration
91
- );
92
-
93
- throw new Error(
94
- 'Unhandled ReferenceError while transition. Please ' +
95
- 'fix the issues and rerun the transitioner again.'
96
- );
97
- }
98
- } else if (removedGlobals[ex.message]) {
99
- return removedGlobals[ex.message](
100
- migration,
101
- tryRequire.bind(this, migration)
102
- );
103
- } else {
104
- log.error(ex.stack, migration);
105
- throw new Error(
106
- 'Unhandled Error while transition. Please ' +
107
- 'fix the issues and rerun the transitioner again.'
108
- );
109
- }
110
- }
111
- }
112
-
113
- module.exports = tryRequire;
@@ -1,48 +0,0 @@
1
- var balanced = require('balanced-match');
2
- var fs = require('fs');
3
-
4
- function updateVersion (required, migration, internals, version) {
5
- var data = fs.readFileSync(migration.path, 'utf8');
6
- var searchString = 'exports.down';
7
- var balance;
8
- var metaIndex;
9
- var plus = 1;
10
- var sub;
11
-
12
- if (required._meta) {
13
- searchString = 'exports._meta';
14
- }
15
-
16
- metaIndex = data.indexOf(searchString);
17
- sub = data.substring(metaIndex);
18
- balance = balanced('{', '}', sub);
19
-
20
- if (sub[balance.end + 1] === ';') {
21
- ++plus;
22
- }
23
-
24
- sub = sub.substring(0, balanced.end);
25
-
26
- if (required._meta) {
27
- required._meta.version = version;
28
-
29
- data =
30
- data.substring(0, metaIndex) +
31
- sub.replace(
32
- sub.substring(balance.start, balance.end + 1),
33
- JSON.stringify(required._meta, null, 2)
34
- ) +
35
- data.substring(metaIndex + balance.end + plus);
36
- } else {
37
- data =
38
- data.substring(0, metaIndex + balance.end + plus) +
39
- '\n\nexports._meta = ' +
40
- JSON.stringify({ version: version }, null, 2) +
41
- ';' +
42
- data.substring(metaIndex + balance.end + plus);
43
- }
44
-
45
- fs.writeFileSync(migration.path, data, 'utf8');
46
- }
47
-
48
- module.exports = updateVersion;