[Ruby] Converting mysql to postgres

Corey Jewett ml at syntheticplayground.com
Mon Aug 14 20:46:38 PDT 2006


On Aug 12, 2006, at 6:48 PM, Ryan Davis wrote:

>
> On Aug 6, 2006, at 9:56 PM, Corey Jewett wrote:
>> On Aug 6, 2006, at 3:19 PM, Ryan Davis wrote:
>>> Easier would also be to use rails... Why would Og be a good idea for
>>> this? I've not used it so maybe I'm missing something.
>> Because you can't have the same set of models simultaneously point at
>> 2 different databases with Rails. Otherwise, yeah ActiveRecord would
>> solve the problem better.
>
> Hrm... I'm not convinced. Simultaneous connections is a false
> requirement. I think you could migrate via active record directly
> just fine. You just have to call establish_connection to switch dbs.

I'm not going to belabor the point because I don't have time to write  
the code. Maybe you just know a hell of a lot more about Rails  
internals than I do, but it seems that if you establish connection,  
then it forgets the old one. So do you have to run through all the  
columns in a model and then switch the connection. I presume that  
anything less means that lazy loading will fail as it goes to the new  
connection, instead of the old. Again I haven't written the code to  
prove this assumption.

I did, however, have a nightmare of a time (1+ solid week wasted)  
with trying to join 2 schema spaces using the establish_connection  
strategy in Rails Recipes. Eventually, I just added a bit of code to  
all my models (because my meta-fu was weeaak at that time) that sets  
the table name to <schema_name_derived_from_RAILS_ENV>.<table_name>.  
Works great.

> Either that, or you use YAML to dump your data as fixtures and load
> them into the new environment.

That would certainly work. Probably a lot less code than doing the Og  
thing, and you get a nice big set of test suite data as a bonus. ;)

Corey




More information about the Ruby mailing list