db-migrate 1.0.0-beta.3 → 1.0.0-beta.31
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/LICENSE +26 -0
- package/README.md +1 -5
- package/api.js +26 -8
- package/connect.js +27 -10
- package/lib/chain.js +70 -12
- package/lib/commands/check.js +3 -3
- package/lib/commands/create-migration.js +28 -3
- package/lib/commands/down.js +1 -1
- package/lib/commands/dump.js +22 -0
- package/lib/commands/fix.js +53 -0
- package/lib/commands/generated.js +2 -1
- package/lib/commands/helper/register-events.js +2 -0
- package/lib/commands/run.js +5 -6
- package/lib/commands/set-default-argv.js +7 -2
- package/lib/commands/sync.js +3 -3
- package/lib/commands/up.js +3 -3
- package/lib/driver/index.js +37 -11
- package/lib/executors/versioned/v2.js +50 -6
- package/lib/learn.js +47 -14
- package/lib/methods/v2/statetravel.js +16 -13
- package/lib/methods/v2/translatestate.js +53 -16
- package/lib/state.js +97 -13
- package/lib/template.js +4 -1
- package/lib/templates/v2.js +12 -0
- package/lib/walker.js +83 -7
- package/package.json +20 -17
- package/tttt.js +2 -0
- package/.eslintignore +0 -1
- package/.eslintrc +0 -11
- package/.jscsrc +0 -0
- package/.jshintignore +0 -2
- package/.jshintrc +0 -14
- package/.labrc.js +0 -10
- package/.prettierrc +0 -3
- package/.tern-project +0 -7
- package/.travis.yml +0 -47
- package/CHANGELOG.md +0 -487
- package/CODE_OF_CONDUCT.md +0 -46
- package/CONTRIBUTING.md +0 -81
- package/commitlint.config.js +0 -1
- package/coverage.html +0 -17232
- package/generateLoader.js +0 -36
- package/lib/commands/transition.js +0 -5
- package/lib/transitions/1.js +0 -30
- package/lib/transitions/ask.js +0 -22
- package/lib/transitions/snippets/setup.sjs +0 -8
- package/lib/transitions/transitioner.js +0 -78
- package/lib/transitions/try-require.js +0 -113
- package/lib/transitions/update-version.js +0 -48
package/LICENSE
CHANGED
|
@@ -20,3 +20,29 @@ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
|
20
20
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
21
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
22
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
23
|
+
|
|
24
|
+
AI OSS License
|
|
25
|
+
|
|
26
|
+
Copyright (c) 2015 db-migrate
|
|
27
|
+
|
|
28
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
29
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
30
|
+
in the Software without restriction, including without limitation the rights
|
|
31
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
32
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
33
|
+
furnished to do so, subject to the following conditions:
|
|
34
|
+
|
|
35
|
+
The above copyright notice and this permission notice shall be included in all
|
|
36
|
+
copies or substantial portions of the Software, as well as in results by
|
|
37
|
+
AI models, which result from the source code this License applies to.
|
|
38
|
+
The source code is not allowed to be used for training except for
|
|
39
|
+
models that itself are open source.
|
|
40
|
+
|
|
41
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
42
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
43
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
44
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
45
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
46
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
47
|
+
SOFTWARE.
|
|
48
|
+
|
package/README.md
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
[](#backers) [](#sponsors)
|
|
2
|
-
[](https://david-dm.org/db-migrate/node-db-migrate)
|
|
4
|
-
[](https://david-dm.org/db-migrate/node-db-migrate#info=devDependencies)
|
|
2
|
+
[](https://github.com/db-migrate/node-db-migrate/actions/workflows/ci.yml)
|
|
5
3
|
[](https://readthedocs.org/projects/db-migrate/?badge=latest)
|
|
6
|
-
[](https://lgtm.com/projects/g/db-migrate/node-db-migrate/context:javascript)
|
|
7
|
-
[](https://lgtm.com/projects/g/db-migrate/node-db-migrate/alerts)
|
|
8
4
|
|
|
9
5
|
# db-migrate
|
|
10
6
|
|
package/api.js
CHANGED
|
@@ -50,7 +50,7 @@ function dbmigrate (plugins, isModule, options, callback) {
|
|
|
50
50
|
if (config.dotenvCustomPath) {
|
|
51
51
|
dotenvConfig.path = config.dotenvCustomPath;
|
|
52
52
|
}
|
|
53
|
-
dotenv.
|
|
53
|
+
dotenv.config(dotenvConfig);
|
|
54
54
|
|
|
55
55
|
/* $lab:coverage:off$ */
|
|
56
56
|
if (!options || !options.throwUncatched) load('helper/register-events')();
|
|
@@ -245,6 +245,31 @@ dbmigrate.prototype = {
|
|
|
245
245
|
);
|
|
246
246
|
},
|
|
247
247
|
|
|
248
|
+
fix: function (specification, opts, callback) {
|
|
249
|
+
var executeFix = load('fix');
|
|
250
|
+
|
|
251
|
+
if (arguments.length > 0) {
|
|
252
|
+
if (typeof specification === 'string') {
|
|
253
|
+
this.internals.argv.destination = specification;
|
|
254
|
+
} else if (typeof specification === 'number') {
|
|
255
|
+
this.internals.argv.count = specification;
|
|
256
|
+
} else if (typeof specification === 'function') {
|
|
257
|
+
callback = specification;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
if (typeof opts === 'string') {
|
|
261
|
+
this.internals.migrationMode = opts;
|
|
262
|
+
this.internals.matching = opts;
|
|
263
|
+
} else if (typeof opts === 'function') {
|
|
264
|
+
callback = opts;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
return Promise.resolve(executeFix(this.internals, this.config)).nodeify(
|
|
269
|
+
callback
|
|
270
|
+
);
|
|
271
|
+
},
|
|
272
|
+
|
|
248
273
|
check: function (specification, opts, callback) {
|
|
249
274
|
var executeCheck = load('check');
|
|
250
275
|
|
|
@@ -320,13 +345,6 @@ dbmigrate.prototype = {
|
|
|
320
345
|
return log.silence(isSilent);
|
|
321
346
|
},
|
|
322
347
|
|
|
323
|
-
/**
|
|
324
|
-
* Transition migrations to the latest defined protocol.
|
|
325
|
-
*/
|
|
326
|
-
transition: function () {
|
|
327
|
-
load('transition')(this.internals);
|
|
328
|
-
},
|
|
329
|
-
|
|
330
348
|
/**
|
|
331
349
|
* Creates a correctly formatted migration
|
|
332
350
|
*/
|
package/connect.js
CHANGED
|
@@ -9,7 +9,9 @@ var path = require('path');
|
|
|
9
9
|
var log = require('db-migrate-shared').log;
|
|
10
10
|
const Promise = require('bluebird');
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
Promise.promisifyAll(driver);
|
|
13
|
+
|
|
14
|
+
exports.connect = async function (config, PassedClass) {
|
|
13
15
|
var internals = {};
|
|
14
16
|
var prefix = 'migration';
|
|
15
17
|
if (config.config) {
|
|
@@ -18,6 +20,8 @@ exports.connect = function (config, PassedClass) {
|
|
|
18
20
|
config = config.config;
|
|
19
21
|
}
|
|
20
22
|
|
|
23
|
+
const db2 = await driver.connectAsync(config, internals);
|
|
24
|
+
|
|
21
25
|
return Promise.fromCallback(callback => {
|
|
22
26
|
driver.connect(config, internals, function (err, db) {
|
|
23
27
|
if (err) {
|
|
@@ -25,10 +29,18 @@ exports.connect = function (config, PassedClass) {
|
|
|
25
29
|
return;
|
|
26
30
|
}
|
|
27
31
|
|
|
32
|
+
const realClose = db.close;
|
|
33
|
+
// close both lines with one disconnect action
|
|
34
|
+
db.close = function (cb) {
|
|
35
|
+
db2.close(function () {});
|
|
36
|
+
db.close = realClose;
|
|
37
|
+
db.close(cb);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
var dirPath = path.resolve(
|
|
41
|
+
internals.argv['migrations-dir'] || 'migrations'
|
|
42
|
+
);
|
|
28
43
|
if (internals.migrationMode) {
|
|
29
|
-
var dirPath = path.resolve(
|
|
30
|
-
internals.argv['migrations-dir'] || 'migrations'
|
|
31
|
-
);
|
|
32
44
|
if (internals.migrationMode !== 'all') {
|
|
33
45
|
var switched = false;
|
|
34
46
|
var newConf;
|
|
@@ -56,10 +68,11 @@ exports.connect = function (config, PassedClass) {
|
|
|
56
68
|
null,
|
|
57
69
|
new PassedClass(
|
|
58
70
|
db,
|
|
59
|
-
|
|
71
|
+
dirPath,
|
|
60
72
|
internals.mode !== 'static',
|
|
61
73
|
internals,
|
|
62
|
-
prefix
|
|
74
|
+
prefix,
|
|
75
|
+
{ db2 }
|
|
63
76
|
)
|
|
64
77
|
);
|
|
65
78
|
});
|
|
@@ -69,7 +82,7 @@ exports.connect = function (config, PassedClass) {
|
|
|
69
82
|
null,
|
|
70
83
|
new PassedClass(
|
|
71
84
|
db,
|
|
72
|
-
|
|
85
|
+
dirPath,
|
|
73
86
|
internals.mode !== 'static',
|
|
74
87
|
internals,
|
|
75
88
|
prefix
|
|
@@ -100,6 +113,7 @@ exports.connect = function (config, PassedClass) {
|
|
|
100
113
|
db,
|
|
101
114
|
oldClose,
|
|
102
115
|
prefix,
|
|
116
|
+
db2,
|
|
103
117
|
cb
|
|
104
118
|
);
|
|
105
119
|
};
|
|
@@ -112,10 +126,11 @@ exports.connect = function (config, PassedClass) {
|
|
|
112
126
|
null,
|
|
113
127
|
new PassedClass(
|
|
114
128
|
db,
|
|
115
|
-
|
|
129
|
+
dirPath,
|
|
116
130
|
internals.mode !== 'static',
|
|
117
131
|
internals,
|
|
118
|
-
prefix
|
|
132
|
+
prefix,
|
|
133
|
+
{ db2 }
|
|
119
134
|
)
|
|
120
135
|
);
|
|
121
136
|
}
|
|
@@ -142,6 +157,7 @@ function migrationFiles (
|
|
|
142
157
|
db,
|
|
143
158
|
close,
|
|
144
159
|
prefix,
|
|
160
|
+
db2,
|
|
145
161
|
cb
|
|
146
162
|
) {
|
|
147
163
|
var file;
|
|
@@ -187,7 +203,8 @@ function migrationFiles (
|
|
|
187
203
|
internals.argv['migrations-dir'],
|
|
188
204
|
internals.mode !== 'static',
|
|
189
205
|
internals,
|
|
190
|
-
prefix
|
|
206
|
+
prefix,
|
|
207
|
+
{ db2 }
|
|
191
208
|
)
|
|
192
209
|
);
|
|
193
210
|
|
package/lib/chain.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
const Promise = require('bluebird');
|
|
2
1
|
const DEFAULT = [
|
|
3
2
|
'renameCollection',
|
|
4
3
|
'dropCollection',
|
|
@@ -16,12 +15,66 @@ const DEFAULT = [
|
|
|
16
15
|
'removeForeignKey'
|
|
17
16
|
];
|
|
18
17
|
|
|
18
|
+
let rollbackCounter = 0;
|
|
19
|
+
let rollbackSignal = null;
|
|
20
|
+
let signal = null;
|
|
21
|
+
let counter = 0;
|
|
22
|
+
|
|
23
|
+
const dbmControl = {
|
|
24
|
+
inc: () => {
|
|
25
|
+
++counter;
|
|
26
|
+
},
|
|
27
|
+
|
|
28
|
+
signal: () => {
|
|
29
|
+
signal = true;
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
hasSignaled: () => {
|
|
33
|
+
return signal;
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
previousSignal: () => {
|
|
37
|
+
const r = rollbackSignal;
|
|
38
|
+
// we reset on retrieval and mark as retrieved
|
|
39
|
+
rollbackSignal = rollbackSignal === null ? null : false;
|
|
40
|
+
return r;
|
|
41
|
+
},
|
|
42
|
+
|
|
43
|
+
get: () => {
|
|
44
|
+
return counter;
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
getPrevious: () => {
|
|
48
|
+
const r = rollbackCounter;
|
|
49
|
+
|
|
50
|
+
// we reset on retrieval and mark as retrieved
|
|
51
|
+
rollbackCounter = rollbackCounter > 0 ? false : 0;
|
|
52
|
+
|
|
53
|
+
return r;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
19
57
|
class Chain {
|
|
20
|
-
constructor (context, file, driver, internals) {
|
|
58
|
+
constructor (context, file, driver, internals, pdriver) {
|
|
21
59
|
this.file = file;
|
|
22
60
|
this.context = context;
|
|
23
61
|
this.driver = context;
|
|
62
|
+
this.pdriver = pdriver;
|
|
24
63
|
this.udriver = driver;
|
|
64
|
+
if (this.udriver._dbmControl !== true) {
|
|
65
|
+
this.udriver._counter = dbmControl;
|
|
66
|
+
this.udriver._dbmControl = true;
|
|
67
|
+
const runSql = this.udriver.runSql;
|
|
68
|
+
this.udriver._dbmControlRSQL = runSql;
|
|
69
|
+
|
|
70
|
+
// couple runSql
|
|
71
|
+
this.udriver.runSql = function (...args) {
|
|
72
|
+
return runSql.apply(this, args).then(x => {
|
|
73
|
+
++counter;
|
|
74
|
+
return x;
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
}
|
|
25
78
|
this.internals = internals;
|
|
26
79
|
this.chains = [];
|
|
27
80
|
this.interfaces = [];
|
|
@@ -32,20 +85,23 @@ class Chain {
|
|
|
32
85
|
DEFAULT.concat(Object.keys(this.context.learnable || [])).forEach(
|
|
33
86
|
method => {
|
|
34
87
|
this[method] = function (...args) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
return Promise.resolve(
|
|
42
|
-
this.exec.apply(this, [method].concat(args))
|
|
43
|
-
).asCallback(cb);
|
|
88
|
+
// we don't handle any callbacks here, v2 ultimately deprecates them
|
|
89
|
+
|
|
90
|
+
this.transferInt();
|
|
91
|
+
|
|
92
|
+
return this.exec.apply(this, [method].concat(args));
|
|
44
93
|
};
|
|
45
94
|
}
|
|
46
95
|
);
|
|
47
96
|
}
|
|
48
97
|
|
|
98
|
+
transferInt () {
|
|
99
|
+
rollbackCounter = counter;
|
|
100
|
+
counter = 0;
|
|
101
|
+
rollbackSignal = signal;
|
|
102
|
+
signal = null;
|
|
103
|
+
}
|
|
104
|
+
|
|
49
105
|
addChain (chain) {
|
|
50
106
|
this.chains.push(chain);
|
|
51
107
|
}
|
|
@@ -58,7 +114,8 @@ class Chain {
|
|
|
58
114
|
this.context,
|
|
59
115
|
this.file,
|
|
60
116
|
this.udriver,
|
|
61
|
-
this.internals
|
|
117
|
+
this.internals,
|
|
118
|
+
this.pdriver
|
|
62
119
|
);
|
|
63
120
|
}
|
|
64
121
|
|
|
@@ -81,6 +138,7 @@ class Chain {
|
|
|
81
138
|
this._step.useState(ret);
|
|
82
139
|
}
|
|
83
140
|
|
|
141
|
+
// need to check if we still want this
|
|
84
142
|
if (this._step.hasModification) {
|
|
85
143
|
const ret = this._step.modify(
|
|
86
144
|
this.context,
|
package/lib/commands/check.js
CHANGED
|
@@ -21,15 +21,15 @@ async function prepare (internals, config) {
|
|
|
21
21
|
);
|
|
22
22
|
|
|
23
23
|
if (internals.locTitle) {
|
|
24
|
-
migrator.
|
|
24
|
+
migrator.directory = path.resolve(
|
|
25
25
|
internals.argv['migrations-dir'],
|
|
26
26
|
internals.locTitle
|
|
27
27
|
);
|
|
28
28
|
} else {
|
|
29
|
-
migrator.
|
|
29
|
+
migrator.directory = path.resolve(internals.argv['migrations-dir']);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
internals.migrationsDir = migrator.
|
|
32
|
+
internals.migrationsDir = migrator.directory;
|
|
33
33
|
|
|
34
34
|
await migrator.createMigrationsTable();
|
|
35
35
|
log.verbose('migration table created');
|
|
@@ -5,18 +5,38 @@ const log = require('db-migrate-shared').log;
|
|
|
5
5
|
const mkdirp = Promise.promisify(require('mkdirp'));
|
|
6
6
|
const fs = require('fs');
|
|
7
7
|
const stat = Promise.promisify(fs.stat);
|
|
8
|
+
const writeFile = Promise.promisify(fs.writeFile);
|
|
8
9
|
const yargs = require('yargs');
|
|
9
10
|
const util = require('util');
|
|
11
|
+
const path = require('path');
|
|
10
12
|
|
|
11
13
|
async function createMigrationDir (dir) {
|
|
12
14
|
const res = await stat(dir).catch(_ => {
|
|
13
15
|
return { err: true };
|
|
14
16
|
});
|
|
15
17
|
if (res && res.err === true) {
|
|
16
|
-
|
|
18
|
+
await mkdirp(dir);
|
|
17
19
|
}
|
|
18
20
|
|
|
19
|
-
|
|
21
|
+
// Create migrations/package.json to ensure migration files are
|
|
22
|
+
// executed as CJS and not ESM
|
|
23
|
+
// https://github.com/db-migrate/node-db-migrate/issues/721
|
|
24
|
+
const packageJsonPath = path.resolve(dir, 'package.json');
|
|
25
|
+
|
|
26
|
+
await stat(packageJsonPath).then(
|
|
27
|
+
async () => {
|
|
28
|
+
const packageJson = require(packageJsonPath);
|
|
29
|
+
packageJson.type = 'commonjs';
|
|
30
|
+
const packageJsonStr = JSON.stringify(packageJson, null, 2);
|
|
31
|
+
await writeFile(packageJsonPath, packageJsonStr, 'utf-8');
|
|
32
|
+
},
|
|
33
|
+
async (err) => {
|
|
34
|
+
const packageJson = JSON.stringify({
|
|
35
|
+
type: 'commonjs'
|
|
36
|
+
}, null, 2)
|
|
37
|
+
await writeFile(packageJsonPath, packageJson, 'utf-8');
|
|
38
|
+
}
|
|
39
|
+
)
|
|
20
40
|
}
|
|
21
41
|
|
|
22
42
|
async function executeCreateMigration (internals, config) {
|
|
@@ -82,8 +102,9 @@ async function executeCreateMigration (internals, config) {
|
|
|
82
102
|
templateType = Migration.TemplateType.SQL_FILE_LOADER;
|
|
83
103
|
} else if (shouldCreateCoffeeFile(internals, config)) {
|
|
84
104
|
templateType = Migration.TemplateType.DEFAULT_COFFEE;
|
|
105
|
+
} else if (shouldCreateV2File(internals, config)) {
|
|
106
|
+
templateType = Migration.TemplateType.V2_DEFAULT;
|
|
85
107
|
}
|
|
86
|
-
|
|
87
108
|
if (plugins) {
|
|
88
109
|
hooks = plugins.hook('create:template') || [];
|
|
89
110
|
}
|
|
@@ -173,6 +194,10 @@ function shouldCreateCoffeeFile (internals, config) {
|
|
|
173
194
|
return internals.argv['coffee-file'] || config['coffee-file'];
|
|
174
195
|
}
|
|
175
196
|
|
|
197
|
+
function shouldCreateV2File (internals, config) {
|
|
198
|
+
return internals.argv['v2-file'] || config['v2-file'];
|
|
199
|
+
}
|
|
200
|
+
|
|
176
201
|
async function createSqlFiles (internals, config) {
|
|
177
202
|
let migrationsDir = internals.argv['migrations-dir'];
|
|
178
203
|
|
package/lib/commands/down.js
CHANGED
|
@@ -22,7 +22,7 @@ async function prepare (internals, config) {
|
|
|
22
22
|
Migrator
|
|
23
23
|
);
|
|
24
24
|
|
|
25
|
-
migrator.
|
|
25
|
+
migrator.directory = path.resolve(internals.argv['migrations-dir']);
|
|
26
26
|
|
|
27
27
|
await migrator.createMigrationsTable();
|
|
28
28
|
log.verbose('migration table created');
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const log = require('db-migrate-shared').log;
|
|
3
|
+
|
|
4
|
+
async function prepare (internals, config) {
|
|
5
|
+
const index = require('../../connect');
|
|
6
|
+
|
|
7
|
+
return index.driver({
|
|
8
|
+
config: config.getCurrent().settings,
|
|
9
|
+
internals: internals
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
module.exports = async function (internals, config) {
|
|
14
|
+
const driver = await prepare(internals, config);
|
|
15
|
+
|
|
16
|
+
try {
|
|
17
|
+
const res = await driver.backupGet(internals.argv);
|
|
18
|
+
return internals.onComplete(driver, internals, null, res);
|
|
19
|
+
} catch (err) {
|
|
20
|
+
return internals.onComplete(driver, internals, err);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
var path = require('path');
|
|
2
|
+
var log = require('db-migrate-shared').log;
|
|
3
|
+
var migrationHook = require('./helper/migration-hook.js');
|
|
4
|
+
|
|
5
|
+
async function prepare (internals, config) {
|
|
6
|
+
try {
|
|
7
|
+
await migrationHook(internals);
|
|
8
|
+
var Migrator = require('../walker.js');
|
|
9
|
+
var index = require('../../connect');
|
|
10
|
+
|
|
11
|
+
if (!internals.argv.count) {
|
|
12
|
+
internals.argv.count = Number.MAX_VALUE;
|
|
13
|
+
}
|
|
14
|
+
const migrator = await index.connect(
|
|
15
|
+
{
|
|
16
|
+
config: config.getCurrent().settings,
|
|
17
|
+
internals: internals,
|
|
18
|
+
prefix: 'migration'
|
|
19
|
+
},
|
|
20
|
+
Migrator
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
if (internals.locTitle) {
|
|
24
|
+
migrator.directory = path.resolve(
|
|
25
|
+
internals.argv['migrations-dir'],
|
|
26
|
+
internals.locTitle
|
|
27
|
+
);
|
|
28
|
+
} else {
|
|
29
|
+
migrator.directory = path.resolve(internals.argv['migrations-dir']);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
internals.migrationsDir = migrator.directory;
|
|
33
|
+
const backupState = internals.argv['backup-state'];
|
|
34
|
+
|
|
35
|
+
await migrator.createMigrationsTable({ emptyState: true, backupState });
|
|
36
|
+
log.verbose('migration table created');
|
|
37
|
+
|
|
38
|
+
return migrator;
|
|
39
|
+
} catch (err) {
|
|
40
|
+
throw err;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
module.exports = async function (internals, config) {
|
|
45
|
+
const migrator = await prepare(internals, config);
|
|
46
|
+
|
|
47
|
+
try {
|
|
48
|
+
const res = await migrator.fix(internals.argv);
|
|
49
|
+
return internals.onComplete(migrator, internals, null, res);
|
|
50
|
+
} catch (err) {
|
|
51
|
+
return internals.onComplete(migrator, internals, err);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
@@ -8,6 +8,8 @@ const files = {
|
|
|
8
8
|
"create-migration": require('./create-migration.js'),
|
|
9
9
|
"db": require('./db.js'),
|
|
10
10
|
"down": require('./down.js'),
|
|
11
|
+
"dump": require('./dump.js'),
|
|
12
|
+
"fix": require('./fix.js'),
|
|
11
13
|
"fn/plugin": require('./fn/plugin.js'),
|
|
12
14
|
"generated": require('./generated.js'),
|
|
13
15
|
"helper/assert": require('./helper/assert.js'),
|
|
@@ -20,7 +22,6 @@ const files = {
|
|
|
20
22
|
"seed": require('./seed.js'),
|
|
21
23
|
"set-default-argv": require('./set-default-argv.js'),
|
|
22
24
|
"sync": require('./sync.js'),
|
|
23
|
-
"transition": require('./transition.js'),
|
|
24
25
|
"undo-seed": require('./undo-seed.js'),
|
|
25
26
|
"up": require('./up.js')
|
|
26
27
|
}
|
|
@@ -4,11 +4,13 @@ var log = require('db-migrate-shared').log;
|
|
|
4
4
|
|
|
5
5
|
function registerEvents () {
|
|
6
6
|
process.on('uncaughtException', function (err) {
|
|
7
|
+
log.error('uncaughtException');
|
|
7
8
|
log.error(err.stack || err);
|
|
8
9
|
process.exit(1);
|
|
9
10
|
});
|
|
10
11
|
|
|
11
12
|
process.on('unhandledRejection', function (reason) {
|
|
13
|
+
log.error('unhandledRejection');
|
|
12
14
|
log.error(reason.stack || reason);
|
|
13
15
|
process.exit(1);
|
|
14
16
|
});
|
package/lib/commands/run.js
CHANGED
|
@@ -5,16 +5,12 @@ var yargs = require('yargs');
|
|
|
5
5
|
|
|
6
6
|
function run (internals, config) {
|
|
7
7
|
const { load } = internals;
|
|
8
|
-
const transition = load('transition');
|
|
9
8
|
var action = internals.argv._.shift();
|
|
10
9
|
var folder = action.split(':');
|
|
11
10
|
|
|
12
11
|
action = folder[0];
|
|
13
12
|
|
|
14
13
|
switch (action) {
|
|
15
|
-
case 'transition':
|
|
16
|
-
transition(internals);
|
|
17
|
-
break;
|
|
18
14
|
case 'create':
|
|
19
15
|
if (folder[1]) {
|
|
20
16
|
internals.matching = folder[1];
|
|
@@ -40,6 +36,7 @@ function run (internals, config) {
|
|
|
40
36
|
|
|
41
37
|
executeSync(internals, config);
|
|
42
38
|
break;
|
|
39
|
+
case 'fix':
|
|
43
40
|
case 'up':
|
|
44
41
|
case 'down':
|
|
45
42
|
case 'reset':
|
|
@@ -62,6 +59,9 @@ function run (internals, config) {
|
|
|
62
59
|
if (action === 'up') {
|
|
63
60
|
var executeUp = load('up');
|
|
64
61
|
executeUp(internals, config);
|
|
62
|
+
} else if (action === 'fix') {
|
|
63
|
+
var executeFix = load('fix');
|
|
64
|
+
executeFix(internals, config);
|
|
65
65
|
} else {
|
|
66
66
|
var executeDown = load('down');
|
|
67
67
|
executeDown(internals, config);
|
|
@@ -114,8 +114,7 @@ function run (internals, config) {
|
|
|
114
114
|
);
|
|
115
115
|
} else {
|
|
116
116
|
log.error(
|
|
117
|
-
'Invalid Action: Must be [up|down|check|create|reset|sync|'
|
|
118
|
-
'db|transition].'
|
|
117
|
+
'Invalid Action: Must be [up|down|check|create|reset|sync|db].'
|
|
119
118
|
);
|
|
120
119
|
yargs.showHelp();
|
|
121
120
|
process.exit(1);
|
|
@@ -16,14 +16,15 @@ module.exports = function (internals, isModule) {
|
|
|
16
16
|
'migrations-dir': internals.cwd + '/migrations',
|
|
17
17
|
'vcseeder-dir': internals.cwd + '/VCSeeder',
|
|
18
18
|
'staticseeder-dir': internals.cwd + '/Seeder',
|
|
19
|
-
'ignore-completed-migrations': false
|
|
19
|
+
'ignore-completed-migrations': false,
|
|
20
|
+
'backup-state': false
|
|
20
21
|
};
|
|
21
22
|
|
|
22
23
|
if (!isModule) {
|
|
23
24
|
internals.argv = yargs
|
|
24
25
|
.default(defaultConfig)
|
|
25
26
|
.usage(
|
|
26
|
-
'Usage: db-migrate [up|down|check|reset|sync|create|db
|
|
27
|
+
'Usage: db-migrate [up|down|check|reset|sync|create|db] ' +
|
|
27
28
|
'[[dbname/]migrationName|all] [options]'
|
|
28
29
|
)
|
|
29
30
|
.describe(
|
|
@@ -64,6 +65,8 @@ module.exports = function (internals, isModule) {
|
|
|
64
65
|
.boolean('version')
|
|
65
66
|
.describe('config', 'Location of the database.json file.')
|
|
66
67
|
.string('config')
|
|
68
|
+
.describe('v2-file', 'Create v2 schema migration')
|
|
69
|
+
.boolean('v2-file')
|
|
67
70
|
.describe(
|
|
68
71
|
'sql-file',
|
|
69
72
|
'Automatically create two sql files for up and down statements in ' +
|
|
@@ -111,6 +114,8 @@ module.exports = function (internals, isModule) {
|
|
|
111
114
|
.boolean('ignore-completed-migrations')
|
|
112
115
|
.describe('log-level', 'Set the log-level, for example sql|warn')
|
|
113
116
|
.string('log-level')
|
|
117
|
+
.describe('backup-state', 'For use with fix, to take a backup of the current state before continuing.')
|
|
118
|
+
.boolean('backup-state')
|
|
114
119
|
.parse();
|
|
115
120
|
} else {
|
|
116
121
|
internals.argv = Object.assign(defaultConfig, internals.cmdOptions);
|
package/lib/commands/sync.js
CHANGED
|
@@ -21,15 +21,15 @@ async function prepare (internals, config) {
|
|
|
21
21
|
);
|
|
22
22
|
|
|
23
23
|
if (internals.locTitle) {
|
|
24
|
-
migrator.
|
|
24
|
+
migrator.directory = path.resolve(
|
|
25
25
|
internals.argv['migrations-dir'],
|
|
26
26
|
internals.locTitle
|
|
27
27
|
);
|
|
28
28
|
} else {
|
|
29
|
-
migrator.
|
|
29
|
+
migrator.directory = path.resolve(internals.argv['migrations-dir']);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
internals.migrationsDir = migrator.
|
|
32
|
+
internals.migrationsDir = migrator.directory;
|
|
33
33
|
|
|
34
34
|
await migrator.createMigrationsTable();
|
|
35
35
|
log.verbose('migration table created');
|
package/lib/commands/up.js
CHANGED
|
@@ -21,15 +21,15 @@ async function prepare (internals, config) {
|
|
|
21
21
|
);
|
|
22
22
|
|
|
23
23
|
if (internals.locTitle) {
|
|
24
|
-
migrator.
|
|
24
|
+
migrator.directory = path.resolve(
|
|
25
25
|
internals.argv['migrations-dir'],
|
|
26
26
|
internals.locTitle
|
|
27
27
|
);
|
|
28
28
|
} else {
|
|
29
|
-
migrator.
|
|
29
|
+
migrator.directory = path.resolve(internals.argv['migrations-dir']);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
internals.migrationsDir = migrator.
|
|
32
|
+
internals.migrationsDir = migrator.directory;
|
|
33
33
|
|
|
34
34
|
await migrator.createMigrationsTable();
|
|
35
35
|
log.verbose('migration table created');
|