JordanHatch/maslow-redux

View on GitHub
bin/heroku_release

Summary

Maintainability
Test Coverage
#!/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"