Active Record Migrations Intro
Active Record includes a migration system that allows developers to version-control database schema changes. Migrations are written in Ruby and provide a way to evolve the database schema over time.
The migration files are located in the db/migrate
directory. Migration files are usually generated using the rails g migration
command.
Example:
rails g migration CreateUsers name:string age:integer
Generates a file named db/migrate/YYYYMMDDHHMMSS_create_users.rb
.
class CreateUsers < ActiveRecord::Migration[7.1]
def change
create_table :users do |t|
t.string :name
t.integer :age
end
end
end