Skip to content

Commit 28b3c6a

Browse files
author
Manoel Ferreira
committed
Removed deprecated method that displayed plugin information because the framework removed the support; added a version to the plugin; updated README;
1 parent cfd0f31 commit 28b3c6a

File tree

5 files changed

+6162
-359
lines changed

5 files changed

+6162
-359
lines changed

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ plugins:
5656

5757
You can check whether the plugin is ready to be used through the terminal. To do so, type the following command on the CLI:
5858

59-
`serverless`
59+
`serverless --help`
6060

6161
the console should display _SequelizeMigrations_ as one of the available plugins in your Serverless project.
6262

@@ -83,7 +83,7 @@ Replace the variables with the information of your own database.
8383

8484
Obs: This plugin does not have support to create the database itself.
8585

86-
As per [Sequelize docs](http://docs.sequelizejs.com/manual/getting-started), you'll have to manually install the driver for your database of choice:
86+
As per [Sequelize docs](https://sequelize.org/v5/manual/getting-started.html), you'll have to manually install the driver for your database of choice:
8787

8888
```
8989
# One of the following:
@@ -94,9 +94,8 @@ $ npm install --save tedious # Microsoft SQL Server
9494
```
9595

9696
## Usage and command line options
97-
To see the available commands of the plugin, run `sls migrations` on the terminal. The following should appear:
97+
To see the available commands of the plugin, run `sls migrations --help` on the terminal. The following should appear:
9898
```
99-
Plugin: SequelizeMigrations
10099
migrations .................... Sequelize migrations management for Serverless
101100
migrations create ............. Create a migration file
102101
migrations up ................. Execute all pending migrations

index.js

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)