-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcli.js
More file actions
79 lines (65 loc) · 2.03 KB
/
cli.js
File metadata and controls
79 lines (65 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env node
'use strict';
const meow = require('meow');
const chalk = require('chalk');
const migratio = require('./');
const cli = meow(`
Usage
migratio [command] [options]
Options
-d, --directory Directory with migrations files [Default: ./migrations]
-c, --connection Connection string to Postgres [Default: $DATABASE_URL]
-r, --revision Specify revision to up/down to
-t, --tableName Table name for metadata [Default: migratio]
-s, --schema Schema name for table with metadata [Default: public]
--unsafe Skip transaction and table locking
Commands
up Applies all migrations from current to latest
down Rollbacks all migrations in current batch
current Shows migrations in current batch
Examples
$ migratio
Current batch:
000005-images.sql (batch:3)
000004-files.sql (batch:3)
000005-images.sql (batch:3)
$ migratio down
↓ 000005-images.sql (batch:3)
↓ 000004-files.sql (batch:3)
↓ 000003-stats.sql (batch:3)
$ migratio up
↑ 000003-stats.sql (batch:3)
↑ 000004-files.sql (batch:3)
↑ 000005-images.sql (batch:3)
↑ 000006-posts.sql (batch:3)
`, {
alias: {
d: 'directory',
c: 'connection',
r: 'revision',
t: 'tableName',
s: 'schema',
h: 'help'
}
// Do not set defaults, it will unset values in package.json
});
const command = cli.input[0] || 'current';
console.log();
function error(err) {
console.error();
console.error(` 💥 ${chalk.red(err.message)}`);
console.error();
console.error(chalk.gray(err.stack));
console.error();
process.exit(1);
}
const options = cli.flags;
options.verbose = true;
if (command === 'current') {
console.log(` ${chalk.gray('Current batch:')}`);
migratio.current(options).catch(error);
} else if (command === 'up') {
migratio.up(options).catch(error);
} else if (command === 'down') {
migratio.down(options).catch(error);
}