Gesamtprojekt: Skript fuer frische Migrationen aller Module in Wegwerf-DBs
CI / Web-Barrierefreiheitspruefung (axe, Tastatur, Reflow, Textabstaende) (push) Canceled after 0s
CI / Core-Modul (Build/Vet/Test) (push) Canceled after 0s
CI / DMS Security-Test-Gate (AC5, Merge-Gate) (push) Canceled after 0s
CI / DMS-Modul (Lint/Build/Test/Coverage/Artefakt) (push) Canceled after 0s
CI / DMS-Modul Supply-Chain-Scan (govulncheck) (push) Canceled after 0s
CI / Web (dms-browser) (push) Canceled after 0s
CI / Web (pdf-viewer) (push) Canceled after 0s
CI / Web (shl) (push) Canceled after 0s

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
patrickandClaude Sonnet 5 committed 2026-09-21 23:30:18 +02:00
1 parent 03c5de8ab8
commit 55b267350b
1 file changed
+57
+57
View File
@@ -0,0 +1,57 @@
#!/usr/bin/env bash
# Gesamtprojekt: alle Migrationen frisch von null in Wegwerf-Datenbanken.
# Core Registry -> eigene DB
# Core Mandant + DMS + Archive + Mail (Postgres) -> gemeinsame Mandanten-DB, ohne Tabellenkollision
# Jede Migration je Modul in Dateinamen-Reihenfolge. Nur im Wegwerf-Cluster (Port 5433); die
# temporaeren Datenbanken werden am Ende entfernt.
# Voraussetzung: TEST_TENANT_DSN_B zeigt auf den Wegwerf-Cluster und darf Datenbanken anlegen.
set -euo pipefail
root=$(cd "$(dirname "$0")/.." && pwd)
: "${TEST_TENANT_DSN_B:?TEST_TENANT_DSN_B nicht gesetzt}"
if [[ "$TEST_TENANT_DSN_B" != *:5433/* ]]; then
echo "abgebrochen: die Datenbank muss im Wegwerf-Cluster auf Port 5433 liegen" >&2
exit 2
fi
withdb() { python3 - "$TEST_TENANT_DSN_B" "$1" <<'PY'
import sys
from urllib.parse import urlsplit, urlunsplit
u = urlsplit(sys.argv[1])
print(urlunsplit((u.scheme, u.netloc, "/" + sys.argv[2], u.query, u.fragment)))
PY
}
admin=$(withdb postgres)
reg_db="migfresh_reg_$$"
ten_db="migfresh_ten_$$"
cleanup() {
for d in "$reg_db" "$ten_db"; do psql "$admin" -q -c "DROP DATABASE IF EXISTS $d WITH (FORCE)" >/dev/null 2>&1 || true; done
}
trap cleanup EXIT
apply() { # dsn label file...
local dsn=$1 label=$2 n=0; shift 2
for f in "$@"; do
psql "$dsn" -v ON_ERROR_STOP=1 -q -f "$f" >/dev/null 2>"$root/.migfresh.err" || { echo "FAIL $label: $f"; cat "$root/.migfresh.err"; rm -f "$root/.migfresh.err"; exit 1; }
n=$((n + 1))
done
rm -f "$root/.migfresh.err"
echo "PASS $label: $n Migrationen"
}
psql "$admin" -v ON_ERROR_STOP=1 -q -c "CREATE DATABASE $reg_db" -c "CREATE DATABASE $ten_db"
reg=$(withdb "$reg_db")
ten=$(withdb "$ten_db")
psql "$reg" -q -c "CREATE EXTENSION IF NOT EXISTS pgcrypto" >/dev/null
psql "$ten" -q -c "CREATE EXTENSION IF NOT EXISTS pgcrypto" >/dev/null
apply "$reg" "Core Registry" $(ls "$root"/migrations/*.up.sql | sort)
apply "$ten" "Core Mandant" $(ls "$root"/migrations/tenant/*.up.sql | sort)
apply "$ten" "DMS" $(ls "$root"/dms/migrations/tenant/*.up.sql | sort)
apply "$ten" "Archive" $(ls "$root"/archive/migrations/*.up.sql | sort)
mail_files=$(find "$root/mail/internal" -path '*/migrations/*.sql' -not -path '*/search/*' | sort)
apply "$ten" "Mail (Postgres)" $mail_files
tables=$(psql "$ten" -Atc "select count(*) from information_schema.tables where table_schema='public' and table_type='BASE TABLE'")
echo "Tabellen in der gemeinsamen Mandanten-DB: $tables"
echo "MIGRATIONEN BESTANDEN"