@echo off
REM Check if old database at 172.16.3.20 is accessible

echo ==========================================
echo Checking Old Database (Jupiter 172.16.3.20)
echo ==========================================
echo.

echo [1] Testing connectivity to Jupiter...
plink -batch guru@172.16.3.20 "echo 'Connected successfully'" 2>nul
if errorlevel 1 (
    echo ERROR: Cannot connect to Jupiter ^(172.16.3.20^)
    echo.
    echo Possible issues:
    echo   - Server is down
    echo   - Network issue
    echo   - SSH not accessible
    echo.
    goto :end
)

echo Connected successfully
echo.

echo [2] Checking if MariaDB Docker container is running...
plink -batch guru@172.16.3.20 "docker ps --filter 'name=mariadb' --format '{{.Names}} - {{.Status}}'" 2>nul
echo.

echo [3] Checking database connectivity...
plink -batch guru@172.16.3.20 "docker exec mariadb mysql -u claudetools -pCT_e8fcd5a3952030a79ed6debae6c954ed -D claudetools -e \"SELECT VERSION();\" 2>/dev/null" 2>nul
if errorlevel 1 (
    echo ERROR: Cannot connect to database
    goto :end
)
echo.

echo [4] Checking for conversation_contexts data...
plink -batch guru@172.16.3.20 "docker exec mariadb mysql -u claudetools -pCT_e8fcd5a3952030a79ed6debae6c954ed -D claudetools -e \"SELECT COUNT(*) as context_count FROM conversation_contexts;\" 2>/dev/null" 2>nul
echo.

echo [5] Checking for other data...
plink -batch guru@172.16.3.20 "docker exec mariadb mysql -u claudetools -pCT_e8fcd5a3952030a79ed6debae6c954ed -D claudetools -e \"SELECT TABLE_NAME, TABLE_ROWS FROM information_schema.TABLES WHERE TABLE_SCHEMA = 'claudetools' AND TABLE_ROWS > 0 ORDER BY TABLE_ROWS DESC LIMIT 10;\" 2>/dev/null" 2>nul
echo.

:end
echo ==========================================
echo Check Complete
echo ==========================================
pause
