golang-template/scripts/reset-db.sh

19 lines
618 B
Bash
Executable file

#!/usr/bin/env bash
# Reset the Postgres database configured in .env: drop all its content, then
# reapply migrations from scratch.
# Usage: ./scripts/reset-db.sh
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
set -a
# shellcheck disable=SC1091
source "$SCRIPT_DIR/../.env"
set +a
DBSTRING="${GOOSE_DBSTRING:-postgres://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_NAME}?sslmode=${DB_SSL_MODE}}"
echo "Dropping and recreating schema public on ${DB_NAME}..."
psql "$DBSTRING" -v ON_ERROR_STOP=1 -c "DROP SCHEMA public CASCADE; CREATE SCHEMA public;"
"$SCRIPT_DIR/goose.sh" up