init_database.sh 735 B

12345678910111213141516171819202122232425262728
  1. #!/usr/bin/env bash
  2. set -x
  3. set -eo pipefail
  4. if ! [ -x "$(command -v psql)" ]; then
  5. echo >&2 "Error: `psql` is not installed."
  6. echo >&2 "install using brew: brew install libpq."
  7. echo >&2 "link to /usr/local/bin: brew link --force libpq ail"
  8. exit 1
  9. fi
  10. if ! [ -x "$(command -v sqlx)" ]; then
  11. echo >&2 "Error: `sqlx` is not installed."
  12. echo >&2 "Use:"
  13. echo >&2 " cargo install --version=0.5.5 sqlx-cli --no-default-features --features postgres"
  14. echo >&2 "to install it."
  15. exit 1
  16. fi
  17. until psql -h "localhost" -U "${DB_USER}" -p "${DB_PORT}" -d "postgres" -c '\q';
  18. do
  19. >&2 echo "Postgres is still unavailable - sleeping"
  20. sleep 1
  21. done
  22. >&2 echo "Postgres is up and running on port ${DB_PORT}!"
  23. sqlx database create