Explain database migrations in Rails

Beginner

Answer

Migrations are Ruby classes that allow you to evolve your database schema over time in a consistent way. They provide:

  • Version control for database schema
  • Team collaboration on schema changes
  • Database-agnostic schema modifications
  • Rollback capabilities
class CreateUsers < ActiveRecord::Migration[7.0]
  def change
    create_table :users do |t|
      t.string :email
      t.timestamps
    end
  end
end