不要怂,就是干,撸起袖子干!

Commit e7c86283 by Ægir Örn Símonarson Committed by Simon Schick

docs(migrations): use npx sequelize-cli when migrating (#10935)

1 parent eef1e88d
Showing with 11 additions and 11 deletions
...@@ -19,7 +19,7 @@ $ npm install --save sequelize-cli ...@@ -19,7 +19,7 @@ $ npm install --save sequelize-cli
To create an empty project you will need to execute `init` command To create an empty project you will need to execute `init` command
```bash ```bash
$ npx sequelize init $ npx sequelize-cli init
``` ```
This will create following folders This will create following folders
...@@ -75,7 +75,7 @@ We will use `model:generate` command. This command requires two options ...@@ -75,7 +75,7 @@ We will use `model:generate` command. This command requires two options
Let's create a model named `User`. Let's create a model named `User`.
```bash ```bash
$ npx sequelize model:generate --name User --attributes firstName:string,lastName:string,email:string $ npx sequelize-cli model:generate --name User --attributes firstName:string,lastName:string,email:string
``` ```
This will do following This will do following
...@@ -90,7 +90,7 @@ This will do following ...@@ -90,7 +90,7 @@ This will do following
Until this step, we haven't inserted anything into the database. We have just created required model and migration files for our first model `User`. Now to actually create that table in database you need to run `db:migrate` command. Until this step, we haven't inserted anything into the database. We have just created required model and migration files for our first model `User`. Now to actually create that table in database you need to run `db:migrate` command.
```bash ```bash
$ npx sequelize db:migrate $ npx sequelize-cli db:migrate
``` ```
This command will execute these steps: This command will execute these steps:
...@@ -106,13 +106,13 @@ Now our table has been created and saved in database. With migration you can rev ...@@ -106,13 +106,13 @@ Now our table has been created and saved in database. With migration you can rev
You can use `db:migrate:undo`, this command will revert most recent migration. You can use `db:migrate:undo`, this command will revert most recent migration.
```bash ```bash
$ npx sequelize db:migrate:undo $ npx sequelize-cli db:migrate:undo
``` ```
You can revert back to initial state by undoing all migrations with `db:migrate:undo:all` command. You can also revert back to a specific migration by passing its name in `--to` option. You can revert back to initial state by undoing all migrations with `db:migrate:undo:all` command. You can also revert back to a specific migration by passing its name in `--to` option.
```bash ```bash
$ npx sequelize db:migrate:undo:all --to XXXXXXXXXXXXXX-create-posts.js $ npx sequelize-cli db:migrate:undo:all --to XXXXXXXXXXXXXX-create-posts.js
``` ```
### Creating First Seed ### Creating First Seed
...@@ -124,7 +124,7 @@ To manage all data migrations you can use seeders. Seed files are some change in ...@@ -124,7 +124,7 @@ To manage all data migrations you can use seeders. Seed files are some change in
Let's create a seed file which will add a demo user to our `User` table. Let's create a seed file which will add a demo user to our `User` table.
```bash ```bash
$ npx sequelize seed:generate --name demo-user $ npx sequelize-cli seed:generate --name demo-user
``` ```
This command will create a seed file in `seeders` folder. File name will look something like `XXXXXXXXXXXXXX-demo-user.js`. It follows the same `up / down` semantics as the migration files. This command will create a seed file in `seeders` folder. File name will look something like `XXXXXXXXXXXXXX-demo-user.js`. It follows the same `up / down` semantics as the migration files.
...@@ -155,7 +155,7 @@ module.exports = { ...@@ -155,7 +155,7 @@ module.exports = {
In last step you have create a seed file. It's still not committed to database. To do that we need to run a simple command. In last step you have create a seed file. It's still not committed to database. To do that we need to run a simple command.
```bash ```bash
$ npx sequelize db:seed:all $ npx sequelize-cli db:seed:all
``` ```
This will execute that seed file and you will have a demo user inserted into `User` table. This will execute that seed file and you will have a demo user inserted into `User` table.
...@@ -169,19 +169,19 @@ Seeders can be undone if they are using any storage. There are two commands avai ...@@ -169,19 +169,19 @@ Seeders can be undone if they are using any storage. There are two commands avai
If you wish to undo most recent seed If you wish to undo most recent seed
```bash ```bash
$ npx sequelize db:seed:undo $ npx sequelize-cli db:seed:undo
``` ```
If you wish to undo a specific seed If you wish to undo a specific seed
```bash ```bash
$ npx sequelize db:seed:undo --seed name-of-seed-as-in-data $ npx sequelize-cli db:seed:undo --seed name-of-seed-as-in-data
``` ```
If you wish to undo all seeds If you wish to undo all seeds
```bash ```bash
$ npx sequelize db:seed:undo:all $ npx sequelize-cli db:seed:undo:all
``` ```
## Advance Topics ## Advance Topics
...@@ -537,7 +537,7 @@ As an alternative to the `--config` option with configuration files defining you ...@@ -537,7 +537,7 @@ As an alternative to the `--config` option with configuration files defining you
use the `--url` option to pass in a connection string. For example: use the `--url` option to pass in a connection string. For example:
```bash ```bash
$ npx sequelize db:migrate --url 'mysql://root:password@mysql_host.com/database_name' $ npx sequelize-cli db:migrate --url 'mysql://root:password@mysql_host.com/database_name'
``` ```
### Passing Dialect Specific Options ### Passing Dialect Specific Options
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!