specify database adapter on Heroku

209 views Asked by At

I'm using pgcrypto gem to encrypt data in certain columns of the database, but in order for this gem to work I have to specify pgcrypto as an adapter in database.yml file. I know that Heroku disregards this file and generates its own when application is pushed to Heroku server, which uses default postgresql adapter. Does anybody know if it's possible to override adapter value, with a configuration variable for example?

2

There are 2 answers

0
koss On BEST ANSWER

Eventually found the solution, which happened to be a quite simple one - I just had to replace the first token in the Heroku's database URL variable, so instead of

postgres://username:password@host:port/dbname

I use

pgcrypto://username:password@host:port/dbname

1
John Paul Ashenfelter On

You can manually create a database connection with

`ActiveRecord::Base.establish_connection(config)

you could also do this on a per-model basis using a mixing.

More info is here Understanding how establish_connection works in ActiveRecord