### Complete Sequelize CLI Workflow Example Source: https://context7.com/sequelize/cli/llms.txt This example outlines the end-to-end process of setting up a Sequelize project, from installation and initialization to generating models, running migrations, seeding data, and rolling back changes. It covers common commands for managing the database lifecycle. ```bash # 1. Install npm install --save-dev sequelize-cli sequelize pg pg-hstore # 2. Initialize project structure npx sequelize init # 3. Edit config/config.json or create .sequelizerc # 4. Create the database NODE_ENV=development npx sequelize db:create # 5. Generate a model + migration npx sequelize model:generate \ --name Article \ --attributes title:string,body:text,authorId:integer,status:enum:'{draft,published}' # 6. Run migrations npx sequelize db:migrate # == 20240101120000-Article: migrated (0.134s) # 7. Generate and populate seed data npx sequelize seed:generate --name sample-articles # edit seeders/20240101130000-sample-articles.js ... npx sequelize db:seed:all # 8. Check status npx sequelize db:migrate:status # up 20240101120000-Article.js # 9. Rollback everything in CI teardown npx sequelize db:seed:undo:all npx sequelize db:migrate:undo:all ``` -------------------------------- ### Navigate to Repository and Install Dependencies Source: https://github.com/sequelize/cli/blob/main/CONTRIBUTING.md Change directory to the cloned repository and install the necessary Node.js modules using npm. ```bash cd /path/to/cloned/repository ``` ```bash npm install ``` -------------------------------- ### Run Sequelize CLI Help Source: https://github.com/sequelize/cli/blob/main/README.md After installation, you can run the CLI to view its help information. ```bash npx sequelize --help ``` -------------------------------- ### Install Sequelize CLI Source: https://context7.com/sequelize/cli/llms.txt Install the Sequelize CLI as a dev dependency along with Sequelize and the appropriate dialect driver. ```bash npm install --save-dev sequelize-cli sequelize mysql2 # or for PostgreSQL: npm install --save-dev sequelize-cli sequelize pg pg-hstore # or for SQLite: npm install --save-dev sequelize-cli sequelize sqlite3 # or for MSSQL: npm install --save-dev sequelize-cli sequelize tedious ``` -------------------------------- ### Install Sequelize CLI Source: https://github.com/sequelize/cli/blob/main/README.md Install the Sequelize CLI as a development dependency in your project. ```bash npm install --save-dev sequelize-cli ``` -------------------------------- ### JSON Configuration File Example Source: https://github.com/sequelize/cli/blob/main/docs/README.md Define database connection details for different environments (development, test, production) in a JSON configuration file. ```json { "development": { "username": "root", "password": null, "database": "database_development", "host": "127.0.0.1", "dialect": "mysql" }, "test": { "username": "root", "password": null, "database": "database_test", "host": "127.0.0.1", "dialect": "mysql" }, "production": { "username": "root", "password": null, "database": "database_production", "host": "127.0.0.1", "dialect": "mysql" } } ``` -------------------------------- ### TypeScript Migration File Example Source: https://context7.com/sequelize/cli/llms.txt This TypeScript migration file demonstrates how to create a 'Users' table with specified columns. It uses the `Migration` type for type safety and defines `up` and `down` methods for applying and reverting the migration. ```typescript // migrations/20240101120000-create-users.ts import type { QueryInterface, DataTypes as DataTypesType } from 'sequelize'; /** @type {import('sequelize-cli').Migration} */ module.exports = { async up(queryInterface: QueryInterface, Sequelize: typeof DataTypesType) { await queryInterface.createTable('Users', { id: { allowNull: false, autoIncrement: true, primaryKey: true, type: Sequelize.INTEGER, }, email: { type: Sequelize.STRING, allowNull: false, unique: true }, createdAt: { allowNull: false, type: Sequelize.DATE }, updatedAt: { allowNull: false, type: Sequelize.DATE }, }); }, async down(queryInterface: QueryInterface) { await queryInterface.dropTable('Users'); }, }; ``` -------------------------------- ### Add Column and Index Migration Source: https://context7.com/sequelize/cli/llms.txt An example of a migration file that adds a new column and creates a unique index on an existing table. Includes `up` and `down` operations. ```javascript 'use strict'; /** @type {import('sequelize-cli').Migration} */ module.exports = { async up(queryInterface, Sequelize) { await queryInterface.addColumn('Users', 'bio', { type: Sequelize.TEXT, allowNull: true, defaultValue: null, }); await queryInterface.addIndex('Users', ['email'], { unique: true, name: 'users_email_unique', }); }, async down(queryInterface) { await queryInterface.removeIndex('Users', 'users_email_unique'); await queryInterface.removeColumn('Users', 'bio'); }, }; ``` -------------------------------- ### Configure Dialect Specific Options Source: https://github.com/sequelize/cli/blob/main/docs/README.md Pass dialect-specific options to the underlying database connectors by using the `dialectOptions` property in the configuration. This example shows how to configure SSL options for MySQL. ```javascript var fs = require('fs'); module.exports = { development: { dialect: 'mysql', dialectOptions: { ssl: { ca: fs.readFileSync(__dirname + '/mysql-ca.crt') } } } }; ``` -------------------------------- ### Clone Sequelize CLI Repository Source: https://github.com/sequelize/cli/blob/main/CONTRIBUTING.md Clone the Sequelize CLI repository using either SSH or HTTPS. Ensure you have Git installed. ```bash git clone git@github.com:sequelize/cli.git ``` ```bash git clone https://github.com/sequelize/cli.git # Using HTTPS ``` -------------------------------- ### Initialize Sequelize Project Source: https://github.com/sequelize/cli/blob/main/docs/FAQ.md Use this command to set up the necessary files for a Sequelize project. ```bash $ sequelize init ``` -------------------------------- ### Initialize Sequelize Project Structure Source: https://context7.com/sequelize/cli/llms.txt Initialize the standard Sequelize project directories and configuration files. Use --force to re-create existing files. ```bash # Initialize everything npx sequelize init # Initialize only specific parts npx sequelize init:config npx sequelize init:models npx sequelize init:migrations npx sequelize init:seeders # Re-create (drop and recreate) an existing config npx sequelize init --force # Output: # Created "config/config.json" # models/index.js created. # migrations folder created. # seeders folder created. ``` -------------------------------- ### Sequelize CLI Commands Overview Source: https://github.com/sequelize/cli/blob/main/README.md This displays all available commands and options for the Sequelize CLI. Use these commands to manage migrations, seeds, models, and database creation/dropping. ```bash Sequelize CLI [Node: 10.21.0, CLI: 6.0.0, ORM: 6.1.0] sequelize 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 command ``` -------------------------------- ### Create Database with Sequelize CLI Source: https://context7.com/sequelize/cli/llms.txt Use `npx sequelize db:create` to create a database. You can specify the environment, charset, collation, encoding, and template. ```bash npx sequelize db:create ``` ```bash NODE_ENV=production npx sequelize db:create ``` ```bash npx sequelize db:create --charset utf8mb4 --collate utf8mb4_unicode_ci ``` ```bash npx sequelize db:create --encoding UTF8 --template template0 ``` -------------------------------- ### Create a Sequelize Seeder Source: https://github.com/sequelize/cli/blob/main/docs/FAQ.md Generate a new seeder file to populate your database with initial data. ```bash $ sequelize seed:create --name ``` -------------------------------- ### Advanced Configuration with config.js Source: https://context7.com/sequelize/cli/llms.txt Use a config.js file for advanced configurations including async operations, environment variables, SSL, and URL-based connections. ```javascript // config/config.js — supports async, environment variables, SSL, and URL-based connections const fs = require('fs'); module.exports = { development: { username: process.env.DB_USER, password: process.env.DB_PASS, database: process.env.DB_NAME, host: process.env.DB_HOST || '127.0.0.1', dialect: 'postgres', dialectOptions: { ssl: { ca: fs.readFileSync(__dirname + '/certs/server-ca.pem'), }, }, }, // URL-based (overrides individual fields): staging: { url: 'postgres://user:pass@staging-host.example.com/mydb', dialect: 'postgres', }, // Environment variable reference: production: { use_env_variable: 'DATABASE_URL', dialect: 'postgres', ssl: true, dialectOptions: { ssl: { require: true, rejectUnauthorized: false }, }, }, }; ``` -------------------------------- ### Run All Sequelize Seeders Source: https://github.com/sequelize/cli/blob/main/docs/FAQ.md Execute all defined seeders to populate the database. ```bash $ sequelize db:seed:all ``` -------------------------------- ### Create a Sequelize Migration Source: https://github.com/sequelize/cli/blob/main/docs/FAQ.md Generate a new migration file by providing a descriptive name for the migration. ```bash $ sequelize migration:create --name ``` -------------------------------- ### Configure CLI Options with Node.js Script Source: https://github.com/sequelize/cli/blob/main/docs/README.md Use a Node.js script for the .sequelizerc file to programmatically define configuration paths. ```javascript var path = require('path') module.exports = { 'config': path.resolve('config', 'database.json'), 'migrations-path': path.resolve('db', 'migrate') } ``` -------------------------------- ### Configuration using Environment Variable Source: https://github.com/sequelize/cli/blob/main/docs/README.md Specify an environment variable name in the JSON configuration to use for the database connection URL. ```json { "production": { "use_env_variable": "DB_CONNECTION_STRING" } } ``` -------------------------------- ### Configure Project Paths with .sequelizerc Source: https://context7.com/sequelize/cli/llms.txt Use a .sequelizerc file to override default folder paths for models, migrations, and seeders. ```javascript // .sequelizerc const path = require('path'); module.exports = { 'config': path.resolve('config', 'database.js'), 'models-path': path.resolve('src', 'models'), 'migrations-path': path.resolve('db', 'migrations'), 'seeders-path': path.resolve('db', 'seeders'), }; ``` -------------------------------- ### Run Pending Migrations with Options Source: https://context7.com/sequelize/cli/llms.txt Executes pending migrations. Supports filtering by specific files (`--to`, `--from`, `--name`), environment (`--env`), or using a connection URL (`--url`). ```bash # Run all pending migrations npx sequelize db:migrate # Run migrations up to (and including) a specific file npx sequelize db:migrate --to 20240101130000-add-bio-to-users.js # Run migrations starting from a specific file (exclusive lower bound) npx sequelize db:migrate --from 20240101120000-User.js # Run only one specific migration by name npx sequelize db:migrate --name 20240101130000-add-bio-to-users.js # Run against production environment npx sequelize db:migrate --env production # Run using a connection URL (bypasses config file) npx sequelize db:migrate --url 'postgres://user:pass@localhost/mydb' # Output: # Loaded configuration file "config/config.json". # Using environment "development". # == 20240101120000-User: migrating ======= # == 20240101120000-User: migrated (0.123s) # == 20240101130000-add-bio-to-users: migrating ======= # == 20240101130000-add-bio-to-users: migrated (0.045s) ``` -------------------------------- ### JSON Configuration with URL Property Source: https://github.com/sequelize/cli/blob/main/docs/README.md Configure a database connection using a single URL string within the JSON configuration. ```json { "development": { "url": "mysql://root:password@mysql_host.com/database_name", "dialect": "mysql" } } ``` -------------------------------- ### Execute All Sequelize Migrations Source: https://github.com/sequelize/cli/blob/main/docs/FAQ.md Run all pending database migrations to update the schema. ```bash $ sequelize db:migrate ``` -------------------------------- ### Configuration for PostgreSQL SSL Connection Source: https://github.com/sequelize/cli/blob/main/docs/README.md Configure a PostgreSQL connection using an environment variable and enable SSL in both the base config and dialect options. ```json { "production": { "use_env_variable":"DB_CONNECTION_STRING", "dialect":"postgres", "ssl": true, "dialectOptions": { "ssl": true } } } ``` -------------------------------- ### Run Sequelize CLI Tests Source: https://github.com/sequelize/cli/blob/main/CONTRIBUTING.md Execute the test suite for Sequelize CLI. This command also handles building the CLI using Babel. The tests may take several minutes to complete. ```bash npm test ``` -------------------------------- ### Generate Model and Migration with Attributes Source: https://context7.com/sequelize/cli/llms.txt Creates a Sequelize model file and a corresponding `CREATE TABLE` migration. Supports various data types, enums, and snake_case naming. ```bash # Basic usage npx sequelize model:generate --name User --attributes firstName:string,lastName:string,email:string # With enum, integer, boolean, and date npx sequelize model:generate \ --name Post \ --attributes title:string,body:text,status:enum:'{draft,published,archived}',views:integer,published:boolean,publishedAt:date # With snake_case timestamps npx sequelize model:generate --name Comment --attributes body:text,userId:integer --underscored # Output: # New model was created at models/user.js . # New migration was created at migrations/20240101120000-User.js . ``` -------------------------------- ### Auto-Loading Model Registry (models/index.js) Source: https://context7.com/sequelize/cli/llms.txt This JavaScript file, typically generated by `sequelize init`, sets up Sequelize, dynamically imports model files, associates them, and exports a `db` object. It reads the environment from `NODE_ENV` and uses configuration from `config.json`. ```javascript // models/index.js (auto-generated by `sequelize init`) 'use strict'; const fs = require('fs'); const path = require('path'); const Sequelize = require('sequelize'); const process = require('process'); const basename = path.basename(__filename); const env = process.env.NODE_ENV || 'development'; const config = require('../config/config.json')[env]; const db = {}; let sequelize; if (config.use_env_variable) { sequelize = new Sequelize(process.env[config.use_env_variable], config); } else { sequelize = new Sequelize(config.database, config.username, config.password, config); } fs.readdirSync(__dirname) .filter(file => file.indexOf('.') !== 0 && file !== basename && file.slice(-3) === '.js' && file.indexOf('.test.js') === -1 ) .forEach(file => { const model = require(path.join(__dirname, file))(sequelize, Sequelize.DataTypes); db[model.name] = model; }); Object.keys(db).forEach(modelName => { if (db[modelName].associate) { db[modelName].associate(db); } }); db.sequelize = sequelize; db.Sequelize = Sequelize; module.exports = db; // Usage in application code: const { User, Post, sequelize } = require('./models'); const users = await User.findAll({ where: { active: true } }); ``` -------------------------------- ### Create or Drop Database with sequelize db:create / db:drop Source: https://context7.com/sequelize/cli/llms.txt Creates or drops the database specified in the active environment's configuration. Supports PostgreSQL, MySQL, and MSSQL. Dialect-specific options can be passed as flags. ```bash npx sequelize db:create npx sequelize db:drop ``` -------------------------------- ### Drop Database with Sequelize CLI Source: https://context7.com/sequelize/cli/llms.txt Use `npx sequelize db:drop` to drop a database, specifying the environment if necessary. ```bash npx sequelize db:drop --env test ``` -------------------------------- ### Basic Migration File Structure Source: https://github.com/sequelize/cli/blob/main/docs/README.md Define the structure for a Sequelize migration file. Migrations must export an object with `up` and `down` methods. The `up` method handles forward migration, and the `down` method handles rollback. Use Promises or callbacks for asynchronous operations. ```javascript "use strict"; module.exports = { up: function(queryInterface, Sequelize, done) { done(); }, down: function(queryInterface) { return new Promise(function (resolve, reject) { resolve(); }); } }; ``` -------------------------------- ### Generate an Empty Migration File Source: https://context7.com/sequelize/cli/llms.txt Creates a blank migration file with a timestamped name, suitable for custom schema changes not tied to a specific model generation. ```bash npx sequelize migration:generate --name add-bio-to-users # New migration was created at migrations/20240101130000-add-bio-to-users.js . ``` -------------------------------- ### List Migration Status with sequelize db:migrate:status Source: https://context7.com/sequelize/cli/llms.txt Prints the execution status of all migration files. 'up' indicates executed, and 'down' indicates pending. ```bash npx sequelize db:migrate:status # Output: # Loaded configuration file "config/config.json". # Using environment "development". # up 20240101120000-User.js # up 20240101130000-add-bio-to-users.js # down 20240101140000-add-roles-table.js ``` -------------------------------- ### Configure Migration and Seeder Storage Source: https://context7.com/sequelize/cli/llms.txt Defines where Sequelize CLI stores migration execution status and seeder states. Supports 'sequelize' (DB table), 'json' (flat file), and 'none' backends. ```json { "development": { "username": "root", "password": null, "database": "myapp_development", "host": "127.0.0.1", "dialect": "mysql", "migrationStorage": "sequelize", "migrationStorageTableName": "schema_migrations", "migrationStorageTableSchema": "myschema", "seederStorage": "json", "seederStoragePath": "db/seeds-state.json", "seederStorageTableName": "sequelize_seeds" } } ``` -------------------------------- ### Run All Seeders with sequelize db:seed:all Source: https://context7.com/sequelize/cli/llms.txt Executes every seeder file in the seeders/ directory. Seeder execution is not tracked by default. Configure seederStorage in config.json to enable tracking. ```bash # Run all seeders npx sequelize db:seed:all # Run against staging environment npx sequelize db:seed:all --env staging # Custom seeders path npx sequelize db:seed:all --seeders-path db/seeds # Output: # == 20240101150000-demo-users: migrating ======= # == 20240101150000-demo-users: migrated (0.056s) ``` -------------------------------- ### Generate Seed File with sequelize seed:generate Source: https://context7.com/sequelize/cli/llms.txt Creates a blank seeder file with a timestamped name in the seeders/ directory. Seeders use the same up/down interface as migrations. ```bash npx sequelize seed:generate --name demo-users # New seed was created at seeders/20240101150000-demo-users.js . ``` ```javascript 'use strict'; /** @type {import('sequelize-cli').Migration} */ module.exports = { async up(queryInterface) { await queryInterface.bulkInsert('Users', [ { firstName: 'Alice', lastName: 'Smith', email: 'alice@example.com', createdAt: new Date(), updatedAt: new Date(), }, { firstName: 'Bob', lastName: 'Jones', email: 'bob@example.com', createdAt: new Date(), updatedAt: new Date(), }, ], {}); }, async down(queryInterface) { await queryInterface.bulkDelete('Users', null, {}); }, }; ``` -------------------------------- ### Add Migration Schema Timestamps Source: https://github.com/sequelize/cli/blob/main/docs/README.md Run this command to add timestamps to the migration schema, which helps in tracking when migrations were executed. This is an opt-in feature for enhanced migration management. ```bash $ sequelize db:migrate:schema:timestamps:add ``` -------------------------------- ### Generate a Sequelize Model Source: https://github.com/sequelize/cli/blob/main/docs/FAQ.md Create a new model by specifying its name and attributes. Attributes are comma-separated with type definitions. ```bash $ sequelize model:create --name User --attributes name:string,state:boolean,birth:date,card:integer,role:enum:'{Admin,Guest}' ``` -------------------------------- ### Configure JSON Migration Storage Source: https://github.com/sequelize/cli/blob/main/docs/README.md Use this configuration to store migration metadata in a JSON file instead of the database. Specify the file path with `migrationStoragePath` or use the default `sequelize-meta.json`. This is useful for managing migrations in a version-controlled environment. ```json { "development": { "username": "root", "password": null, "database": "database_development", "host": "127.0.0.1", "dialect": "mysql", // Use a different storage type. Default: sequelize "migrationStorage": "json", // Use a different file name. Default: sequelize-meta.json "migrationStoragePath": "sequelizeMeta.json", // Use a different table name. Default: SequelizeMeta "migrationStorageTableName": "sequelize_meta", // Use a different schema (Postgres-only). Default: undefined "migrationStorageTableSchema": "sequelize_schema" } } ``` -------------------------------- ### Configure JSON Seeder Storage Source: https://github.com/sequelize/cli/blob/main/docs/README.md Configure the CLI to store seeder metadata in a JSON file. Set `seederStorage` to `json` and optionally specify `seederStoragePath` for a custom file name, defaulting to `sequelize-data.json`. This allows for version control of seed data. ```json { "development": { "username": "root", "password": null, "database": "database_development", "host": "127.0.0.1", "dialect": "mysql", // Use a different storage. Default: none "seederStorage": "json", // Use a different file name. Default: sequelize-data.json "seederStoragePath": "sequelizeData.json", // Use a different table name. Default: SequelizeData "seederStorageTableName": "sequelize_data" } } ``` -------------------------------- ### Run Specific Seeder with sequelize db:seed Source: https://context7.com/sequelize/cli/llms.txt Executes one or more named seeder files instead of running all seeders. Use the --seed flag for each seeder to run. ```bash # Run a single seeder npx sequelize db:seed --seed 20240101150000-demo-users.js # Run multiple seeders npx sequelize db:seed --seed 20240101150000-demo-users.js --seed 20240101160000-demo-posts.js ``` -------------------------------- ### Generated Sequelize Model Structure Source: https://context7.com/sequelize/cli/llms.txt The standard structure for a Sequelize model file generated by the CLI. Includes initialization and association definitions. ```javascript 'use strict'; const { Model } = require('sequelize'); module.exports = (sequelize, DataTypes) => { class User extends Model { static associate(models) { // define associations here } } User.init({ firstName: DataTypes.STRING, lastName: DataTypes.STRING, email: DataTypes.STRING, }, { sequelize, modelName: 'User', }); return User; }; ``` -------------------------------- ### Add Timestamps to Meta Table with sequelize db:migrate:schema:timestamps:add Source: https://context7.com/sequelize/cli/llms.txt Upgrades the SequelizeMeta tracking table to include createdAt and updatedAt columns. Run this command once after enabling timestamped migration tracking. ```bash npx sequelize db:migrate:schema:timestamps:add # Output: # Successfully added timestamps to MetaTable. # (or) # MetaTable already has timestamps. ``` -------------------------------- ### Generated Migration for Model Creation Source: https://context7.com/sequelize/cli/llms.txt A typical migration file generated for creating a table corresponding to a Sequelize model. Includes `up` and `down` methods for schema changes. ```javascript 'use strict'; /** @type {import('sequelize-cli').Migration} */ module.exports = { async up(queryInterface, Sequelize) { await queryInterface.createTable('Users', { id: { allowNull: false, autoIncrement: true, primaryKey: true, type: Sequelize.INTEGER, }, firstName: { type: Sequelize.STRING }, lastName: { type: Sequelize.STRING }, email: { type: Sequelize.STRING }, createdAt: { allowNull: false, type: Sequelize.DATE }, updatedAt: { allowNull: false, type: Sequelize.DATE }, }); }, async down(queryInterface) { await queryInterface.dropTable('Users'); }, }; ``` -------------------------------- ### Sequelize CLI Global Flags Source: https://context7.com/sequelize/cli/llms.txt These flags can be used with any Sequelize CLI command to override configuration file defaults. They allow specifying environment, config file path, migration/seeder/model paths, connection URL, and enabling debug mode. ```bash npx sequelize db:migrate \ --env production \ --config config/database.js \ --options-path .sequelizerc \ --migrations-path db/migrations \ --seeders-path db/seeds \ --models-path src/models \ --url 'mysql://root:pass@localhost/mydb' \ --debug ``` -------------------------------- ### Handle Enum Type in Model Creation Source: https://github.com/sequelize/cli/blob/main/docs/FAQ.md When creating a model with an enum type, ensure the enum values within curly braces are properly quoted or escaped for your shell to avoid errors. ```bash sequelize model:create --name User --attributes role:enum:'{Admin,Guest}' ``` ```bash sequelize model:create --name User --attributes role:enum:'{Admin, Guest}' ``` ```bash sequelize model:create --name User --attributes role:enum:\{Admin,Guest\} ``` -------------------------------- ### Accessing Environment Variables in JS Config Source: https://github.com/sequelize/cli/blob/main/docs/README.md Directly access environment variables within a JavaScript configuration file for dynamic settings. ```javascript module.exports = { "production": { "hostname": process.env.DB_HOSTNAME } } ``` -------------------------------- ### Rollback All Sequelize Migrations Source: https://github.com/sequelize/cli/blob/main/docs/FAQ.md Undo all executed database migrations. ```bash $ sequelize db:migrate:undo:all ``` -------------------------------- ### Rollback All Sequelize Seeders Source: https://github.com/sequelize/cli/blob/main/docs/FAQ.md Undo all executed seeders, removing the data they added. ```bash $ sequelize db:seed:undo:all ``` -------------------------------- ### Revert All Seeders with sequelize db:seed:undo:all Source: https://context7.com/sequelize/cli/llms.txt Calls the down function of all seeders in reverse order. This is useful for resetting test databases between test runs. ```bash npx sequelize db:seed:undo:all # Output: # == 20240101160000-demo-posts: reverting ======= # == 20240101160000-demo-posts: reverted (0.021s) # == 20240101150000-demo-users: reverting ======= # == 20240101150000-demo-users: reverted (0.034s) ``` -------------------------------- ### Revert All Migrations with sequelize db:migrate:undo:all Source: https://context7.com/sequelize/cli/llms.txt Rolls back every executed migration in reverse chronological order. The --to flag can be used to revert to a specific point in migration history. ```bash # Revert all migrations npx sequelize db:migrate:undo:all # Revert down to (but not including) a specific migration npx sequelize db:migrate:undo:all --to 20240101120000-User.js # Output: # == 20240101130000-add-bio-to-users: reverting ======= # == 20240101130000-add-bio-to-users: reverted (0.032s) # == 20240101120000-User: reverting ======= # == 20240101120000-User: reverted (0.089s) ``` -------------------------------- ### Revert Last or Specific Seeder with sequelize db:seed:undo Source: https://context7.com/sequelize/cli/llms.txt Calls the down function of the most recently run seeder, or a specific one when --seed is provided. If storage is 'none' (default), it targets the last pending file. ```bash # Undo the most recent seeder npx sequelize db:seed:undo # Undo a specific seeder npx sequelize db:seed:undo --seed 20240101150000-demo-users.js ``` -------------------------------- ### Revert Last Migration with sequelize db:migrate:undo Source: https://context7.com/sequelize/cli/llms.txt Rolls back the most recently executed migration. Optionally, a specific migration can be reverted using the --name flag. ```bash # Undo the last executed migration npx sequelize db:migrate:undo # Undo a specific migration by filename npx sequelize db:migrate:undo --name 20240101130000-add-bio-to-users.js # Output: # == 20240101130000-add-bio-to-users: reverting ======= # == 20240101130000-add-bio-to-users: reverted (0.032s) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.