[Rails] new rails project with legacy DB (sort of)

1 view
Skip to first unread message

agilehack

unread,
May 5, 2010, 5:23:21 PM5/5/10
to Ruby on Rails: Talk
I am starting a new rails project and have been given a DB with data
etc. The good news is that the data is not being used by any other
system so even though the DB has been designed and given to me I have
liberty to change as needed. My goal would be to tweak the DB before
starting to work well follow rails conventions. I will change table
names and add the created_at, modified_at fields manually. My issue
comes in with the ID field/primary key. I would love to add the ID
field as primary key and auto_increment so that I can create my Rails
app fresh and everything works as if I created through a migration.
Trouble being that each table already has a primary key, usually
<tablename_id> and that field also exists in other tables. So I cant
just change the field name to ID. But since the DB isn't being used
by any other system, can I just create a new column named ID and make
it the primary key(auto_increment) and remove the primary key status
from the existing? In this scenario all the data given to me remains
intact I just create and change the primary key. Or would this
destroy the data relationships of these table and cause more issues
down the road?

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonra...@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-ta...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Larry Meadors

unread,
May 5, 2010, 5:30:37 PM5/5/10
to rubyonra...@googlegroups.com
Why not start from scratch with a rails-created database, then import
the old data into it?

Seems like it'd be the least pain solution.

Larry

agilehack

unread,
May 6, 2010, 9:07:38 AM5/6/10
to Ruby on Rails: Talk
that is a great idea and I had that thought. It has several tables
and some of the table many fields so is there an easy way to do that?
Do you think taking a SQL dump of the DB and then copy paste most it
into the migration file and then run rake db:migrate?? any other
suggestions? I would think this is a very common thing amongst rails
developers being that often you are given the data or some of it,
regardless of if the DB is already relied upon or not - wanted to make
sure I was doing things smartly
> > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To unsubscribe from this group, send email to rubyonrails-ta...@googlegroups.com.
> For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en.

Marnen Laibow-Koser

unread,
May 6, 2010, 4:40:33 PM5/6/10
to rubyonra...@googlegroups.com
agilehack wrote:
> that is a great idea and I had that thought. It has several tables
> and some of the table many fields so is there an easy way to do that?
> Do you think taking a SQL dump of the DB and then copy paste most it
> into the migration file and then run rake db:migrate??

No way! That will just keep the old schema. (But see below.)

> any other
> suggestions? I would think this is a very common thing amongst rails
> developers being that often you are given the data or some of it,
> regardless of if the DB is already relied upon or not - wanted to make
> sure I was doing things smartly

The smart thing to do:
* Look at the old DB.
* Understand the data in it.
* Figure out a way of modeling that data that Rails will like.
* Write migrations to create a new DB from scratch. (It might look
nothing like the old one.)
* Import data as appropriate.

Alternatively, start by duplicating the legacy schem as you suggested,
then refactor it bit by bit.

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
mar...@marnen.org
--
Posted via http://www.ruby-forum.com/.
Reply all
Reply to author
Forward
0 new messages