AI Database Silmeye Çalışınca Wrapper Yaptım v2: Read-Only Edition
Son güncelleme
Bu yararlı oldu mu?
Bu yararlı oldu mu?
psql() {
# Bypass flag → bir sonraki komut için kaldır
if [[ -f /tmp/psql_bypass ]]; then
command rm -f /tmp/psql_bypass
command psql "$@"
return
fi
# Temporary psqlrc → SET SESSION read-only
local temp_rc=$(mktemp)
echo "SET SESSION default_transaction_read_only = on;" > "$temp_rc"
local output
local exit_code
output=$(PSQLRC="$temp_rc" command psql "$@" 2>&1)
exit_code=$?
command rm -f "$temp_rc"
echo "$output"
# Read-only hata → instruction bas
# NOTE: exit_code check yapmıyoruz çünkü psql heredoc ile çalıştırıldığında
# connection başarılı = exit_code 0, ama SQL command fail olabilir
if echo "$output" | grep -q "read-only transaction"; then
echo ""
echo "🛑 STOP: DATABASE WRITE OPERATION BLOCKED"
echo "ACTION REQUIRED: Ask user to type '!y' by telling HOW AWARE YOU ARE, then retry this command"
fi
return $exit_code
}
y() {
touch /tmp/psql_bypass
echo "✓ Next psql command approved" >&2
}Claude DROP atar → psql read-only başlar → PostgreSQL reddeder →
Wrapper hatayı yakalar → Claude açıklama yapar → Ben y() ile approve →
psql write mode'da çalışır → Komut execute olur