title: How to use a different database for Heroku review apps?
body: <p>I have a deployment pipeline on Heroku which recently started using review apps. This means I have an app - let's call it CI-APP -- which is being created from the master branch.</p>
  
  <p>Every time a pull request is made, a review app is created. We are using Django in our project and so I also added the <code>migrate</code> command to the <code>release</code> phase in the project, so that database migrations can be done automatically.</p>
  
  <p>Today, a coworker submitted a pull request which contained some database changes. The problem is that the migration was ran, and since review apps seem to be using <em>the same database</em> as the app they are suppose to merge to, the migration was applied and now my app CI-APP stopped working...since the code base no longer matches the database structure.</p>
  
  <p>I searched a lot about how to use <em>completely different databases</em> for the review apps compared to the parent app, but to no avail (there are some resources mentioning how you can copy db contents, but that is not what I need).</p>
  
  <p>Any suggestion ?</p>
  
  <p><em>Update</em></p>
  
  <p>Ok, so it seems that Heroku does create a new database for the review app, however: the review app copies all of its environment variables from the parent, including the DATABASE_URL (this seems to be the only way to actually create the review app : <a href="https://s3.amazonaws.com/heroku-devcenter-files/article-images/1461071037-initial_set_up_review_apps.png" rel="nofollow noreferrer">https://s3.amazonaws.com/heroku-devcenter-files/article-images/1461071037-initial_set_up_review_apps.png</a>)</p>
  
  <p>I think I can do some black magic in the postdeploy script, but since the database generated url can be something such as HEROKU_POSTGRESQL_{color}_URL, I am not sure how to find it ....</p>