โ† Ruby on Rails learning path
Ruby on Rails ยท Module 4 of 10

Migrations and the database

Migrations change the database schema in versioned steps.

๐Ÿ“– Key ideas

  1. bin/rails generate migration AddStockToProducts stock:integer creates a migration file.
  2. bin/rails db:migrate applies pending migrations.
  3. db/schema.rb records the current schema.
  4. bin/rails db:rollback undoes the last migration.
  5. config/database.yml sets the database for each environment.
๐Ÿ’ก Real-life example: Like dated amendments to a rule book: each one records exactly what changed, and anyone can replay them in order.
MigrationVersioned schema change
db:migrateApply pending migrations
schema.rbCurrent schema snapshot
db:rollbackUndo the last migration