Frantisek Psotka | 17 May 12:18

two database migration (active record)


Hello.

I want to write script, that will migrate one database (with models) to
another database (with another models) using ActiveRecord and all of its
benefits. It is possible? Please give me any tips.

I am moving database form old app to new one. It would be great to use
ActiveRecord for this complex task.

Thank you.

rndrfero
--

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

Phlip | 17 May 15:22

Re: two database migration (active record)


> I want to write script, that will migrate one database (with models) to
> another database (with another models) using ActiveRecord and all of its
> benefits. It is possible? Please give me any tips.
>
> I am moving database form old app to new one. It would be great to use
> ActiveRecord for this complex task.

An important rule of programming is to always be as incremental as possible. 
The bigger a change you make, the higher the risks go.

If you want to deliver new features to a client, as soon as possible, leave 
the data in the old database, and hook up to them using ActiveRecord's 
system to set your models' table names, primary keys, etc.

The book /Rails Recipes/ lists these techniques under "Integrating with 
Legacy Database".

Don't make the mountain come to Mohammed, if Mohammed can just go to the 
mountain!

Over time, when you need new tables, or if you find occassion to refactor 
the existing tables, you can rename them closer to ActiveRecord's notorious 
opinions. 

--~--~---------~--~----~------------~-------~--~----~
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
(Continue reading)

Steven Line | 21 May 06:00

Re: two database migration (active record)


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
(Continue reading)

Steven Line | 21 May 06:02

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
> 
(Continue reading)


Gmane