Thanks Andrew,<br><br>That is realy heplfull and I did not know about acts_as_importable plugin. <br><br><div class="gmail_quote">On Fri, Jan 8, 2010 at 10:51 AM, Andrew Stewart <span dir="ltr"><<a href="mailto:boss@airbladesoftware.com">boss@airbladesoftware.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="im"><br>
On 8 Jan 2010, at 10:33, Riccardo Tacconi wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
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.<br>
</blockquote>
<br></div>
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.<br>
<br>
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).<br>
</blockquote><div><br><br>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. <br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
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.<br>
<br></blockquote><div><br><br>Yes I am using the same.<br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
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.<br>
<br>
<a href="http://github.com/timriley/acts-as-importable" target="_blank">http://github.com/timriley/acts-as-importable</a><br>
<br></blockquote><div><br>From that plugin I see that there is an easy way to connect to a second database, different per each environoment:<br><font size="4"><br></font><pre><font size="4"><span class="n">establish_connection</span> <span class="s2">"legacy_</span><span class="si">#{</span><span class="no">Rails</span><span class="o">.</span><span class="n">env</span><span class="si">}</span><span class="s2">"</span><br>
</font><br></pre><br><br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Regards,<br>
<br>
Andy Stewart<br>
-------<br>
<a href="http://airbladesoftware.com" target="_blank">http://airbladesoftware.com</a><br>
<br>
_______________________________________________<br>
Chat mailing list<br>
<a href="mailto:Chat@lists.lrug.org" target="_blank">Chat@lists.lrug.org</a><br>
<a href="http://lists.lrug.org/listinfo.cgi/chat-lrug.org" target="_blank">http://lists.lrug.org/listinfo.cgi/chat-lrug.org</a><br>
</blockquote></div><br><br clear="all"><br>-- <br>Riccardo Tacconi<br>VIRTUELOGIC LIMITED<br><br><a href="http://www.linkedin.com/in/riccardotacconi">http://www.linkedin.com/in/riccardotacconi</a><br><a href="http://riccardotacconi.blogspot.com/">http://riccardotacconi.blogspot.com/</a><br>
<a href="http://twitter.com/rtacconi">http://twitter.com/rtacconi</a><br>Linux user: #400461<br>