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

Commit e978e59b by Sushant Committed by GitHub

docs(migrations): proper lists

1 parent 4615d7f7
Showing with 17 additions and 17 deletions
...@@ -22,10 +22,10 @@ $ node_modules/.bin/sequelize init ...@@ -22,10 +22,10 @@ $ node_modules/.bin/sequelize init
This will create following folders This will create following folders
1) `config`, contains config file, which tells CLI how to connect with database - `config`, contains config file, which tells CLI how to connect with database
2) `models`, contains all models for your project - `models`, contains all models for your project
3) `migrations`, contains all migration files - `migrations`, contains all migration files
4) `seeders`, contains all seed files - `seeders`, contains all seed files
#### Configuration #### Configuration
Before continuing further we will need to tell CLI how to connect to database. To do that lets open default config file `config/config.json`. It looks something like this Before continuing further we will need to tell CLI how to connect to database. To do that lets open default config file `config/config.json`. It looks something like this
...@@ -65,8 +65,8 @@ Once you have properly configured CLI config file you are ready to create you fi ...@@ -65,8 +65,8 @@ Once you have properly configured CLI config file you are ready to create you fi
We will use `model:generate` command. This command requires two options We will use `model:generate` command. This command requires two options
1) `name`, Name of the model - `name`, Name of the model
2) `attributes`, List of model attributes - `attributes`, List of model attributes
Lets create a model named `User` Lets create a model named `User`
...@@ -76,8 +76,8 @@ $ node_modules/.bin/sequelize model:generate --name User --attributes firstName: ...@@ -76,8 +76,8 @@ $ node_modules/.bin/sequelize model:generate --name User --attributes firstName:
This will do following This will do following
1) Create a model file `user` in `models` folder - Create a model file `user` in `models` folder
2) Create a migration file with name like `XXXXXXXXXXXXXX-create-user.js` in `migrations` folder - Create a migration file with name like `XXXXXXXXXXXXXX-create-user.js` in `migrations` folder
**Note:** _Sequelize will only use Model files, its the table representation. On other hand migration file is a change in that model or more specifically that table, used by CLI. Treat migrations like a commit or a log for some change in database._ **Note:** _Sequelize will only use Model files, its the table representation. On other hand migration file is a change in that model or more specifically that table, used by CLI. Treat migrations like a commit or a log for some change in database._
...@@ -90,9 +90,9 @@ $ node_modules/.bin/sequelize db:migrate ...@@ -90,9 +90,9 @@ $ node_modules/.bin/sequelize db:migrate
This command will execute these steps This command will execute these steps
1) It will ensure a table called `SequelizeMeta` in database. This table is used to record which migration have ran on current database - Will ensure a table called `SequelizeMeta` in database. This table is used to record which migration have ran on current database
2) Start looking for any migration files which haven't ran yet. This is possible by checking `SequelizeMeta` table. In this case it will run `XXXXXXXXXXXXXX-create-user.js` migration, which we created in last step. - Start looking for any migration files which haven't ran yet. This is possible by checking `SequelizeMeta` table. In this case it will run `XXXXXXXXXXXXXX-create-user.js` migration, which we created in last step.
3) Creates a table called `User` with all columns as specified in its migration file. - Creates a table called `User` with all columns as specified in its migration file.
### Undoing Migrations ### Undoing Migrations
Now our table has been created and saved in database. With migration you can revert to old state by just running a command. Now our table has been created and saved in database. With migration you can revert to old state by just running a command.
...@@ -209,8 +209,8 @@ module.exports = { ...@@ -209,8 +209,8 @@ module.exports = {
### The `.sequelizerc` File ### The `.sequelizerc` File
This is a special configuration file. It let you specify various options that you would usually pass as arguments to CLI. Some scenarios where you can use it. This is a special configuration file. It let you specify various options that you would usually pass as arguments to CLI. Some scenarios where you can use it.
1) You want to override default path to `migrations`, `models`, `seeders` or `config` folder. - You want to override default path to `migrations`, `models`, `seeders` or `config` folder.
2) You want to rename `config.json` to something else like `database.json` - You want to rename `config.json` to something else like `database.json`
And a whole lot more. Let see how you can use this file for custom configuration. And a whole lot more. Let see how you can use this file for custom configuration.
...@@ -235,10 +235,10 @@ module.exports = { ...@@ -235,10 +235,10 @@ module.exports = {
With this config you are telling CLI to With this config you are telling CLI to
1) Use `config/database.json` file for config settings - Use `config/database.json` file for config settings
2) Use `db/models` as models folder - Use `db/models` as models folder
3) Use `db/seeders` as seeders folder - Use `db/seeders` as seeders folder
4) Use `db/migrations` as migrations folder - Use `db/migrations` as migrations folder
### Dynamic Configuration ### Dynamic Configuration
Configuration file is by default a JSON file called `config.json`. But sometimes you want to execute some code or access environment variables which is not possible in JSON files. Configuration file is by default a JSON file called `config.json`. But sometimes you want to execute some code or access environment variables which is not possible in JSON files.
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!