Intern Track Roadmap

ActiveRecord: migrations

This course covers ActiveRecord migrations: ordered, versioned files that describe each change to a database's structure. It shows how bin/rails generate migration creates a timestamped file and how the timestamp sets the run order. It explains the change method, create_table, null: false and t.timestamps, and why Migration[8.0] carries a version number. It then covers applying pending migrations with db:migrate, reading db/schema.rb as a generated snapshot, and undoing the latest step with db:rollback. A final lesson follows one CreateArticles migration from file to table.

What you'll learn

  • ✓What a migration is and why it is committed to git
  • ✓Generating migrations and how timestamps set the run order
  • ✓Writing the change method with create_table and column options
  • ✓Applying pending migrations with db:migrate and checking db:migrate:status
  • ✓Reading db/schema.rb and loading it with db:schema:load
  • ✓Undoing the latest migration with db:rollback
Free preview · Lesson 1 2 min read

What is a migration?

Every course since ActiveRecord: model introduction assumed an articles table existed for Article.find, .create and .all. None explained where it came from, or how it could gain a column later without breaking saved rows. A migration fills that gap: one ordered, versioned instruction describing one…

Read the full lesson free →

Curriculum

7 lessons
Type to start searching...