Guitars

Running Alpas app Migrations on a free tier Heroku Server

Jun 17, 2020

So you have built an Alpas app and followed these steps to deploy to Heroku but you are having issues running migrations. These additional steps should help you run the migrations as well as any other Alpas task you need on Heroku, especially the free tier.

Initial Fixes

When running heroku run ./alpas db:migrate you may find that the migration exits too early because the dyno capacity on the free tier has been maxed out. If this happens try making a trivial change to your project to force a new deploy (with the Heroku web process set to 0), navigate to App > More > Restart All Dynos to reset the box. Then try to run the migration command.

Alternatively try App > More > Restart All Dynos followed by heroku ps:scale web=0 to ensure that the app is not running when trying to run a migration.

Migrating with the Compiled Project

If the problem persists, you will need to run the db:migrate command on the compiled jar file. The normal alpas script recompiles the entire project before running the migration which likely requires too much RAM for the lower/free tier dynos on Heroku.

  1. Create a new file called alpas_prod.sh in the root of your project. This can be called anything but if you name it differently just apply that consistently to the next steps.
  2. Copy and paste in the contents of this sample file into your alpas_prod.sh file. This is very similar to the original alpas script but runs against the already compiled jar file rather than using gradle commands which recompile the project. Be sure to rename the jar file reference in the script to your project’s jar file after copying over.
  3. As per the original alpas script, make sure this new file has executable rights with chmod +x ./alpas_prod.sh
  4. Commit your changes then step through the migration process in the previous post, substituting heroku run ./alpas_prod.sh db:migrate in for the migration command.

You should see now that the migration happens without the need to recompile and successfully executes!