1 | const USAGE_INFO = `
|
2 | Perform database changes
|
3 |
|
4 | --only Optional. Filter out specific models
|
5 |
|
6 | migrate
|
7 |
|
8 | --make Optional. Take an snapshot from your models
|
9 | --apply Optional. Save changes from executed migrations
|
10 |
|
11 | --create Optional. Create database from your schema
|
12 | --destroy Optional. Drop the database entirely
|
13 |
|
14 | --up Optional. Apply all pending migrations
|
15 | --down Optional. Revert all applied migrations
|
16 | --next Optional. Apply the latest pending migration
|
17 | --prev Optional. Revert the latest applied migration
|
18 |
|
19 | --from Optional. Apply migrations from this offset
|
20 | --to Optional. Apply migrations up to this offset
|
21 |
|
22 | backup
|
23 |
|
24 | --import Optional. Load into the database, directory or file
|
25 | --export Optional. Save backup to destination, directory
|
26 |
|
27 | Examples:
|
28 | {bin} migrate --make
|
29 | {bin} migrate --apply "migration description"
|
30 | {bin} backup --load ../from/backup/or/path/to/seeds
|
31 | {bin} backup --save path/to/seeds --only Product,Cart
|
32 | `;
|
33 |
|
34 | function getHelp(binary) {
|
35 | return USAGE_INFO.replace(/{bin}/g, binary || process.argv.slice(1)[0]);
|
36 | }
|
37 |
|
38 | function runHook(db, cmd, argv) {
|
39 | argv = argv || require('wargs')(process.argv.slice(2));
|
40 | cmd = cmd || (argv._ && argv._[0]);
|
41 |
|
42 | const all = argv._ ? argv._.slice(1) : [];
|
43 | const opts = argv.flags || {};
|
44 |
|
45 | return require(`./${cmd}`)(db, {
|
46 | migrations: all,
|
47 | options: opts,
|
48 | });
|
49 | }
|
50 |
|
51 | module.exports = {
|
52 | usage: getHelp,
|
53 | execute: runHook,
|
54 | };
|