diff --git a/scripts/db-health-check.sh b/scripts/db-health-check.sh index e5c24f26..bea82049 100755 --- a/scripts/db-health-check.sh +++ b/scripts/db-health-check.sh @@ -65,6 +65,15 @@ if [ "$MICRODAO_COUNT" -eq 0 ]; then log "๐Ÿ’ก Consider restoring from backup: /opt/microdao-daarion/db_backups/" fi +# Remove test agents (they should never exist) +log "๐Ÿงน Checking for test agents..." +TEST_AGENT_COUNT=$(docker exec daarion-postgres psql -U postgres -d daarion -t -c "SELECT COUNT(*) FROM agents WHERE id IN ('ag_atlas', 'ag_oracle', 'ag_builder', 'ag_greeter');" 2>/dev/null | tr -d ' ' || echo "0") +if [ "$TEST_AGENT_COUNT" -gt 0 ]; then + log "โš ๏ธ Found $TEST_AGENT_COUNT test agents, removing..." + docker exec daarion-postgres psql -U postgres -d daarion -c "DELETE FROM agents WHERE id IN ('ag_atlas', 'ag_oracle', 'ag_builder', 'ag_greeter');" 2>&1 | grep -v "DELETE\|^$" || true + log "โœ… Test agents removed" +fi + # Check volume persistence VOLUME_SIZE=$(du -sh /var/lib/docker/volumes/daarion_pgdata/_data/ 2>/dev/null | awk '{print $1}' || echo "unknown") log "๐Ÿ“ฆ Database volume size: $VOLUME_SIZE" diff --git a/scripts/remove-test-agents.sh b/scripts/remove-test-agents.sh new file mode 100755 index 00000000..5c5bd32d --- /dev/null +++ b/scripts/remove-test-agents.sh @@ -0,0 +1,34 @@ +#!/bin/bash +# Remove test agents that should not exist +# Run this script after migrations or when test agents appear + +set -e + +echo "๐Ÿงน Removing test agents..." + +# Database connection +DATABASE_URL="${DATABASE_URL:-postgresql://postgres:postgres@localhost:5432/daarion}" + +# Test agent IDs that should never exist +TEST_AGENT_IDS=("ag_atlas" "ag_oracle" "ag_builder" "ag_greeter") + +# Delete test agents +for agent_id in "${TEST_AGENT_IDS[@]}"; do + echo " Checking for: $agent_id" + docker exec daarion-postgres psql -U postgres -d daarion -c \ + "DELETE FROM agents WHERE id = '$agent_id';" 2>&1 | grep -E "DELETE|0" || true +done + +echo "โœ… Test agents removed" + +# Verify +COUNT=$(docker exec daarion-postgres psql -U postgres -d daarion -t -c \ + "SELECT COUNT(*) FROM agents WHERE id IN ('ag_atlas', 'ag_oracle', 'ag_builder', 'ag_greeter');" 2>&1 | tr -d ' ') + +if [ "$COUNT" -eq 0 ]; then + echo "โœ… No test agents found" +else + echo "โš ๏ธ Warning: $COUNT test agents still exist" + exit 1 +fi +