below is the list of commands for sequelize cli
Create Model with Migration
npx sequelize-cli model:generate --name User --attributes name:string,first_name:string
Create Migration
npx sequelize-cli migration:create --name modify_rates_add_weight
Run Migration
npx sequelize-cli db:migrate --env=development
Adding Foreign Key to Migrations
type: Sequelize.INTEGER,
references: {
model: "vendors", // tables name not model name
key: 'id'
}
Create Seed
npx sequelize-cli seed:generate --name shippers
Timestamp In Seed
created_at: new Date(),
updated_at: new Date()
Run Seeder
npx sequelize-cli db:seed:all
Run Single Seeder
npx sequelize-cli db:seed --seed 20220622131903-file_name.js
List all available CLI commands
npx sequelize-cli --list
References
- npx sequelize-cli db:migrate | Run pending migrations
- npx sequelize-cli db:migrate:schema:timestamps:add | Update migration table to have timestamps
- npx sequelize-cli db:migrate:status | List the status of all migrations
- npx sequelize-cli db:migrate:undo | Reverts a migration
- npx sequelize-cli db:migrate:undo:all | Revert all migrations ran
- npx sequelize-cli db:seed | Run specified seeder
- npx sequelize-cli db:seed:undo | Deletes data from the database
- npx sequelize-cli db:seed:all | Run every seeder
- npx sequelize-cli db:seed:undo:all | Deletes data from the database
- npx sequelize-cli db:create | Create database specified by configuration
- npx sequelize-cli db:drop | Drop database specified by configuration
- npx sequelize-cli init | Initializes project
- npx sequelize-cli init:config | Initializes configuration
- npx sequelize-cli init:migrations | Initializes migrations
- npx sequelize-cli init:models | Initializes models
- npx sequelize-cli init:seeders | Initializes seeders
- npx sequelize-cli migration:generate | Generates a new migration file
- npx sequelize-cli migration:create | Generates a new migration file
- npx sequelize-cli model:generate | Generates a model and its migration
- npx sequelize-cli model:create | Generates a model and its migration
- npx sequelize-cli seed:generate | Generates a new seed file
- npx sequelize-cli seed:create | Generates a new seed file