21 May 06:00
Re: two database migration (active record)
From: Steven Line <rails-mailing-list@...>
Subject: Re: two database migration (active record)
Newsgroups: gmane.comp.lang.ruby.rails
Date: 2008-05-21 04:00:34 GMT
Subject: Re: two database migration (active record)
Newsgroups: gmane.comp.lang.ruby.rails
Date: 2008-05-21 04:00:34 GMT
Hi Frantisek,
I recently did this. Here is some code, maybe you can figure it out from
this. If not post questions.
# copying data from table named legacy_aid_stations to table
# named aid_stations
def migrate_aid_stations
# connect to legacy table. :legacy_development is defined in
# databases.yml
LegacyAidStation.establish_connection(:legacy_development)
# get all rows from legacy table
@lAidStations = LegacyAidStation.find(:all)
# clear any rows that may be in new table
AidStation.delete_all
@aidStations = Array.new
@lAidStations.each do |l|
aidStation = AidStation.new
# copy fields from legacy object to new object
aidStation.name = l.AidStationName.split(/ /).map {|word|
word.capitalize}.join ' ' # capitalize 1st letter of each word
aidStation.sortOrderCW = l.SortOrderCW
aidStation.sortOrderCCW = l.SortOrderCCW
aidStation.save
@aidStations.push aidStation
end
end
--
--
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@...
To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@...
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
RSS Feed