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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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 On Wed, May 5, 2010 at 3:23 PM, agilehack <jason.rabolli-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group at http://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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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 On May 5, 5:30 pm, Larry Meadors <larry.mead...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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 > > > > > > On Wed, May 5, 2010 at 3:23 PM, agilehack <jason.rabo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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 smartlyThe 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 marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.