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

Riccardo Tacconi rtacconi at gmail.com
Fri Jan 8 03:52:17 PST 2010


Thanks Andrew,

That is realy heplfull and I did not know about acts_as_importable plugin.

On Fri, Jan 8, 2010 at 10:51 AM, Andrew Stewart
<boss at airbladesoftware.com>wrote:

>
> 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).
>


If I use :table_name_prefix => "rails_" I suppose that a table rails_teams
will be defined in Rails as teams, isn't it? Otherwise I cannot see the
utility.


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

Yes I am using the same.


> 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
>
>
>From that plugin I see that there is an easy way to connect to a second
database, different per each environoment:

establish_connection "legacy_#{Rails.env}"





> Regards,
>
> Andy Stewart
> -------
> http://airbladesoftware.com
>
> _______________________________________________
> Chat mailing list
> Chat at lists.lrug.org
> http://lists.lrug.org/listinfo.cgi/chat-lrug.org
>



-- 
Riccardo Tacconi
VIRTUELOGIC LIMITED

http://www.linkedin.com/in/riccardotacconi
http://riccardotacconi.blogspot.com/
http://twitter.com/rtacconi
Linux user: #400461
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lrug.org/pipermail/chat-lrug.org/attachments/20100108/3614aa5b/attachment-0003.html>


More information about the Chat mailing list