Skip to content

Commit

Permalink
docs(migrations): Simplify CLI Call (#10201)
Browse files Browse the repository at this point in the history
  • Loading branch information
negezor authored and sushantdhiman committed Nov 27, 2018
1 parent f2cafcc commit ed1d28b
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions docs/migrations.md
Expand Up @@ -17,7 +17,7 @@ $ npm install --save sequelize-cli
To create an empty project you will need to execute `init` command

```bash
$ node_modules/.bin/sequelize init
$ npx sequelize init
```

This will create following folders
Expand Down Expand Up @@ -71,7 +71,7 @@ We will use `model:generate` command. This command requires two options
Let's create a model named `User`.

```bash
$ node_modules/.bin/sequelize model:generate --name User --attributes firstName:string,lastName:string,email:string
$ npx sequelize model:generate --name User --attributes firstName:string,lastName:string,email:string
```

This will do following
Expand All @@ -85,7 +85,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.

```bash
$ node_modules/.bin/sequelize db:migrate
$ npx sequelize db:migrate
```

This command will execute these steps:
Expand All @@ -100,13 +100,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.

```bash
$ node_modules/.bin/sequelize db:migrate:undo
$ npx sequelize 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.

```bash
$ node_modules/.bin/sequelize db:migrate:undo:all --to XXXXXXXXXXXXXX-create-posts.js
$ npx sequelize db:migrate:undo:all --to XXXXXXXXXXXXXX-create-posts.js
```

### Creating First Seed
Expand All @@ -117,7 +117,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.

```bash
$ node_modules/.bin/sequelize seed:generate --name demo-user
$ npx sequelize 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.
Expand Down Expand Up @@ -147,7 +147,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.

```bash
$ node_modules/.bin/sequelize db:seed:all
$ npx sequelize db:seed:all
```

This will execute that seed file and you will have a demo user inserted into `User` table.
Expand All @@ -160,19 +160,19 @@ Seeders can be undone if they are using any storage. There are two commands avai
If you wish to undo most recent seed

```bash
node_modules/.bin/sequelize db:seed:undo
$ npx sequelize db:seed:undo
```

If you wish to undo a specific seed

```bash
node_modules/.bin/sequelize db:seed:undo --seed name-of-seed-as-in-data
$ npx sequelize db:seed:undo --seed name-of-seed-as-in-data
```

If you wish to undo all seeds

```bash
node_modules/.bin/sequelize db:seed:undo:all
$ npx sequelize db:seed:undo:all
```

## Advance Topics
Expand Down Expand Up @@ -514,7 +514,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:

```bash
$ node_modules/.bin/sequelize db:migrate --url 'mysql://root:password@mysql_host.com/database_name'
$ npx sequelize db:migrate --url 'mysql://root:password@mysql_host.com/database_name'
```

### Connecting over SSL
Expand Down

0 comments on commit ed1d28b

Please sign in to comment.