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
@@ -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;