bin/heroku_release
#!/usr/bin/env bash
#
# Usage: bin/heroku_release
#
# Adapted from stevenharman's Gist:
# https://gist.github.com/stevenharman/98576bf49b050b9e59fb26626b7cceff
set -euo pipefail
schema_version=$(bin/rails db:version | { grep "^Current version: [0-9]\\+$" || true; } | tr -s ' ' | cut -d ' ' -f3)
if [ -z "$schema_version" ]; then
printf "š [Release Phase]: Database schema version could not be determined. Does the database exist?\n"
exit 1
fi
if [ "$schema_version" -eq "0" ]; then
printf "\nā³ [Release Phase]: Loading the database schema.\n"
bin/rails db:schema:load
else
printf "\nā³ [Release Phase]: Running database migrations.\n"
bin/rails db:migrate
fi
printf "\nš [Release Phase]: Database is up to date.\n"