WIP - ActixWeb multi-tenant blog and newsletter API server. Originally forked from LukeMathWalker/zero-to-production.
at main 38 lines 1.1 kB view raw
1#!/usr/bin/env bash 2 3set -x 4set -eo pipefail 5 6if ! [ -x "$(command -v sqlx)" ]; then 7 echo >&2 "Error: sqlx is not installed." 8 echo >&2 "Use:" 9 echo >&2 " cargo install --version='~0.8' sqlx-cli --no-default-features --features rustls,postgres" 10 echo >&2 "to install it." 11 exit 1 12fi 13 14# Check if a custom parameter has been set, otherwise use default values 15APP_DB_NAME="${APP_DB_NAME:=newsletter}" 16APP_USER_PWD="${APP_USER_PWD:=password}" 17APP_USER="${APP_USER:=postgres}" 18DB_HOST="${DB_HOST:=localhost}" 19DB_PORT="${DB_PORT:=5432}" 20 21export PGPASSWORD="${APP_USER_PWD}" 22 23until psql -h "${DB_HOST}" -U "${APP_USER}" -p "${DB_PORT}" -d "postgres" -c '\q'; do 24 echo >&2 "Postgres is still unavailable - sleeping" 25 sleep 1 26done 27 28echo >&2 "Postgres is up and running on port ${DB_PORT} - running migrations now!" 29 30# Create the application database 31DATABASE_URL=postgres://${APP_USER}:${APP_USER_PWD}@${DB_HOST}:${DB_PORT}/${APP_DB_NAME} 32 33export DATABASE_URL 34 35sqlx database create 36sqlx migrate run 37 38echo >&2 "Postgres has been migrated, ready to go!"