blob: ad20dcdf9332b2aa2ce5da5737e7f2e401d89d24 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
Migrations
==========
Migrations are a convenient way for you to alter your database in a structured and organised manner. While you could edit fragments of SQL by hand it would then be up to you to tell other developers that they need to run your scripts when they next pull changes. You'd also have to keep track of which changes need to be run against the production machines next time you deploy. Active Record tracks which migrations have already been run so all you have to do is update your source and run `rake db:migrate`. Active Record will work out which migrations should be run.
Migrations also allow you to describe these transformation using ruby. The great thing about this is that (like most of Active Record's functionality) its database independent, you don't need to worry about the precise syntax of CREATE TABLE any more that you worry about variations on SELECT * (you can drop down to raw SQL for database specific features). For example you could use SQLite3 in development, but MySQL in production.
You'll learn all about migrations including:
* The generators you can use to create them
* The methods Active Record provides to manipulate your database
* The rake tasks that manipulate them
* How they relate to schema.rb
include::anatomy_of_a_migration.txt[]
include::creating_a_migration.txt[]
include::writing_a_migration.txt[]
include::rakeing_around.txt[]
include::using_models_in_migrations.txt[]
include::scheming.txt[]
|