-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmigrate.js
40 lines (34 loc) · 825 Bytes
/
migrate.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
const migratio = require('migratio')
const {db, sql, pgp} = require('db')
const argv = process.argv.slice(2)
const command = argv[0]
const opts = {
directory: 'migration',
tableName: 'migration',
verbose: true,
}
function finalize () {
pgp.end()
}
function fail (err) {
console.error(err)
process.exit(1)
}
if (argv.r) {
opts.revision = argv.r
}
if (command === 'up') {
migratio.up(opts).catch(fail)
} else if (command === 'down') {
migratio.down(opts).catch(fail)
} else if (command === 'current') {
migratio.current(opts).catch(fail)
} else if (command === 'recreate') {
db.query(sql('schema')).finally(finalize).catch(fail)
} else if (command === 'seed') {
db.tx(function (t) {
return t.query(sql('seed'))
}).finally(finalize).catch(fail)
} else {
fail('invalid migration command')
}