Dissecting Rails Migrations: Anatomy, Rollbacks, and Errors (Rails 8.1)
A Rails migration is a timestamped Ruby class inheriting from ActiveRecord::Migration whose change method alters the database schema. bin/rails db:migrate runs each pending migration once, records its version in the schema_migrations table, and dumps the result to db/schema.rb. Rollbacks invert change; irreversible steps need up and down. On PostgreSQL and SQLite, each migration runs inside a transaction.