What is migration?
Migrations are a convenient way to alter your database schema over time in a consistent way.
- We need to run migration make sure the schema on the machine is up-to-date with the code.
Migration file
# 20211109184904_create_table.rb
class CreateProducts < ActiveRecord::Migration[7.1]
def change
create_table :products do |t|
t.string :name
t.text :description
t.timestamps
end
end
end
Do migration on a file
bundle exec rake db:migrate:up VERSION=20211109184904
Check migration status
bundle exec rails db:migrate:status
Source