#!/bin/bash # Script to completely reset the database cache and rebuild from scratch # This clears all cached data and triggers a full sync from Jira set -e echo "🔄 Complete Database Reset and Rebuild" echo "======================================" echo "" # Check if backend is running BACKEND_URL="${BACKEND_URL:-http://localhost:3001}" API_URL="${API_URL:-$BACKEND_URL/api}" echo "📡 Checking backend connection..." if ! curl -s -f "$BACKEND_URL/health" > /dev/null 2>&1; then echo "âš ī¸ Backend is not accessible at $BACKEND_URL" echo " Make sure the backend is running and accessible" echo "" read -p "Continue anyway? (yes/no): " confirm if [ "$confirm" != "yes" ]; then echo "❌ Aborted." exit 1 fi fi echo "✅ Backend is accessible" echo "" # Check if we need authentication echo "🔐 Checking authentication..." AUTH_HEADER="" if [ -n "$API_TOKEN" ]; then AUTH_HEADER="-H \"Authorization: Bearer $API_TOKEN\"" echo "✅ Using API token from environment" elif [ -f ".env" ]; then # Try to get token from .env or session echo "â„šī¸ Note: You may need to authenticate via the UI first" echo " Or set API_TOKEN environment variable" fi echo "" # Step 1: Clear all cache echo "đŸ—‘ī¸ Step 1: Clearing all cached data..." CLEAR_RESPONSE=$(curl -s -X DELETE "$API_URL/cache/clear" \ -H "Content-Type: application/json" \ $AUTH_HEADER 2>&1) if echo "$CLEAR_RESPONSE" | grep -q "cleared\|status"; then echo "✅ Cache cleared successfully" else echo "âš ī¸ Clear response: $CLEAR_RESPONSE" echo " This might indicate an authentication issue" echo "" read -p "Continue with sync anyway? (yes/no): " confirm if [ "$confirm" != "yes" ]; then echo "❌ Aborted." exit 1 fi fi echo "" # Step 2: Trigger full sync echo "🔄 Step 2: Triggering full sync from Jira..." SYNC_RESPONSE=$(curl -s -X POST "$API_URL/cache/sync" \ -H "Content-Type: application/json" \ $AUTH_HEADER 2>&1) if echo "$SYNC_RESPONSE" | grep -q "started\|status"; then echo "✅ Full sync started in background" echo "" echo "📊 The sync is running in the background. You can monitor progress:" echo " - Check cache status: curl $API_URL/cache/status" echo " - View backend logs: docker-compose logs -f backend" echo " - Or check the UI: $BACKEND_URL (Settings → Cache Management)" else echo "âš ī¸ Sync response: $SYNC_RESPONSE" echo " This might indicate an authentication issue or missing Jira credentials" fi echo "" echo "✨ Reset and rebuild process initiated!" echo "" echo "Next steps:" echo "1. Monitor sync progress via the UI or API" echo "2. Wait for sync to complete (this may take several minutes)" echo "3. Verify data in the UI or via: curl $API_URL/cache/status" echo ""