#!/usr/bin/env bash
# Serrure du migration-warden (hook PreToolUse Bash) : bloque le DDL destructif
# qu'un agent tenterait d'exécuter. La politique vit dans le prompt de l'agent,
# la garantie vit ici. Exit 2 = refus (Claude Code bloque l'appel).
set -euo pipefail

input="$(cat)"

if printf '%s' "$input" | grep -qiE 'DROP[[:space:]]+(TABLE|DATABASE|SCHEMA|COLUMN)|TRUNCATE[[:space:]]|ALTER[[:space:]]+TABLE[^;]*DROP[[:space:]]+COLUMN|db_reset|db:reset'; then
  echo "migration-warden : DDL destructif ou reset bloqué par hook. Ce garde-fou lit et juge, il n'exécute pas. Utilise 'alembic upgrade --sql' (dry-run) pour inspecter le SQL." >&2
  exit 2
fi

exit 0
