⚙️ Rails Migration


🧭 What is a Migration?

Use Ruby code to make database structure changes (DDL) like creating tables or adding columns.

Used in database level.


🏗️ Create Tasks Table

bundle exec rails generate migration CreateTasks

# db/migrate/TIMESTAMP_create_tasks.rb
class CreateTasks < ActiveRecord::Migration[7.1]
  def change
    create_table :tasks do |t|
      t.text :title
      t.timestamps
    end
  end
end

bundle exec rails db:migrate


🔍 Check Tables

bundle exec rails console
ActiveRecord::Base.connection.tables


📁 schema.rb Is Source of Truth


🔁 Rollback & Edit Migration

bundle exec rails db:rollback