[Rails] Intial data in Migrations

Chris Mear
Mon, 13 Feb 2006 14:14:10 -0000

On 11 Feb 2006, at 1:03 am, Tom Mornini wrote:
>
> On Feb 10, 2006, at 4:02 PM, Sean Wolfe wrote:
>
>> One thing I found annoying about Migrations, besides that you have a
>> very limited ways to define your data, is that it will overwrite
>> EVERYTHING in your schema file. So if you spend hours customizing
>> your
>> initial schema file, to get it work, exactly like you''ll need
it,
>> that
>> work immediately becomes for nothing once you run a migration. Your
>> entire schema will get rewritten, not appended to.
>>
>> In that case, with migrations, how is one suppose to handle initial
>> data, such a look up table (such as state or country). Do those get
>> put into a separate file? something like an initialize_db.rb?
>>
>> How have others been able to handle this with migrations?
>
> db/migrate:
>   001_create_schema.rb
>   002_load_units.rb
>   003_load_settlement_states.rb

Or, in other words, don''t edit schema.rb directly. Everything that
you were putting in schema.rb by hand, put into your first migration
instead. It should be your first migration that sets up the database
from scratch.

As it says at the top of schema.rb:

# This file is autogenerated. Instead of editing this file, please
use the
# migrations feature of ActiveRecord to incrementally modify your
database, and
# then regenerate this schema definition.

Chris