ADAM
ADAM

Reputation: 3903

Rails: mysql & postgres at the same time in the same app?

Why you may ask? Because i have built the app on mysql and need to start using postgres for GIS component of my app only. Eventually i will migrate to postgres completely but in the mean time would like to know if this is possible

Upvotes: 4

Views: 1548

Answers (2)

Jimmy Stenke
Jimmy Stenke

Reputation: 11220

If for instance you, in your database.yml have something like this (don't really recall the correct attributes, but I think you get the idea):

postgres:
    adapter: postgres
    database: gis

mysql:
    adapter: mysql
    database: app

Then, you could add

establish_connection :postgres 

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

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

Or, since you are planning on migrating to Postgres eventually, you probably should do the opposite, make the Postgres database default and change the connection for the MySQL.

Upvotes: 10

Guillermo
Guillermo

Reputation: 179

You just have con instantiate another ODBC connection with your new Postgres driver an use it to create query's. That's all.

Upvotes: -3

Related Questions