sequelize
Manage database migrations with Sequelize
TLDR
Create a model with 3 fields and a migration file
Run the migration file
Revert all migrations
Create a seed file with the specified name to populate the database
Populate database using all seed files
SYNOPSIS
sequelize
PARAMETERS
db:create
Creates the database specified in your configuration.
db:drop
Drops the database specified in your configuration.
db:migrate
Runs pending database migrations.
db:migrate:undo
Undoes the last applied migration.
db:migrate:undo:all
Undoes all applied migrations.
db:seed
Runs specified seeders.
db:seed:undo
Undoes the last applied seeder.
db:seed:undo:all
Undoes all applied seeders.
init
Initializes a new Sequelize project with the necessary configuration files (config, models, migrations, seeders).
init:config
Generates the config.json file.
init:models
Generates the models directory.
init:migrations
Generates the migrations directory.
init:seeders
Generates the seeders directory.
model:create --name
Generates a model with specified attributes.
migration:create --name
Generates a migration file.
seeder:create --name
Generates a seeder file.
--help
Displays help information.
--version
Displays the version number.
DESCRIPTION
The `sequelize` command provides a command-line interface (CLI) tool for managing Sequelize-based projects. Sequelize is a Node.js ORM (Object-Relational Mapper) for Postgres, MySQL, SQLite and MSSQL. The `sequelize` CLI allows you to easily generate models, migrations, seeders, and other files related to your database schema. It simplifies database development tasks such as creating database schemas, migrating between schema versions, and seeding databases with initial data. It facilitates generating boilerplate code that promotes standardized project structure and best practices.
Using this tool, developers can create and manage their databases directly from the terminal using easy to understand commands.
CAVEATS
The `sequelize` CLI relies on having a properly configured `config.json` file in your project. Ensure that your database credentials (host, username, password, database name) are correctly set up in this file. Also you need to install sequelize-cli to use this tool.
Without the correct setup it may produce errors or be unusable.
CONFIGURATION
The Sequelize CLI typically relies on a `config.json` or `config.js` file in your project's root directory to define database connection settings (host, username, password, database, dialect). Ensure that this file is correctly configured with the appropriate settings for your development, testing, and production environments.
DIALECTS
Sequelize supports various database dialects, including Postgres, MySQL, SQLite, and MSSQL. Ensure that you have the corresponding database driver installed for the database you are using (e.g., `pg` for Postgres, `mysql2` for MySQL, `sqlite3` for SQLite, `tedious` for MSSQL).
HISTORY
The `sequelize` CLI evolved alongside the Sequelize ORM to provide developers with a convenient way to manage database schemas and migrations. Over time, new commands and features have been added to streamline database development workflows. It is actively maintained, with updates and improvements being regularly released.