skills/infrastructure/review-migration/SKILL.md
Use when reviewing production database migrations, performing a migration safety review, planning zero-downtime migration, or deploying database changes safely. Reviews phased rollouts, lock behavior, rollback strategy, strong_migrations, and deployment ordering. Enforces: add nullable-first then backfill then enforce NOT NULL; add indexes with `algorithm: :concurrently` + `disable_ddl_transaction!` on large tables; backfill in batches outside migration transaction; check lock behavior for indexes/constraints/defaults/rewrites; use multi-step rollouts for renames/type changes/unique constraints; deploy code tolerating both old and new schemas during transitions. Never combines schema change and data backfill in one migration, never adds NOT NULL before backfill completes, never drops columns before removing all code references.
npx skillsauth add igmarin/rails-agent-skills review-migrationInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
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 |
development
Entry point for Rails development workflows covering TDD, RSpec, Service Objects, DDD, GraphQL, Engines, and Code Quality. Use when the user asks about Ruby on Rails development patterns, needs RSpec test suites generated, wants service objects scaffolded, is setting up GraphQL schemas, performing Rails code review, refactoring .rb files, working with domain-driven design, implementing background jobs, conducting Rails security checks, or building Rails engines. Generates RSpec tests, structures service objects, enforces TDD workflows, configures GraphQL schemas, and coordinates domain-driven design patterns. Trigger keywords: Rails, RSpec, TDD, Rails testing, Rails refactor, Rails API, Rails code review, domain driven design, service objects, GraphQL, Rails engine, Ruby, .rb, background jobs, Rails migrations, Rails security check.
development
Use when shipping a Rails engine gem — FIRST run full test suite (`bundle exec rspec`) and fix ALL failures, verify gemspec metadata and dependencies match tested Rails/Ruby versions, dry-run: `gem build *.gemspec && gem push --dry-run *.gem` and verify contents, generate CHANGELOG.md organized by category (added/changed/deprecated/removed/fixed), produce step-by-step upgrade notes with before/after code, set semantic version in `lib/[engine_name]/version.rb`, document deprecations with migration paths, load release assets conditionally and state which one informed the output. Trigger words: version bump, changelog, deprecation, gemspec, upgrade, release, publish gem, ship gem.
development
Orchestrates the full Rails TDD cycle with hard gates: test MUST exist, be run, and FAIL for the correct reason (e.g. undefined method, not syntax error) before any implementation code — propose minimal implementation and wait for user approval → verify test PASSES → run full suite with rubocop, brakeman, rspec all green → produce YARD documentation and self-reviewed PR; phases context/test design→implementation→iterate→finish. Use when practicing test-driven development, red-green-refactor, TDD workflow, writing tests before code, adding tests first, or building a Rails feature where specs must gate implementation.
development
Complete Rails project setup loop with hard gates: verify Ruby version matches .ruby-version, Bundler installed, database connection successful, all env vars loaded, and ALL external CI actions pinned to immutable commit SHAs (never mutable tags like @v4) → configure CI/CD pipeline with linting, testing, and security scanning → validate end-to-end with bundle install, db:create, db:migrate, rspec, and write SETUP_CHECKLIST.md; phases context/onboarding→CI/CD configuration→environment validation. Use when starting a new Rails project, running `rails new`, configuring a Gemfile or .ruby-version, setting up a development environment, or wiring up CI/CD for a Ruby on Rails app. Trigger: setup project, new Rails app, configure CI/CD, dev environment setup, rails new, Gemfile setup, .ruby-version, Ruby on Rails project bootstrap.