fix: Add automatic removal of test agents in health check
- Add remove-test-agents.sh script - Integrate test agent removal into db-health-check.sh - Prevents test agents (ag_atlas, ag_oracle, ag_builder, ag_greeter) from reappearing
This commit is contained in:
@@ -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"
|
||||
|
||||
34
scripts/remove-test-agents.sh
Executable file
34
scripts/remove-test-agents.sh
Executable file
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user