Rails: mysql and postgres simultaneously in one application?

Why can you ask? Because I created the application in mysql and you need to start using postgres only for the GIS component of my application. In the end, I will go all the way to postgres, but at the same time I would like to know if this is possible.

+4
source share
2 answers

If, for example, you, in your database.yml, are something like this (don't really remember the correct attributes, but I think you understand):

postgres: adapter: postgres database: gis mysql: adapter: mysql database: app 

Then you can add

 establish_connection :postgres 

in models that should use the Postgres database. Of course, it would be easier to create an abstract class and force all models to use it instead, since it is more DRYer.

 class PostgresRecord::Base < ActiveRecord::Base self.abstract_class = true establish_connection :postgres end 

Or, since you plan to eventually migrate to Postgres, you should probably do the opposite, make the default Postgres database, and change the connection for MySQL.

+10
source

You just have an instance of another ODBC connection with your new Postgres driver to use to create queries. It's all.

-3
source

All Articles