-
-
Notifications
You must be signed in to change notification settings - Fork 189
/
Reset.js
68 lines (58 loc) · 1.42 KB
/
Reset.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
'use strict'
/**
* adonis-lucid
*
* (c) Harminder Virk <virk@adonisjs.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
const Command = require('./Command')
class Reset extends Command {
/**
* signature to be used by ace
*
* @return {String}
*
* @public
*/
get signature () {
return 'migration:reset {-f,--force?} {--log?:Log SQL queries that will run}'
}
/**
* command description to be used by ace
*
* @return {String}
*
* @public
*/
get description () {
return 'Reset migrations to latest batch'
}
/**
* this method will rollback all the migrations latest batch.
*
* @param {Object} options
* @param {Object} flags
*
* @public
*/
* handle (options, flags) {
try {
this.checkEnv(flags.force)
const migrationsFiles = this.loadFiles(this.helpers.migrationsPath())
const MigrationsRunner = this.migrations
const response = yield new MigrationsRunner().down(migrationsFiles, 0, flags.log)
if (flags.log && !response.status) {
this._logQueries(response)
return
}
const successMessage = 'Rolled back to latest batch.'
const infoMessage = 'Already at the latest batch.'
this._log(response.status, successMessage, infoMessage)
} catch (e) {
this.error(e)
}
}
}
module.exports = Reset