Why this matters
Keeps data consistent when any step fails.
Wrap multi-record changes in a database transaction and use bang methods to ensure rollback on failure.
Keeps data consistent when any step fails.
Side-by-side examples engineers can pattern-match during review.
user.update!(a: 1); order.save!; payment.save! # without transactionActiveRecord::Base.transaction do
user.update!(a: 1)
order.save!
payment.save!
endmultiple saves without transactionActiveRecord::Base.transaction { ... }From 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.