Forum: Ruby on Rails Intial data in Migrations

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
8f15d89f469605e9e07a8b5ce5d3d5d1?d=identicon&s=25 Sean Wolfe (Guest)
on 2006-02-11 01:02
(Received via mailing list)
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?

--
Sean Wolfe
master nerd of
i heart squares, Co.

3711 N. Ravenswood Ave. #147 Chicago, IL 60613
Ph. (773) 531-6301  Fx. (773) 529-7041
http://www.iheartsquares.com
59de94a56fd2c198f33d9515d1c05961?d=identicon&s=25 Tom Mornini (Guest)
on 2006-02-11 02:04
(Received via mailing list)
db/migrate:
   001_create_schema.rb
   002_load_units.rb
   003_load_settlement_states.rb

--
-- Tom Mornini
3a0f2ec009ceffdd65f056540a409a23?d=identicon&s=25 Chris Mear (Guest)
on 2006-02-13 15:14
(Received via mailing list)
On 11 Feb 2006, at 1:03 am, Tom Mornini wrote:
>> entire schema will get rewritten, not appended to.
>   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
97a7959f0d9e6c90ddae200520e93067?d=identicon&s=25 Damon Clinkscales (Guest)
on 2006-02-13 17:54
(Received via mailing list)
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
http://damonclinkscales.com/
This topic is locked and can not be replied to.