Last Updated: November 06, 2018
·
730
· naohiro

How to copy staging data to review app on heroku postgres

I ran into this problem as I was setting up the review app on heroku.
I do have enough seed file to run app, but not enough to run all tests.

Here is how I solved with postdeploy script in app.json

{
  "name": "test_app",
  "scripts": {
    "postdeploy": "pg_dump $STAGING_DATABASE_URL | psql $DATABASE_URL && bundle exec rake db:migrate"
  },
  "env": {
    "STAGING_DATABASE_URL": {
      "required": true
    },
  }
  "addons": [
    "heroku-postgresql",
   ],
  "buildpacks": [
    {
      "url": "heroku/ruby"
    }
  ]
}

NOTE: You need to set STAGING_DATABASE_URL in parent app first