PJSCopeland
PJSCopeland

Reputation: 3006

Specify Postgres version in ActiveRecord config

I have multiple versions of PostgreSQL running on my machine (running Ubuntu Trusty).

$ service postgresql status
9.1/main (port 5433): online
9.5/main (port 5432): online

I am running several Ruby apps with ActiveRecord, that are each using different versions of Postgres, and I want to be able to specify the Postgres version in database.yml, something like this:

default: &default
  adapter: postgresql
  encoding: utf8
  version: 9.1
  # ... or, since this seems to be close to pg_wrapper's syntax:
  cluster: 9.1/main

What I don't want to have to do is specify port: 5433, since that's likely to be different for each version on each machine it's running on. Is there a way to do this?

Upvotes: 2

Views: 2373

Answers (1)

mu is too short
mu is too short

Reputation: 434585

You can put environment variables in your database.yml using a bit of ERB:

default: &default
  adapter: postgresql
  encoding: utf8
  port: <%= ENV['POSTGRESQL_91_PORT'] %>

That way your database.yml files are the same on your various machines and you just need to set up some machine-specific environment settings.

Upvotes: 2

Related Questions