Why this matters
Eases review and reduces errors in irreversible changes.
Keep migrations readable by extracting multi-step data fixes to helper methods within the migration.
Eases review and reduces errors in irreversible changes.
Side-by-side examples engineers can pattern-match during review.
def change; User.find_each { |u| u.update!(x: compute(u)) }; enddef up; backfill_x; end
private
def backfill_x; User.find_each { |u| u.update!(x: compute(u)) }; endlong loop inlinehelper method encapsulates loopFrom the same buckets as this rule.
Review SQL/database migrations for operations that can lock large tables or cause downtime. Examples: creating indexes without CONCURRENTLY (Postgres), ALTER COLUMN TYPE on big tables, adding NOT NULL without backfill, long-running updates without batching. Require an online migration strategy (CONCURRENTLY, backfill in batches, dual-write/expand-contract) and a rollback plan.