#!/bin/bash
# 檢查 CodiMD 資料庫 Port Forward 狀態

echo "=== CodiMD 資料庫 Port Forward 狀態 ==="

if pgrep -f "port-forward.*codimd-db" > /dev/null; then
    PIDS=$(pgrep -f "port-forward.*codimd-db")
    echo "✅ Port-forward 正在運行"
    echo "   PID(s): $PIDS"

    # 檢查 port 是否可連接
    if nc -z localhost 5432 2>/dev/null; then
        echo "✅ Port 5432 可連接"
    else
        echo "⚠️  Port 5432 無法連接"
    fi
    exit 0
else
    echo "❌ Port-forward 未運行"
    echo ""
    echo "啟動方式: ./db-port-forward.sh"
    exit 1
fi
