[Rails] Re: Intial data in Migrations

Damon Clinkscales
Mon, 13 Feb 2006 16:54:19 -0000

Chris Mear <chris@...> writes:

> >> How have others been able to handle this with migrations?
See below for a plugin I''ve been working on.

> Or, in other words, don''t edit schema.rb directly.
Agreed.

It isn''t fully baked yet, but I have a plugin that does this.
It''s called the
"first_migration" plugin.

Here''s how you install it:

script/plugin source http://damonclinkscales.com/svn/plugins/
script/plugin install first_migration

Here''s how you run it:
script/generate first_migration

USAGE:   generate first_migration   (equal to generate first_migration
InitialSchema ruby)
         generate first_migration ClassName sql  (runs db_structure_dump)
         generate first_migration ClassName sql  [file1.sql] (just uses
db/file1.sql instead)
         generate first_migration ClassName ruby (runs db_schema_dump)
         generate first_migration ClassName ruby [file1.rb] (just uses
db/file1.rb instead)

What it does:

It builds a migration file from one of four sources:
1. your db as a Rails structure dump
2. your db as a Rails schema dump
3. your db as a sql file (custom)
4. your db as a ruby schema file (custom)

Please send me feedback, as I am still improving it to handle all scenarios.

Back up your existing data because it doesn''t quite handle all
situations with
existing data quite yet.

Best,

-damon