#!/bin/bash
# =============================================
# 数据库检查脚本
# =============================================

DB_HOST="8.155.172.147"
DB_PORT="3306"
DB_NAME="monisuo"
DB_USER="monisuo"
DB_PASS="JPJ8wYicSGC8aRnk"

echo "=========================================="
echo "Monisuo 数据库检查"
echo "=========================================="
echo ""

# 检查 cold_wallet 表是否存在
echo "【1】检查 cold_wallet 表是否存在..."
mysql -h$DB_HOST -P$DB_PORT -u$DB_USER -p$DB_PASS $DB_NAME -e "SHOW TABLES LIKE 'cold_wallet';" 2>/dev/null

if [ $? -eq 0 ]; then
  echo "✅ cold_wallet 表存在"
  
  echo ""
  echo "【2】检查默认钱包地址..."
  mysql -h$DB_HOST -P$DB_PORT -u$DB_USER -p$DB_PASS $DB_NAME -e "SELECT id, name, address, network, is_default, status FROM cold_wallet WHERE is_default=1 AND status=1;" 2>/dev/null
  
  echo ""
  echo "【3】检查所有钱包..."
  mysql -h$DB_HOST -P$DB_PORT -u$DB_USER -p$DB_PASS $DB_NAME -e "SELECT id, name, network, is_default, status FROM cold_wallet;" 2>/dev/null
else
  echo "❌ cold_wallet 表不存在，需要执行补丁脚本"
  echo ""
  echo "执行命令:"
  echo "mysql -h$DB_HOST -P$DB_PORT -u$DB_USER -p$DB_PASS $DB_NAME < sql/patch_cold_wallet.sql"
fi

echo ""
echo "【4】检查 order_fund 表结构..."
mysql -h$DB_HOST -P$DB_PORT -u$DB_USER -p$DB_PASS $DB_NAME -e "DESC order_fund;" 2>/dev/null | grep -E "wallet|pay_time|confirm_time|withdraw_contact"

echo ""
echo "=========================================="
echo "检查完成"
echo "=========================================="
