โ Ruby on Rails learning pathRuby on Rails ยท Module 4 of 10
Migrations and the database
Migrations change the database schema in versioned steps.
๐ Key ideas
- bin/rails generate migration AddStockToProducts stock:integer creates a migration file.
- bin/rails db:migrate applies pending migrations.
- db/schema.rb records the current schema.
- bin/rails db:rollback undoes the last migration.
- 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