forked from rleenders/cassandra-migrate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
87 lines (76 loc) · 2.28 KB
/
app.js
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
80
81
82
83
84
85
86
87
#!/usr/bin/env node
'use strict';
const program = require('commander');
const fs = require('fs');
const actions = require('./commands/command-actions');
const usage = [
'',
' Examples: ',
'',
' cassandra-migrate <command> [options]',
'',
' cassandra-migrate up -k <keyspace> (Runs All pending cassandra migrations)',
'',
' cassandra-migrate down -k <keyspace> (Rolls back a single cassandra migration)',
'',
' cassandra-migrate <up/down> -t <migration_timestamp>.',
'(Runs cassandra migrations UP or DOWN to a particular migration timestamp).',
'',
' cassandra-migrate create <migration_name>. (Creates a new cassandra migration)',
'',
' cassandra-migrate create <migration_name> -t <template>',
'(Creates a new cassandra migrate but uses a specified template instead of default).',
''
].join('\n');
program.on('--help', function () {
console.log(usage);
});
program
.version(JSON.parse(fs.readFileSync(__dirname + '/package.json', 'utf8')).version);
program.name = 'cassandra-migrate';
program
.command('create <name>')
.description('initialize a new migration file with title.')
.option('-t, --template "<template>"', 'sets the template for create')
.action((name, options) => {
return actions.createAction(name, options)
.then(result => {
console.log(result);
process.exit(0);
})
.catch(error => {
console.log(error);
process.exit(1);
});
});
program
.command('up')
.description('run pending migrations')
.option('-t, --timestamp "<number>"', 'run migrations up to a specified migration timestamp')
.action((options) => {
return actions.upAction(options)
.then(result => {
console.log(result);
process.exit(0);
})
.catch(error => {
console.log(error);
process.exit(1);
});
});
program
.command('down')
.description('roll back already run migrations')
.option('-t, --timestamp "<number>"', 'rollback migrations down to a specified migration timestamp')
.action((options) => {
return actions.downAction(options)
.then(result => {
console.log(result);
process.exit(0);
})
.catch(error => {
console.log(error);
process.exit(1);
});
});
program.parse(process.argv);