Migration is a way to alter your databases. It is a subclass of Active Record (the model for representing data and logic. Active Record has a series of methods that can be used to perform tasks on your databse.
Examples:
rails generate model Product name:string description:text
This would create a migration that looks like this:
class CreateProducts < ActiveRecord::Migration
def change
create_table :products do |t|
t.string :name
t.text :description
t.timestamps
end
end
end
To understand schema migration, first it's important to understand what a relational database is. A relational database is a database that contains a table structure rather than individual documents. Mongo is non-relational, Active Record is relational. So with non-relational databases, you would have to create another table and connect the two, rather than with SQL, relational databases, they're connected and updated within one table.
Schema Migration is used to update a relational databse, either to a newer or older version. Updating the database is done through Schema Migration. This is done using a tool. In Rails, this tool is rake db:migrate. Rails magic!
Rake is a Ruby Make to build up a list of tasks.
$rake --tasks
^^ Shows us the list of tasks available. Rake allows us to run tasks, particularly tasks that build off of eachother.
Schema migration allows us to have more adaptive databases that don't need to be designed form the ground up every time. It makes the updating process much easier.