[LRUG] Multiple databases, migration, integration...

Andrew Stewart boss at airbladesoftware.com
Fri Jan 8 02:51:26 PST 2010


On 8 Jan 2010, at 10:33, Riccardo Tacconi wrote:
> Yesterday I decided to refactor a page developed in PHP with Rails.  
> I am using two MySql databases, one for the PHP, one for Rails. Now  
> I am not sure if I should use only one database or two. The DB for  
> PHP has name in the singular form (dept, user, article...), the  
> primary keys are something like 'deptID', 'user_id', in few words is  
> an old rubbish inherited DB.

I am working in a similar situation where I am running an old Mambo  
(PHP) site alongside a new Rails site, while slowly moving  
functionality from the former to the latter.

I have a single MySQL database containing both the PHP system's tables  
and the Rails app's tables.  This way I only need to connect to a  
single database, which is the way Rails likes it.  To avoid table name  
clashes I prefixed all the Rails app's tables with a simple prefix,  
configuring ActiveRecord appropriately (c.f. the table_name_prefix  
method).

Have a class for each PHP table you need to use, and use  
ActiveRecord's table_name and primary_key methods to cope with the old  
table names.  I do this and it all works perfectly.

When I want to move functionality and data from PHP-land to Rails- 
land, I use Tim Riley's marvellous acts_as_importable plugin.  He came  
up with an excellent pattern for migrating data, and for my system it  
works very well.

http://github.com/timriley/acts-as-importable

Regards,

Andy Stewart
-------
http://airbladesoftware.com




More information about the Chat mailing list