LinuxCommandLibrary

sequelize

Sequelize ORM migration and model CLI

TLDR

Initialize sequelize

$ npx sequelize-cli init
copy
Create model
$ npx sequelize-cli model:generate --name [User] --attributes [name:string,email:string]
copy
Run migrations
$ npx sequelize-cli db:migrate
copy
Undo last migration
$ npx sequelize-cli db:migrate:undo
copy
Create seed
$ npx sequelize-cli seed:generate --name [demo-user]
copy
Run seeds
$ npx sequelize-cli db:seed:all
copy
Create migration
$ npx sequelize-cli migration:generate --name [add-column]
copy

SYNOPSIS

sequelize-cli command [options]

DESCRIPTION

sequelize-cli manages Sequelize ORM projects, providing scaffolding for models, migrations, and seed files. The init command creates the standard project structure with config, models, migrations, and seeders directories.
Models define database table mappings with typed attributes, and the CLI generates both the model file and an initial migration. Migrations version the database schema using up and down functions, allowing incremental schema changes that can be applied or reverted. Seeds populate tables with initial or test data.
The CLI supports PostgreSQL, MySQL, MariaDB, SQLite, and Microsoft SQL Server through Sequelize's database abstraction layer.

PARAMETERS

init

Initialize project.
model:generate
Create model.
db:migrate
Run migrations.
db:migrate:undo
Revert migration.
seed:generate
Create seed file.
db:seed:all
Run all seeds.
migration:generate
Create migration.
--name NAME
Model/migration name.
--attributes ATTRS
Model attributes.

CONFIGURATION

config/config.json

Database connection configuration for development, test, and production environments, specifying host, port, username, password, dialect, and database name.
.sequelizerc
Project-level configuration file overriding default paths for models, migrations, seeders, and config directories.

CAVEATS

Node.js ORM. Database-specific syntax may vary. Migration ordering is important.

HISTORY

Sequelize is a Node.js ORM supporting PostgreSQL, MySQL, SQLite, and others. The CLI provides scaffolding and migration tools.

SEE ALSO

node(1), npm(1), knex(1)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community