Database Migrations on Secondary Database on Heroku

184 Views Asked by At

Our company acquired an application from another company, so I'm a little unfamiliar with how they may have done this in the past. Currently there are two applications in Heroku. A production and staging app. Below is the basic app setup for clarity.

Production App
   WHITE // Primary database
   BLACK // Secondary database linked to Staging App

Staging App
   // No databases

Staging application has Config Vars that point to BLACK database URL.

I am trying to run heroku run rake db:migrate on our staging app, but noticed the database is linked to a secondary production BLACK database.

If I run

$ heroku run rake db:migrate -a production

It will update the primary WHITE database in production, but I want to test on the secondary BLACK database first.

If I run

$ heroku run rake db:migrate -a staging

I get the following error

Error: You must install at least one postgresql-client-<version> package.
rake aborted!
Error dumping database
...
Tasks: TOP => db:structure:dump
(See full trace by running task with --trace)

How can I target the secondary BLACK database with a rake command?

2

There are 2 best solutions below

0
On BEST ANSWER

Working with Heroku support, I was not able to get this to work with the current configuration. So in the end I decided to create a database for our staging app. Imported the latest dump file from production. And ran heroku run rake db:migrate against staging.

I still got the same error from my original post (see original question). But when I checked the staging database, the schema was updated correctly. Heroku pointed me to the following Stackoverflow discussion, which seems to indicate this may be a Rails 3 bug.

Below solution for clarity:

Production App
  WHITE // Primary database
  BLACK // Deleted

Staging App
  Gray // Primary database
1
On

Check your Gemfile to make sure your database driver psql isn't in a production only block.