Migrations are a feature of Active Record that allows you to evolve your database schema over time. Rather than write schema modifications in pure SQL, migrations allow you to use an easy Ruby DSL to describe changes to your tables.
up
change_table
create_table
add_column
add_index
change_column
drop_table
remove_column
remove_index
- `rename_column
class CreateUsers < ActiveRecord::Migration[5.0]
def up
create_table :users do |t|
t.string :name
t.string :email
end
end
end
:string
:text
:integer
:float
:decimal
:datetime
:timestamp
:time
:date
:binary
:boolean
## Change a table
```ruby
class ChangeUsers <
def change
#your commands
end
end
# Add one column
class AddDescriptionToProduct < ActiveRecord::Migration[4.2]
def change
add_column :products, :description, :text
end
end
# Add multiple columns to a table
class AddDescriptionToProduct < ActiveRecord::Migration[4.2]
def change
add_column :products, :description, :text
end
end