From rails-agent-skills
Reviews production database migrations for safety, including lock behavior, rollback strategy, and zero-downtime deployment ordering. Enforces patterns like nullable-first backfill and concurrent indexes.
How this skill is triggered — by the user, by Claude, or both
Slash command
/rails-agent-skills:review-migrationThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Use this skill when schema changes must be safe in real environments.
Use this skill when schema changes must be safe in real environments.
DO NOT combine schema change and data backfill in one migration.
DO NOT add NOT NULL on a column that hasn't been fully backfilled.
DO NOT drop columns before all code references are removed.
If the project uses strong_migrations, follow it. If it does not, apply the same safety rules manually.
| Operation | Safe Pattern | Common Mistake | Why It Fails |
|---|---|---|---|
| Add column | Nullable first, backfill later, enforce NOT NULL last | add_column :t, :col, :string, null: false, default: "x" on large table | Table rewrite + lock (PG < 11) |
| Add index (large table) | algorithm: :concurrently (PG) / :inplace (MySQL) + disable_ddl_transaction! | add_index :users, :email without algorithm: :concurrently | Share lock blocks writes |
| Backfill data | Batch job outside migration transaction, throttle to reduce replication lag | User.update_all(...) inside migration | Transaction lock held for full duration |
| Rename column | Add new, copy data, migrate callers, drop old | Rename column directly | Breaks running app during deploy |
| Add NOT NULL | After backfill confirms all rows have values | Enforce NOT NULL before backfill completes | Fails or locks on rows missing values |
| Add foreign key | After cleaning orphaned records | Add FK without cleaning orphans | Constraint violation at migration time |
| Remove column | Remove code references first, deploy, then drop column | Drop column while code still reads it | unknown attribute errors at runtime |
For every step, state the expected lock or table-rewrite risk explicitly; if negligible, say why.
Deploy code that tolerates both old and new schemas during transitions.
Concurrent index (Rails / PostgreSQL):
class AddIndexOnUsersEmail < ActiveRecord::Migration[7.1]
disable_ddl_transaction!
def change
add_index :users, :email, algorithm: :concurrently
end
end
disable_ddl_transaction!is required — concurrent index creation cannot run inside a transaction.
Nullable-first column with deferred NOT NULL (Rails):
# Step 1 — Deploy: add nullable column
class AddConfirmedAtToUsers < ActiveRecord::Migration[7.1]
def change
add_column :users, :confirmed_at, :datetime
end
end
# Step 2 — Backfill outside migration (background job or script)
User.in_batches(of: 1_000) do |batch|
batch.update_all(confirmed_at: Time.current)
sleep(0.05) # throttle to reduce replication lag
end
# Step 3 — Deploy: enforce NOT NULL only after all rows are filled
class ChangeConfirmedAtNotNull < ActiveRecord::Migration[7.1]
def change
change_column_null :users, :confirmed_at, false
end
end
Type change rollout (5-step):
Not applicable and explain why.| Skill | When to chain |
|---|---|
| code-review | When reviewing PRs that include migrations |
| implement-background-job | For backfill jobs that run after schema change |
| security-check | When migrations expose or move sensitive data |
npx claudepluginhub igmarin/rails-agent-skills --plugin rails-agent-skillsGenerates zero-downtime database migrations with forward SQL, rollback SQL, and deployment sequences for schema changes like adding columns, renaming tables, or dropping columns.
Plans safe database schema migrations with zero-downtime strategies, rollback procedures, and data validation for PostgreSQL, MySQL, and SQLite.
Enforces a hard gate for production database schema changes and data transformations. Requires written migration plans with rollback strategies, dry runs, and verification steps to prevent data loss and downtime.