Migration files give you a step-by-step of what was done with the db & when
If you move your app to another host, it helps you reconstruct the database, pin-point where problems arose, and generally gives you a much more robust way to populate & evolve the database over time
From the migrations documentation:
Migrations are a convenient way to alter your database schema over
time in a consistent and easy way. They use a Ruby DSL so that you
don't have to write SQL by hand, allowing your schema and changes to
be database independent.
You can think of each migration as being a new 'version' of the
database. A schema starts off with nothing in it, and each migration
modifies it to add or remove tables, columns, or entries. Active
Record knows how to update your schema along this timeline, bringing
it from whatever point it is in the history to the latest version.
Active Record will also update your db/schema.rb file to match the
up-to-date structure of your database.
To me, it's basically a way to keep your database structure constructed correctly, even whilst migrating over different server
Answer
To answer your question, there are a number of rake methods you can use to rebuild your db:
- db:migrate runs (single) migrations that have not run yet.
- db:create
creates the database db:drop deletes the database
db:schema:load
creates tables and columns within the (existing) database following
schema.rb
db:setup does db:create, db:schema:load, db:seed
db:reset does db:drop, db:setup
If you want to create the db from scratch, you'll have to run a combination of rake db:create
, rake db:migrate
and others