The Sequelize Command Line Interface (CLI)
-
Added controller (CRUD) and validator (create and update) when generating model
-
Use npx
https://github.com/lemoissonM/cli ....When passing the attributes you can now add the reference and notNull properties direclty from the cli ex:https://github.com/lemoissonM/cli model:generate --name User --attributes 'name:string:notNull,roleId:uuid:ref(roles;id):notNull'
In the example : we are creating the table user with the attribute name of type string and it should not allow nulls, we are also adding another attribute 'roleId' which is uuid, we are adding reference to the roles table with target 'id'
- if attribute has reference :
nameOfAttribute:dataType:ref(tableName;targetKey) - if attribute should not be null :
nameOfAttribute:dataType:notNull - if attribute should not be null and has reference :
nameOfAttribute:dataType:ref(tableName;targetKey):notNull ( in this case notNull comes after reference)
Make sure you have Sequelize installed. Then install the Sequelize CLI to be used in your project with
npm install --save-dev sequelize-cliAnd then you should be able to run the CLI with
npx sequelize --helpSequelize CLI [Node: 10.21.0, CLI: 6.0.0, ORM: 6.1.0]
sequelize <command>
Commands:
sequelize db:migrate Run pending migrations
sequelize db:migrate:schema:timestamps:add Update migration table to have timestamps
sequelize db:migrate:status List the status of all migrations
sequelize db:migrate:undo Reverts a migration
sequelize db:migrate:undo:all Revert all migrations ran
sequelize db:seed Run specified seeder
sequelize db:seed:undo Deletes data from the database
sequelize db:seed:all Run every seeder
sequelize db:seed:undo:all Deletes data from the database
sequelize db:create Create database specified by configuration
sequelize db:drop Drop database specified by configuration
sequelize init Initializes project
sequelize init:config Initializes configuration
sequelize init:migrations Initializes migrations
sequelize init:models Initializes models
sequelize init:seeders Initializes seeders
sequelize migration:generate Generates a new migration file [aliases: migration:create]
sequelize model:generate Generates a model and its migration [aliases: model:create]
sequelize seed:generate Generates a new seed file [aliases: seed:create]
Options:
--version Show version number [boolean]
--help Show help [boolean]
Please specify a commandAll contributions are accepted as a PR.
- You can file issues by submitting a PR (with test) as a test case.
- Implement new feature by submitting a PR
- Improve documentation by submitting PR to Sequelize
Please read the contributing guidelines.