commit 0016c1a0cda56af65eb7c5a558bdb2f7fd198851 parent d114e61d1c5aaad8e51002bb77c1b8053b87f759 Author: Henrique Chan Carvalho Machado <henriqueccmachado@tecnico.ulisboa.pt> Date: Mon, 3 Nov 2025 23:09:02 +0100 oauth2_gateway: add db teardown script Diffstat:
| A | oauth2_gateway/scripts/teardown_test_db.sh | | | 40 | ++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 40 insertions(+), 0 deletions(-)
diff --git a/oauth2_gateway/scripts/teardown_test_db.sh b/oauth2_gateway/scripts/teardown_test_db.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +DB_PORT=5432 +DB_NAME=oauth2gw +DB_USER=oauth2gw +DB_ADMIN=${DB_ADMIN:-} + +echo "Tearing down OAuth2 Gateway test database..." +echo +echo "WARNING: This will destroy all data!" +echo + +if ! command -v psql &> /dev/null +then + echo "psql could not be found, please install PostgreSQL first." + exit 1 +fi + +if ! pg_isready -h localhost -p "$DB_PORT" >/dev/null 2>&1; then + echo "PostgreSQL is not running." + exit 1 +fi + +PSQL_CMD="psql -h localhost -p $DB_PORT" +if [ -n "$DB_ADMIN" ]; then + PSQL_CMD="$PSQL_CMD -U $DB_ADMIN" +fi + +echo "Dropping oauth2gw schema and unregistering all patches..." +MIGRATIONS_DIR="$(dirname "$0")/../migrations" +$PSQL_CMD -d "$DB_NAME" -f "$MIGRATIONS_DIR/drop.sql" + +echo +echo "Teardown completed." +echo +echo "Schema dropped. Database '$DB_NAME' still exists but is empty." +echo "Run scripts/setup_test_db.sh to rebuild schema." +echo +echo "To completely remove the database, run:" +echo " psql -h localhost -p $DB_PORT -d postgres -c \"DROP DATABASE $DB_NAME;\""