Patrick Aljord
2006-Dec-07 02:42 UTC
need to transfer data from old php like db to rails style db
hey all, I have two tables like that from an old php project: artists(id,name) albums(id,artist_id,album_name) and I need to transfer the data of this database to three tables that look like this: artists(id,name) albums(id,name) artists_albums(album_id,artist_id) any idea what''s the fastest query to do this? thanx in advance Pat --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Rob Biedenharn
2006-Dec-07 02:59 UTC
Re: need to transfer data from old php like db to rails style db
On Dec 6, 2006, at 9:42 PM, Patrick Aljord wrote:> hey all, > I have two tables like that from an old php project: > artists(id,name) > albums(id,artist_id,album_name) > > and I need to transfer the data of this database to three tables that > look like this: > artists(id,name) > albums(id,name) > artists_albums(album_id,artist_id) > > any idea what''s the fastest query to do this? > > thanx in advance > > PatWell, for starters, you probably want albums_artists if you intend this to be a has_and_belongs_to_many table since "albums" comes before "artists" rename artists to old_artists rename albums to old_albums insert into artists select * from old_artists insert into albums select id, album_name as name from old_albums insert into albums_artists select id as album_id, artist_id from old_albums then if all your test pass ;-) you can drop the old_* tables You didn''t say what database so I''m leaving this generic. (and migrations are great for this sort of thing, too) -Rob Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Patrick Aljord
2006-Dec-07 03:05 UTC
Re: need to transfer data from old php like db to rails style db
On 12/7/06, Rob Biedenharn <Rob-GBZH0y1GwQfnZcttdmLDtcI/UQi/AW5J@public.gmane.org> wrote:> > On Dec 6, 2006, at 9:42 PM, Patrick Aljord wrote: > > hey all, > > I have two tables like that from an old php project: > > artists(id,name) > > albums(id,artist_id,album_name) > > > > and I need to transfer the data of this database to three tables that > > look like this: > > artists(id,name) > > albums(id,name) > > artists_albums(album_id,artist_id) > > > > any idea what''s the fastest query to do this? > > > > thanx in advance > > > > Pat > > Well, for starters, you probably want albums_artists if you intend > this to be a has_and_belongs_to_many table since "albums" comes > before "artists" > > rename artists to old_artists > rename albums to old_albums > > insert into artists select * from old_artists > insert into albums select id, album_name as name from old_albums > insert into albums_artists select id as album_id, artist_id from > old_albums > > then if all your test pass ;-) you can drop the old_* tables > > You didn''t say what database so I''m leaving this generic. (and > migrations are great for this sort of thing, too) > > -Rob >thanx a lot! --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---