46 lines
3.1 KiB
Bash
Executable File
46 lines
3.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Setzt die nexarch-Testumgebung zurueck: loescht die geteilte
|
|
# Registry-Tabelle "tenants" in der postgres-Wartungsdatenbank sowie alle
|
|
# tenant_*-Datenbanken. Noetig, weil verschiedene Feature-Branches
|
|
# unterschiedliche Registry-Schemata erwarten, aber dieselbe physische
|
|
# Postgres-Instanz auf dem Testhost teilen (siehe [[project-nexarch-test-infra]]).
|
|
#
|
|
# Aufruf: NEXARCH_TEST_DB_PASSWORD=... ./scripts/reset-test-env.sh
|
|
set -euo pipefail
|
|
|
|
PASS="${NEXARCH_TEST_DB_PASSWORD:?Setze NEXARCH_TEST_DB_PASSWORD vor dem Aufruf}"
|
|
ROLE="nexarch_test"
|
|
|
|
export PGPASSWORD="$PASS"
|
|
|
|
# Alle Registry-Tabellen, die von migrations/*.up.sql angelegt werden -
|
|
# inklusive der Tabellen mit FK-Bezug auf tenants (tenant_keks). "DROP TABLE
|
|
# tenants CASCADE" entfernt lediglich die FK-CONSTRAINT auf einer
|
|
# referenzierenden Tabelle, NICHT deren Zeilen - ohne den expliziten Drop
|
|
# hier ueberleben verwaiste tenant_keks-Zeilen jeden Reset und verfaelschen
|
|
# spaetere Testlaeufe (QA-04-Befund: internal/pentest kollidierte mit
|
|
# Altzeilen aus fruehreren internal/kek-Testlaeufen).
|
|
psql -h localhost -U "$ROLE" -d postgres -v ON_ERROR_STOP=1 -c "DROP TABLE IF EXISTS tenant_keks CASCADE;"
|
|
psql -h localhost -U "$ROLE" -d postgres -v ON_ERROR_STOP=1 -c "DROP TABLE IF EXISTS tenant_settings_history CASCADE;"
|
|
psql -h localhost -U "$ROLE" -d postgres -v ON_ERROR_STOP=1 -c "DROP TABLE IF EXISTS tenant_settings CASCADE;"
|
|
psql -h localhost -U "$ROLE" -d postgres -v ON_ERROR_STOP=1 -c "DROP TABLE IF EXISTS tenants CASCADE;"
|
|
psql -h localhost -U "$ROLE" -d postgres -v ON_ERROR_STOP=1 -c "DROP TABLE IF EXISTS superadmins CASCADE;"
|
|
psql -h localhost -U "$ROLE" -d postgres -v ON_ERROR_STOP=1 -c "DROP TABLE IF EXISTS rate_limit_counters CASCADE;"
|
|
psql -h localhost -U "$ROLE" -d postgres -v ON_ERROR_STOP=1 -c "DROP TABLE IF EXISTS rate_limit_configs CASCADE;"
|
|
psql -h localhost -U "$ROLE" -d postgres -v ON_ERROR_STOP=1 -c "DROP TABLE IF EXISTS policy_rule_changes CASCADE;"
|
|
psql -h localhost -U "$ROLE" -d postgres -v ON_ERROR_STOP=1 -c "DROP TABLE IF EXISTS policy_rules CASCADE;"
|
|
psql -h localhost -U "$ROLE" -d postgres -v ON_ERROR_STOP=1 -c "DROP TABLE IF EXISTS feature_flags CASCADE;"
|
|
psql -h localhost -U "$ROLE" -d postgres -v ON_ERROR_STOP=1 -c "DROP TABLE IF EXISTS module_credentials CASCADE;"
|
|
psql -h localhost -U "$ROLE" -d postgres -v ON_ERROR_STOP=1 -c "DROP TABLE IF EXISTS modules CASCADE;"
|
|
psql -h localhost -U "$ROLE" -d postgres -v ON_ERROR_STOP=1 -c "DROP TABLE IF EXISTS usage_quotas CASCADE;"
|
|
psql -h localhost -U "$ROLE" -d postgres -v ON_ERROR_STOP=1 -c "DROP TABLE IF EXISTS usage_counters CASCADE;"
|
|
psql -h localhost -U "$ROLE" -d postgres -v ON_ERROR_STOP=1 -c "DROP TABLE IF EXISTS tenant_licenses CASCADE;"
|
|
psql -h localhost -U "$ROLE" -d postgres -v ON_ERROR_STOP=1 -c "DROP TABLE IF EXISTS audit_events CASCADE;"
|
|
|
|
dbs=$(psql -h localhost -U "$ROLE" -d postgres -tAc "SELECT datname FROM pg_database WHERE datname LIKE 'tenant\_%' ESCAPE '\'")
|
|
for db in $dbs; do
|
|
psql -h localhost -U "$ROLE" -d postgres -v ON_ERROR_STOP=1 -c "DROP DATABASE IF EXISTS \"${db}\";"
|
|
done
|
|
|
|
echo "Testumgebung zurueckgesetzt: registry-tabelle + $(echo "$dbs" | grep -c . || true) tenant-datenbank(en) entfernt."
|