dimanche 2 août 2015

Rails - same model with multiple databases (read only)

I have multiple databases, with the same tables and columns names inside (but different unique ids and rows..). Instead of having one huge database with all the rows, it is splitted into different databases. This is something I cannot change (you can think of this as collecting the same data from different countries, but each country has its own database). These databases are "read only" - meaning, when I use them via Rails, it is only to display the data (or save it on a local database) - I do not change the data on any of the remote databases.

My problem is, that I need to have 1 model in rails, that collects the data from all these databases. We want to be able to do something like:

OneBigDB.select_where(...)

and not to split each search to:

data1 = FirstDB.select_where(same_condition)
data2 = SecondDB.select_where(same_condition)
...
data = data1 + data2 + ...

Is there any way to do so? As we do not change any of these databases, and each row has a unique id, there shouldn't be any problem to get the data from different databases and join it together...

Thanks!

Aucun commentaire:

Enregistrer un commentaire