Create and manage database migrations safely with rollback support. Use when modifying database schema, adding indexes, or managing database changes.
View on GitHubarmanzeroeight/fastagent-plugins
backend-developer
plugins/backend-developer/skills/database-migration-helper/SKILL.md
January 21, 2026
Select agents to install to:
npx add-skill https://github.com/armanzeroeight/fastagent-plugins/blob/main/plugins/backend-developer/skills/database-migration-helper/SKILL.md -a claude-code --skill database-migration-helperInstallation paths:
.claude/skills/database-migration-helper/# Database Migration Helper
Create and manage database migrations safely with proper rollback support.
## Quick Start
Create migration files with up/down functions, test locally, backup before production, run migrations incrementally.
## Instructions
### Migration Structure
**Basic migration:**
```javascript
// migrations/001_create_users_table.js
exports.up = async (db) => {
await db.schema.createTable('users', (table) => {
table.increments('id').primary();
table.string('email').unique().notNullable();
table.string('password_hash').notNullable();
table.timestamps(true, true);
});
};
exports.down = async (db) => {
await db.schema.dropTable('users');
};
```
### Creating Tables
**With Knex:**
```javascript
exports.up = async (knex) => {
await knex.schema.createTable('posts', (table) => {
table.increments('id').primary();
table.integer('user_id').unsigned().notNullable();
table.string('title', 200).notNullable();
table.text('content');
table.enum('status', ['draft', 'published', 'archived']).defaultTo('draft');
table.timestamps(true, true);
// Foreign key
table.foreign('user_id').references('users.id').onDelete('CASCADE');
// Indexes
table.index('user_id');
table.index('status');
});
};
exports.down = async (knex) => {
await knex.schema.dropTable('posts');
};
```
**With raw SQL:**
```sql
-- migrations/001_create_users.up.sql
CREATE TABLE users (
id SERIAL PRIMARY KEY,
email VARCHAR(255) UNIQUE NOT NULL,
password_hash VARCHAR(255) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX idx_users_email ON users(email);
-- migrations/001_create_users.down.sql
DROP TABLE IF EXISTS users;
```
### Adding Columns
```javascript
exports.up = async (knex) => {
await knex.schema.table('users', (table) => {
table.string('phone', 20);
table.boolean('is_verified').defaultTo(false);
});
};
ex