This is a simplified, but fairly thorough, set of scripts and configuration to enable Heroku Release Phase for Rails apps.
Further, this particular set up plays nicely with Heroku Review Apps in that the release
phase script will:
- Fail, loudly, if the DB does not yet exist.
- Load the DB schema if the current schema version (as determined by
bin/rails db:version
) is0
. - Run DB migrations otherwise.
For a "normal" app that usually means it will run the DB migrations.
For a Review App, on the first deploy the release
phase will bin/rails db:schema:load
.
And then the postdeploy
script will seed data.
During subsequent deploys to the Review App, the release
phase will bin/rails db:migrate
.
So about the why: We are running a home automation platform (apilio.com), and we face the challenge of having to expose parts of the functionality to the public, while wanting to keep other parts restricted to certain sources to protect them from attacks.
Due to some restrictions of Heroku, we came up with an architecture that involves having two instances of the same app running as separate applications (so it's not one application scaled up, but two separate applications).
I think of the possible solutions (probably all with caution):