db-migrate 1.2.0 → 1.3.0
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/README.md +9 -8
- package/api.js +18 -46
- package/lib/commands/generated.js +1 -0
- package/lib/commands/helper/seeder.js +29 -0
- package/lib/commands/run.js +11 -13
- package/lib/commands/seed.js +5 -9
- package/lib/commands/set-default-argv.js +4 -1
- package/lib/commands/undo-seed.js +5 -9
- package/lib/dml.js +758 -0
- package/lib/executors/versioned/v2.js +18 -78
- package/lib/recovery.js +83 -0
- package/lib/seed.js +199 -0
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -10,6 +10,15 @@
|
|
|
10
10
|
|
|
11
11
|
Database migration framework for node.js
|
|
12
12
|
|
|
13
|
+
> **New: [db-migrate for meta](https://github.com/db-migrate/meta-db-migrate)**
|
|
14
|
+
>
|
|
15
|
+
> db-migrate rewritten in meta: your program ships with its migrations
|
|
16
|
+
> compiled in, as one binary, no node.js needed to migrate. It uses the same
|
|
17
|
+
> migrations table and the same state as db-migrate, v2 migrations included,
|
|
18
|
+
> so a database migrated by one of them can be carried on by the other.
|
|
19
|
+
>
|
|
20
|
+
> [Try meta-db-migrate](https://github.com/db-migrate/meta-db-migrate)
|
|
21
|
+
|
|
13
22
|
# Platinum sponsors
|
|
14
23
|
|
|
15
24
|
[<img src="https://www.wizardtales.com/wzrdtales.png" width="100">](https://www.wizardtales.com)
|
|
@@ -67,14 +76,6 @@ db-migrate to use the `tunnel` setting of your database config:
|
|
|
67
76
|
|
|
68
77
|
$ npm install db-migrate-plugin-tunnel-ssh
|
|
69
78
|
|
|
70
|
-
## db-migrate for meta
|
|
71
|
-
|
|
72
|
-
[meta-db-migrate](https://github.com/db-migrate/meta-db-migrate) is db-migrate
|
|
73
|
-
rewritten in meta: a program ships with its migrations compiled in, as one
|
|
74
|
-
binary. It uses the same migrations table and the same state as db-migrate,
|
|
75
|
-
v2 migrations included, so a database migrated by one of them can be carried
|
|
76
|
-
on by the other.
|
|
77
|
-
|
|
78
79
|
## Resources and usage instructions
|
|
79
80
|
|
|
80
81
|
Please follow the link below, for usage instructions examples and the full
|
package/api.js
CHANGED
|
@@ -422,69 +422,41 @@ dbmigrate.prototype = {
|
|
|
422
422
|
},
|
|
423
423
|
|
|
424
424
|
/**
|
|
425
|
-
*
|
|
426
|
-
* the
|
|
425
|
+
* Inserts the rows of the static seeds in seeds-dir, all or the one named,
|
|
426
|
+
* removing the rows of their earlier runs first.
|
|
427
427
|
*/
|
|
428
|
-
seed: function (
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
this.internals.matching = scope;
|
|
428
|
+
seed: function (name, callback) {
|
|
429
|
+
if (typeof name === 'function') {
|
|
430
|
+
callback = name;
|
|
431
|
+
name = undefined;
|
|
433
432
|
}
|
|
434
433
|
|
|
435
|
-
this.internals.
|
|
436
|
-
return Promise.resolve(
|
|
434
|
+
this.internals.seedName = name;
|
|
435
|
+
return Promise.resolve(load('seed')(this.internals, this.config)).asCallback(
|
|
437
436
|
callback
|
|
438
437
|
);
|
|
439
438
|
},
|
|
440
439
|
|
|
441
440
|
/**
|
|
442
|
-
*
|
|
441
|
+
* Removes the rows inserted by the static seeds, all or the one named.
|
|
443
442
|
*/
|
|
444
|
-
undoSeed: function (
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
this.internals.argv.count = specification;
|
|
449
|
-
|
|
450
|
-
if (scope) {
|
|
451
|
-
this.internals.migrationMode = scope;
|
|
452
|
-
this.internals.matching = scope;
|
|
453
|
-
}
|
|
454
|
-
} else if (typeof specification === 'string') {
|
|
455
|
-
this.internals.migrationMode = scope;
|
|
456
|
-
this.internals.matching = scope;
|
|
457
|
-
}
|
|
443
|
+
undoSeed: function (name, callback) {
|
|
444
|
+
if (typeof name === 'function') {
|
|
445
|
+
callback = name;
|
|
446
|
+
name = undefined;
|
|
458
447
|
}
|
|
459
448
|
|
|
449
|
+
this.internals.seedName = name;
|
|
460
450
|
return Promise.resolve(
|
|
461
|
-
|
|
451
|
+
load('undo-seed')(this.internals, this.config)
|
|
462
452
|
).asCallback(callback);
|
|
463
453
|
},
|
|
464
454
|
|
|
465
455
|
/**
|
|
466
|
-
*
|
|
456
|
+
* Removes the rows inserted by all static seeds.
|
|
467
457
|
*/
|
|
468
|
-
resetSeed: function (
|
|
469
|
-
|
|
470
|
-
if (arguments.length > 0) {
|
|
471
|
-
if (typeof specification === 'number') {
|
|
472
|
-
this.internals.argv.count = specification;
|
|
473
|
-
|
|
474
|
-
if (scope) {
|
|
475
|
-
this.internals.migrationMode = scope;
|
|
476
|
-
this.internals.matching = scope;
|
|
477
|
-
}
|
|
478
|
-
} else if (typeof specification === 'string') {
|
|
479
|
-
this.internals.migrationMode = scope;
|
|
480
|
-
this.internals.matching = scope;
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
this.internals.argv.count = Number.MAX_VALUE;
|
|
485
|
-
return Promise.resolve(
|
|
486
|
-
executeUndoSeed(this.internals, this.config)
|
|
487
|
-
).asCallback(callback);
|
|
458
|
+
resetSeed: function (callback) {
|
|
459
|
+
return this.undoSeed(undefined, callback);
|
|
488
460
|
},
|
|
489
461
|
|
|
490
462
|
/**
|
|
@@ -17,6 +17,7 @@ const files = {
|
|
|
17
17
|
"helper/migration-hook": require('./helper/migration-hook.js'),
|
|
18
18
|
"helper/register-events": require('./helper/register-events.js'),
|
|
19
19
|
"helper/scopes": require('./helper/scopes.js'),
|
|
20
|
+
"helper/seeder": require('./helper/seeder.js'),
|
|
20
21
|
"index": require('./index.js'),
|
|
21
22
|
"on-complete": require('./on-complete.js'),
|
|
22
23
|
"run": require('./run.js'),
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const Seed = require('../../seed');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Connects like the migrations do, the seeds need the schema of the state
|
|
7
|
+
* to know the tables they can insert into.
|
|
8
|
+
*/
|
|
9
|
+
module.exports = async function (internals, config, action) {
|
|
10
|
+
const Migrator = require('../../walker.js');
|
|
11
|
+
const index = require('../../../connect');
|
|
12
|
+
|
|
13
|
+
const migrator = await index.connect(
|
|
14
|
+
{
|
|
15
|
+
config: config.getCurrent().settings,
|
|
16
|
+
internals: internals,
|
|
17
|
+
prefix: 'migration'
|
|
18
|
+
},
|
|
19
|
+
Migrator
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
try {
|
|
23
|
+
await migrator.createMigrationsTable();
|
|
24
|
+
await Seed[action](migrator, internals.seedName);
|
|
25
|
+
return internals.onComplete(migrator, internals);
|
|
26
|
+
} catch (err) {
|
|
27
|
+
return internals.onComplete(migrator, internals, err);
|
|
28
|
+
}
|
|
29
|
+
};
|
package/lib/commands/run.js
CHANGED
|
@@ -97,21 +97,19 @@ function run (internals, config) {
|
|
|
97
97
|
report(load('db')(internals, config));
|
|
98
98
|
}
|
|
99
99
|
break;
|
|
100
|
-
case 'seed':
|
|
101
|
-
|
|
102
|
-
|
|
100
|
+
case 'seed': {
|
|
101
|
+
// seed [name], seed down [name], seed reset
|
|
102
|
+
const args = internals.argv._.map(String);
|
|
103
|
+
const undo = args[0] === 'down' || args[0] === 'reset';
|
|
103
104
|
|
|
104
|
-
if (
|
|
105
|
-
|
|
106
|
-
internals.argv.count = Number.MAX_VALUE;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
internals.argv._.shift();
|
|
110
|
-
report(load('undo-seed')(internals, config));
|
|
111
|
-
} else {
|
|
112
|
-
report(load('seed')(internals, config));
|
|
105
|
+
if (undo) {
|
|
106
|
+
args.shift();
|
|
113
107
|
}
|
|
108
|
+
|
|
109
|
+
internals.seedName = args[0];
|
|
110
|
+
report(load(undo ? 'undo-seed' : 'seed')(internals, config));
|
|
114
111
|
break;
|
|
112
|
+
}
|
|
115
113
|
|
|
116
114
|
default:
|
|
117
115
|
var plugins = internals.plugins;
|
|
@@ -125,7 +123,7 @@ function run (internals, config) {
|
|
|
125
123
|
);
|
|
126
124
|
} else {
|
|
127
125
|
log.error(
|
|
128
|
-
'Invalid Action: Must be [up|down|check|create|reset|sync|db].'
|
|
126
|
+
'Invalid Action: Must be [up|down|check|create|reset|sync|db|seed].'
|
|
129
127
|
);
|
|
130
128
|
yargs.showHelp();
|
|
131
129
|
process.exit(1);
|
package/lib/commands/seed.js
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const seeder = require('./helper/seeder');
|
|
4
|
+
|
|
3
5
|
/**
|
|
4
|
-
*
|
|
5
|
-
* finished. A new concept follows separately, see #687.
|
|
6
|
+
* Inserts the rows of the static seeds, removing those of earlier runs.
|
|
6
7
|
*/
|
|
7
|
-
module.exports = function () {
|
|
8
|
-
return
|
|
9
|
-
new Error(
|
|
10
|
-
'Seeders are not supported by db-migrate 1.0. The unfinished seeders ' +
|
|
11
|
-
'of db-migrate 0.11 are still available there.'
|
|
12
|
-
)
|
|
13
|
-
);
|
|
8
|
+
module.exports = function (internals, config) {
|
|
9
|
+
return seeder(internals, config, 'run');
|
|
14
10
|
};
|
|
@@ -16,6 +16,7 @@ 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
|
+
'seeds-dir': internals.cwd + '/seeds',
|
|
19
20
|
'ignore-completed-migrations': false,
|
|
20
21
|
'backup-state': false,
|
|
21
22
|
'lock-timeout': 60000,
|
|
@@ -26,7 +27,7 @@ module.exports = function (internals, isModule) {
|
|
|
26
27
|
internals.argv = yargs
|
|
27
28
|
.default(defaultConfig)
|
|
28
29
|
.usage(
|
|
29
|
-
'Usage: db-migrate [up|down|check|reset|sync|create|db] ' +
|
|
30
|
+
'Usage: db-migrate [up|down|check|reset|sync|create|db|seed] ' +
|
|
30
31
|
'[[dbname/]migrationName|all] [options]'
|
|
31
32
|
)
|
|
32
33
|
.describe(
|
|
@@ -111,6 +112,8 @@ module.exports = function (internals, isModule) {
|
|
|
111
112
|
.string('vcseeder-dir')
|
|
112
113
|
.describe('staticseeder-dir', 'Set the path to the Seeder directory.')
|
|
113
114
|
.string('staticseeder-dir')
|
|
115
|
+
.describe('seeds-dir', 'Set the path to the directory of the seeds.')
|
|
116
|
+
.string('seeds-dir')
|
|
114
117
|
.describe('non-transactional', 'Explicitly disable transactions')
|
|
115
118
|
.boolean('non-transactional')
|
|
116
119
|
.describe('ignore-completed-migrations', 'Start at the first migration')
|
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const seeder = require('./helper/seeder');
|
|
4
|
+
|
|
3
5
|
/**
|
|
4
|
-
*
|
|
5
|
-
* finished. A new concept follows separately, see #687.
|
|
6
|
+
* Removes the rows inserted by the static seeds.
|
|
6
7
|
*/
|
|
7
|
-
module.exports = function () {
|
|
8
|
-
return
|
|
9
|
-
new Error(
|
|
10
|
-
'Seeders are not supported by db-migrate 1.0. The unfinished seeders ' +
|
|
11
|
-
'of db-migrate 0.11 are still available there.'
|
|
12
|
-
)
|
|
13
|
-
);
|
|
8
|
+
module.exports = function (internals, config) {
|
|
9
|
+
return seeder(internals, config, 'undo');
|
|
14
10
|
};
|