#!/bin/bash # Test NOTIFY functionality for Wave 71 Agent 7 # This script demonstrates the hot-reload configuration management set -e PGPASSWORD=foxhunt_dev_password export PGPASSWORD echo "=== Testing PostgreSQL NOTIFY Functionality ===" echo "" # Test 1: Config settings change notification echo "Test 1: Config Settings Change Notification" echo "--------------------------------------------" echo "Simulating config update..." psql -h localhost -U foxhunt -d foxhunt << 'EOF' -- Update a configuration value UPDATE config_settings SET config_value = '"160000"'::jsonb WHERE config_key LIKE '%daily_loss%' LIMIT 1 RETURNING config_key, config_value, updated_at; EOF echo "" echo "✅ Config update executed - NOTIFY sent to config_changed_* channels" echo "" # Test 2: Permission change notification echo "Test 2: Permission Change Notification" echo "---------------------------------------" echo "Simulating role permission update..." psql -h localhost -U foxhunt -d foxhunt << 'EOF' -- Create a test role assignment DELETE FROM user_roles WHERE user_id = (SELECT id FROM users WHERE username = 'test_trader') AND role_id = (SELECT id FROM roles WHERE name = 'trader'); INSERT INTO user_roles (user_id, role_id) SELECT (SELECT id FROM users WHERE username = 'test_trader'), (SELECT id FROM roles WHERE name = 'trader') RETURNING user_id, role_id, created_at; EOF echo "" echo "✅ Permission update executed - NOTIFY sent to permissions_changed channel" echo "" # Test 3: Verify trigger functions echo "Test 3: Verify NOTIFY Trigger Functions" echo "----------------------------------------" psql -h localhost -U foxhunt -d foxhunt << 'EOF' SELECT p.proname as function_name, pg_get_functiondef(p.oid) LIKE '%pg_notify%' as has_notify FROM pg_proc p WHERE p.proname LIKE '%notify%' ORDER BY p.proname; EOF echo "" echo "=== NOTIFY Functionality Test Complete ===" echo "" echo "To manually test NOTIFY in two terminals:" echo " Terminal 1: PGPASSWORD=foxhunt_dev_password psql -h localhost -U foxhunt -d foxhunt -c \"LISTEN permissions_changed;\"" echo " Terminal 2: PGPASSWORD=foxhunt_dev_password psql -h localhost -U foxhunt -d foxhunt -c \"INSERT INTO user_roles (user_id, role_id) SELECT (SELECT id FROM users WHERE username = 'test_trader'), (SELECT id FROM roles WHERE name = 'analyst');\"" echo ""