Steven Line | 21 May 06:02
Gravatar

Re: two database migration (active record)


Steven Line wrote:
> 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

Here's the definition of :legacy_development in databases.yml:

legacy_development:
  adapter: mysql
  database: hardrockOrig
  username: root
  password: booyah
  socket: /tmp/mysql.sock
--

-- 
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
-~----------~----~----~----~------~----~------~--~---


Gmane