Sequelize migration patterns and best practices for PostgreSQL schema changes. Use when creating migrations, modifying tables, managing indexes, or handling data migrations safely.
View on GitHubfrancanete/fran-marketplace
database-expert
database-expert/skills/sequelize-migrations/SKILL.md
January 20, 2026
Select agents to install to:
npx add-skill https://github.com/francanete/fran-marketplace/blob/main/database-expert/skills/sequelize-migrations/SKILL.md -a claude-code --skill sequelize-migrationsInstallation paths:
.claude/skills/sequelize-migrations/# Sequelize Migration Patterns
## Migration Basics
### File Structure
```
migrations/
├── 20240101000000-create-users.js
├── 20240101000001-create-orders.js
├── 20240102000000-add-status-to-users.js
└── 20240103000000-add-index-to-orders.js
```
### Basic Migration Template
```javascript
'use strict';
/** @type {import('sequelize-cli').Migration} */
module.exports = {
async up(queryInterface, Sequelize) {
// Forward migration
},
async down(queryInterface, Sequelize) {
// Rollback migration
},
};
```
## Creating Tables
### Basic Table Creation
```javascript
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.createTable('users', {
id: {
type: Sequelize.BIGINT,
primaryKey: true,
autoIncrement: true,
},
email: {
type: Sequelize.TEXT,
allowNull: false,
unique: true,
},
first_name: {
type: Sequelize.TEXT,
allowNull: false,
},
last_name: {
type: Sequelize.TEXT,
allowNull: false,
},
status: {
type: Sequelize.TEXT,
allowNull: false,
defaultValue: 'active',
},
metadata: {
type: Sequelize.JSONB,
allowNull: false,
defaultValue: {},
},
created_at: {
type: Sequelize.DATE,
allowNull: false,
defaultValue: Sequelize.literal('NOW()'),
},
updated_at: {
type: Sequelize.DATE,
allowNull: false,
defaultValue: Sequelize.literal('NOW()'),
},
});
// Add indexes after table creation
await queryInterface.addIndex('users', ['email'], { unique: true });
await queryInterface.addIndex('users', ['status']);
await queryInterface.addIndex('users', ['created_at']);
},
async down(queryInterface) {
await queryInterface.dropTable('users');
},
};
```
### Table with Foreign Keys
```javascript
module.exports = {
async up(queryInterface, Sequelize) {