Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Create and manage database migrations with reversible changes, proper naming conventions, and zero-downtime deployment strategies. Use this skill when creating database migration files, modifying schema, adding or removing tables/columns, managing indexes, or handling data migrations. Apply when working with migration files (e.g., db/migrate/, migrations/, alembic/, sequelize migrations), schema changes, database versioning, rollback implementations, or when you need to ensure backwards compatib
.claude/skills/microck-backend-migration-standards/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-01 | ✗→✓ | ▲ Improved | 111% | 0% |
| case-02 | ✗→✓ | ▲ Improved | 73% | 0% |
| case-07 | ✗→✓ | ▲ Improved | 76% | 0% |
| case-08 | ✗→✓ | ▲ Improved | 3% | 0% |
| case-09 | ✗→✓ | ▲ Improved | 44% | 0% |
Apply these rules when creating or modifying database migrations. Migrations are permanent records of schema evolution and must be treated with extreme care.
This Skill provides Claude Code with specific guidance on how to adhere to coding standards as they relate to how it should handle backend migrations.
Reversibility is Mandatory: Every migration MUST have a working rollback method. Test the down migration immediately after writing the up migration. If a change cannot be reversed safely (e.g., dropping a column with data), document why in comments and consider a multi-step approach.
One Logical Change Per Migration: Each migration should do exactly one thing - add a table, add a column, create an index, etc. This makes debugging easier, rollbacks safer, and code review clearer. If you need to make multiple related changes, create multiple migrations.
Never Modify Deployed Migrations: Once a migration runs in any shared environment (staging, production), it becomes immutable. Create a new migration to fix issues. Modifying deployed migrations breaks version control and causes deployment failures.
Naming Convention: Use timestamps and descriptive names that indicate the change:
20241118120000_add_email_to_users.py20241118120100_create_orders_table.rb20241118120200_add_index_on_users_email.jsThe name should answer "what does this migration do?" without reading the code.
File Organization:
migrations/schema/migrations/data/Adding Columns: Always specify default values for NOT NULL columns on existing tables to avoid locking issues:
python# BAD - locks table during backfill op.add_column('users', sa.Column('status', sa.String(), nullable=False)) # GOOD - uses default, no lock op.add_column('users', sa.Column('status', sa.String(), nullable=False, server_default='active'))
Removing Columns: Use multi-step approach for zero-downtime:
Renaming Columns: Treat as add + remove for zero-downtime:
Creating Indexes: Use concurrent index creation on large tables to avoid blocking writes:
python# PostgreSQL op.create_index('idx_users_email', 'users', ['email'], postgresql_using='btree', postgresql_concurrently=True) # MySQL op.create_index('idx_users_email', 'users', ['email'], mysql_algorithm='INPLACE', mysql_lock='NONE')
Index Naming: Use pattern idx_<table>_<column(s)> for clarity:
idx_users_emailidx_orders_user_id_created_atWhen to Index: Add indexes for:
Separate from Schema: Never mix schema and data changes in one migration. Schema changes are structural and fast; data changes are operational and slow.
Batch Processing: Process large datasets in batches to avoid memory issues and long-running transactions:
pythondef upgrade(): batch_size = 1000 connection = op.get_bind() while True: result = connection.execute( "UPDATE users SET status = 'active' WHERE status IS NULL LIMIT %s", batch_size ) if result.rowcount == 0: break
Idempotency: Data migrations should be safe to run multiple times:
python# BAD - fails on second run op.execute("INSERT INTO settings (key, value) VALUES ('feature_flag', 'true')") # GOOD - idempotent op.execute("INSERT INTO settings (key, value) VALUES ('feature_flag', 'true') ON CONFLICT (key) DO NOTHING")
Backwards Compatibility: New migrations must work with the currently deployed code version. Deploy order:
Additive Changes First: When changing column types or constraints:
Foreign Key Constraints: Add in separate migration after data is consistent to avoid validation failures.
Before Committing:
rake db:migrate or equivalentrake db:rollback or equivalentTest with Production-Like Data: Use anonymized production data dump to test migrations against realistic data volumes and edge cases.
Alembic (Python):
pythondef upgrade(): op.add_column('users', sa.Column('email', sa.String(255), nullable=True)) op.create_index('idx_users_email', 'users', ['email']) def downgrade(): op.drop_index('idx_users_email', 'users') op.drop_column('users', 'email')
Rails (Ruby):
rubydef change add_column :users, :email, :string add_index :users, :email end
Sequelize (JavaScript):
javascriptmodule.exports = { up: async (queryInterface, Sequelize) => { await queryInterface.addColumn('users', 'email', { type: Sequelize.STRING, allowNull: true }); await queryInterface.addIndex('users', ['email']); }, down: async (queryInterface, Sequelize) => { await queryInterface.removeIndex('users', ['email']); await queryInterface.removeColumn('users', 'email'); } };
If you're about to:
STOP. Review this document and plan a safer approach.
| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-01 | fail→pass | 9,339 | 10,203 | +9% | 1 | 1 | 0% | 1,800 | 3,802 | +111% | 0 | 0 | — |
case-02 | fail→pass | 10,166 | 8,042 | -21% | 1 | 1 | 0% | 1,893 | 3,284 | +73% | 0 | 0 | — |
case-03 | pass→pass | 8,667 | 6,270 | -28% | 1 | 1 | 0% | 1,608 | 2,875 | +79% | 0 | 0 | — |
case-04 | pass→pass | 7,436 | 5,344 | -28% | 1 | 1 | 0% | 1,456 | 2,751 | +89% | 0 | 0 | — |
case-05 | pass→pass | 11,963 | 14,526 | +21% | 1 | 1 | 0% | 2,428 | 4,835 | +99% | 0 | 0 | — |
case-06 | pass→pass | 10,866 | 6,093 | -44% | 1 | 1 | 0% | 1,841 | 2,873 | +56% | 0 | 0 | — |
case-07 | fail→pass | 9,782 | 5,556 | -43% | 1 | 1 | 0% | 1,647 | 2,897 | +76% | 0 | 0 | — |
case-08 | fail→pass | 19,615 | 10,431 | -47% | 1 | 1 | 0% | 3,480 | 3,587 | +3% | 0 | 0 | — |
case-09 | fail→pass | 11,701 | 7,109 | -39% | 1 | 1 | 0% | 2,142 | 3,090 | +44% | 0 | 0 | — |
case-10 | pass→pass | 12,753 | 9,330 | -27% | 1 | 1 | 0% | 2,360 | 3,475 | +47% | 0 | 0 | — |
case-11 | pass→pass | 13,353 | 9,626 | -28% | 1 | 1 | 0% | 2,174 | 3,481 | +60% | 0 | 0 | — |
case-12 | pass→pass | 15,051 | 9,651 | -36% | 1 | 1 | 0% | 2,442 | 3,594 | +47% | 0 | 0 | — |
case-13 | pass→pass | 4,146 | 6,122 | +48% | 1 | 1 | 0% | 722 | 2,775 | +284% | 0 | 0 | — |
case-14 | pass→pass | 11,838 | 8,254 | -30% | 1 | 1 | 0% | 1,938 | 3,203 | +65% | 0 | 0 | — |
case-15 | pass→pass | 9,112 | 3,912 | -57% | 1 | 1 | 0% | 1,507 | 2,387 | +58% | 0 | 0 | — |
case-16 | pass→pass | 16,947 | 6,104 | -64% | 1 | 1 | 0% | 2,743 | 2,814 | +3% | 0 | 0 | — |
case-17 | pass→pass | 11,392 | 6,790 | -40% | 1 | 1 | 0% | 1,789 | 2,903 | +62% | 0 | 0 | — |
case-18 | pass→pass | 15,543 | 12,766 | -18% | 1 | 1 | 0% | 2,514 | 3,952 | +57% | 0 | 0 | — |
case-19 | pass→pass | 9,184 | 6,330 | -31% | 1 | 1 | 0% | 1,506 | 2,949 | +96% | 0 | 0 | — |
case-20 | pass→pass | 4,438 | 5,120 | +15% | 1 | 1 | 0% | 744 | 2,674 | +259% | 0 | 0 | — |
case-21 | pass→pass | 12,899 | 10,432 | -19% | 1 | 1 | 0% | 1,992 | 3,443 | +73% | 0 | 0 | — |
case-22 | pass→pass | 11,321 | 9,567 | -15% | 1 | 1 | 0% | 1,978 | 3,697 | +87% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 22 cases were attempted. The headline lift of +23 percentage points is the difference between those two pass rates over the 22 comparable cases.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.