12-migrations.sh 933 B

12345678910111213141516171819202122232425262728293031323334
  1. #!/bin/bash
  2. : "${ENTRYPOINT_ROOT:="/docker"}"
  3. # shellcheck source=SCRIPTDIR/../helpers.sh
  4. source "${ENTRYPOINT_ROOT}/helpers.sh"
  5. entrypoint-set-script-name "$0"
  6. # Allow automatic applying of outstanding/new migrations on startup
  7. : "${DB_APPLY_NEW_MIGRATIONS_AUTOMATICALLY:=0}"
  8. # Wait for the database to be ready
  9. await-database-ready
  10. # Detect if we have new migrations
  11. declare -i new_migrations=0
  12. (run-as-runtime-user php artisan migrate:status || :) | grep No && new_migrations=1
  13. if is-true "${new_migrations}"; then
  14. log-info "No outstanding migrations detected"
  15. exit 0
  16. fi
  17. log-warning "New migrations available!"
  18. if is-false "${DB_APPLY_NEW_MIGRATIONS_AUTOMATICALLY}"; then
  19. log-info "Automatic applying of new database migrations is disabled"
  20. log-info "Please set [DB_APPLY_NEW_MIGRATIONS_AUTOMATICALLY=1] in your [.env] file to enable this."
  21. exit 0
  22. fi
  23. run-as-runtime-user php artisan migrate --force