@@ -12,43 +12,50 @@ class SequelizeMigrations {
1212 const dbConnectionOptions = {
1313 dbDialect : {
1414 usage : "Specify the database dialect (one of: 'mysql', 'mariadb', 'postgres', 'mssql')" ,
15- default : ''
15+ default : '' ,
16+ type : 'string'
1617 } ,
1718 dbHost : {
1819 usage : "Specify the database host" ,
19- default : ''
20+ default : '' ,
21+ type : 'string'
2022 } ,
2123 dbPort : {
2224 usage : "Specify the database port" ,
23- default : ''
25+ default : '' ,
26+ type : 'string'
2427 } ,
2528 dbName : {
2629 usage : "Specify the database name" ,
27- default : ''
30+ default : '' ,
31+ type : 'string'
2832 } ,
2933 dbUsername : {
3034 usage : "Specify the database username" ,
31- default : ''
35+ default : '' ,
36+ type : 'string'
3237 } ,
3338 dbPassword : {
3439 usage : "Specify the database password" ,
35- default : ''
40+ default : '' ,
41+ type : 'string'
3642 }
3743 }
3844
3945 this . commands = {
4046 migrations : {
4147 usage : "Sequelize migrations management for Serverless" ,
42- lifecycleEvents : [ "showPluginInfo" ] ,
4348 options : {
4449 path : {
4550 usage : "Specify the migrations path (default is './migrations')" ,
4651 shortcut : "p" ,
47- default : "./migrations"
52+ default : "./migrations" ,
53+ type : 'string'
4854 } ,
4955 verbose : {
5056 usage : "Shows sequelize logs" ,
51- shortcut : "v"
57+ shortcut : "v" ,
58+ type : 'boolean'
5259 }
5360 } ,
5461 commands : {
@@ -59,7 +66,8 @@ class SequelizeMigrations {
5966 name : {
6067 usage : "Specify the name of the migration to be created" ,
6168 shortcut : "n" ,
62- required : true
69+ required : true ,
70+ type : 'boolean'
6371 }
6472 }
6573 } ,
@@ -71,7 +79,8 @@ class SequelizeMigrations {
7179 usage :
7280 "Rolls back applied migrations in case of error (default is false)" ,
7381 shortcut : "r" ,
74- default : false
82+ default : false ,
83+ type : 'boolean'
7584 } ,
7685 ...dbConnectionOptions
7786 }
@@ -83,12 +92,14 @@ class SequelizeMigrations {
8392 times : {
8493 usage : "Specify how many times to roll back (default is 1)" ,
8594 shortcut : "t" ,
86- default : 1
95+ default : 1 ,
96+ type : 'string'
8797 } ,
8898 name : {
8999 usage :
90100 'Specify the name of the migration to be rolled back (e.g. "--name create-users.js")' ,
91- shortcut : "n"
101+ shortcut : "n" ,
102+ type : 'string'
92103 } ,
93104 ...dbConnectionOptions
94105 }
@@ -108,7 +119,8 @@ class SequelizeMigrations {
108119 usage :
109120 "Specify the status of migrations to be listed (--status pending [default] or --status executed)" ,
110121 shortcut : "s" ,
111- default : "pending"
122+ default : "pending" ,
123+ type : 'string'
112124 } ,
113125 ...dbConnectionOptions
114126 }
@@ -118,7 +130,6 @@ class SequelizeMigrations {
118130 } ;
119131
120132 this . hooks = {
121- "migrations:showPluginInfo" : this . showPluginInfo . bind ( this ) ,
122133 "migrations:up:run" : this . migrate . bind ( this ) ,
123134 "migrations:down:run" : this . revert . bind ( this ) ,
124135 "migrations:reset:run" : this . reset . bind ( this ) ,
@@ -133,10 +144,6 @@ class SequelizeMigrations {
133144 _ . get ( this . serverless , "service.custom.migrationsPath" ) ;
134145 }
135146
136- showPluginInfo ( ) {
137- this . serverless . cli . generateCommandsHelp ( [ "migrations" ] ) ;
138- }
139-
140147 setUpMigrationsHandler ( ) {
141148 const databaseConnectionUrlBuilder = new DatabaseConnectionUrlBuilder ( this . serverless , this . options ) ;
142149 const database = databaseConnectionUrlBuilder . build ( ) ;
@@ -169,7 +176,9 @@ class SequelizeMigrations {
169176 try {
170177 const migrationsHandler = this . setUpMigrationsHandler ( ) ;
171178
172- await migrationsHandler . revert ( this . options . times , this . options . name ) ;
179+ const times = parseInt ( this . options . times ) ;
180+
181+ await migrationsHandler . revert ( times , this . options . name ) ;
173182 } catch ( e ) {
174183 this . serverless . cli . log ( `Error trying to rollback migrations: \n${ e } ` ) ;
175184 process . exit ( 1 ) ;
0 commit comments