Files
breakpilot-compliance/scripts/apply_consent_history_migration.sh
Benjamin Admin 393eab6acd
All checks were successful
CI / go-lint (push) Has been skipped
CI / python-lint (push) Has been skipped
CI / nodejs-lint (push) Has been skipped
CI / test-go-ai-compliance (push) Successful in 36s
CI / test-python-backend-compliance (push) Successful in 31s
CI / test-python-document-crawler (push) Successful in 23s
CI / test-python-dsms-gateway (push) Successful in 18s
feat: Package 4 Nachbesserungen — History-Tracking, Pagination, Frontend-Fixes
Backend:
- Migration 009: compliance_einwilligungen_consent_history Tabelle
- EinwilligungenConsentHistoryDB Modell (consent_id, action, version, ip, ua, source)
- _record_history() Helper: automatisch bei POST /consents (granted) + PUT /revoke (revoked)
- GET /consents/{id}/history Endpoint (vor revoke platziert für korrektes Routing)
- GET /consents: history-Array pro Eintrag (inline Sub-Query)
- 5 neue Tests (TestConsentHistoryTracking) — 32/32 bestanden

Frontend:
- consent/route.ts: limit+offset aus Frontend-Request weitergeleitet, total-Feld ergänzt
- Neuer Proxy consent/[id]/history/route.ts für GET /consents/{id}/history
- page.tsx: globalStats state + loadStats() (Backend /consents/stats für globale Zahlen)
- page.tsx: Stats-Kacheln auf globalStats umgestellt (nicht mehr page-relativ)
- page.tsx: history-Mapper: created_at→timestamp, consent_version→version
- page.tsx: loadStats() bei Mount + nach Revoke

Dokumentation:
- Developer Portal: neue API-Docs-Seite /api/einwilligungen (Consent + Legal Docs + Cookie Banner)
- developer-portal/app/api/page.tsx: Consent Management Abschnitt
- MkDocs: History-Endpoint, Pagination-Abschnitt, History-Tracking Abschnitt
- Deploy-Skript: scripts/apply_consent_history_migration.sh

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-03 11:54:25 +01:00

52 lines
1.8 KiB
Bash

#!/bin/bash
# Apply Consent History migration and rebuild backend-compliance on Mac Mini
# Usage: bash scripts/apply_consent_history_migration.sh
set -e
DOCKER="/usr/local/bin/docker"
BACKEND_CONTAINER="bp-compliance-backend"
PROJECT_DIR="/Users/benjaminadmin/Projekte/breakpilot-compliance"
echo "==> Pushing code to Mac Mini..."
git push origin main && git push gitea main
echo "==> Pulling code on Mac Mini..."
ssh macmini "git -C ${PROJECT_DIR} pull --no-rebase origin main"
echo "==> Applying Consent History migration (009_consent_history.sql)..."
ssh macmini "${DOCKER} exec ${BACKEND_CONTAINER} \
psql \"\${DATABASE_URL}\" -f /app/migrations/009_consent_history.sql \
&& echo 'Consent History migration applied' \
|| echo 'psql failed, trying python...'"
ssh macmini "${DOCKER} exec ${BACKEND_CONTAINER} \
python3 -c \"
import psycopg2, os
conn = psycopg2.connect(os.environ['DATABASE_URL'])
conn.autocommit = True
cur = conn.cursor()
with open('/app/migrations/009_consent_history.sql', 'r') as f:
sql = f.read()
cur.execute(sql)
cur.close()
conn.close()
print('Consent History migration (python) applied')
\"" 2>/dev/null || echo "Note: Migration already applied or use manual SQL."
echo ""
echo "==> Rebuilding backend-compliance..."
ssh macmini "${DOCKER} compose -f ${PROJECT_DIR}/docker-compose.yml build --no-cache backend-compliance && \
${DOCKER} compose -f ${PROJECT_DIR}/docker-compose.yml up -d backend-compliance"
echo ""
echo "==> Verifying history endpoint..."
sleep 5
curl -sk "https://macmini:8002/api/compliance/einwilligungen/consents/test/history" \
-H "X-Tenant-ID: test-tenant" \
| python3 -c "import sys,json; d=json.load(sys.stdin); print(f'History endpoint OK: {type(d).__name__}')" \
|| echo "Endpoint check needs backend restart"
echo ""
echo "Done. Check logs: ssh macmini '${DOCKER} logs -f ${BACKEND_CONTAINER}'"