#!/bin/bash
# ERP Java 数据库初始化脚本
# 用法: bash init.sh

DB_HOST="111.229.80.149"
DB_USER="root"
DB_PASS="nihao588+"
DB_NAME="erp_java"

echo "=== 创建数据库 ==="
mysql -h $DB_HOST -u $DB_USER -p$DB_PASS -e "DROP DATABASE IF EXISTS $DB_NAME; CREATE DATABASE $DB_NAME DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;" 2>/dev/null

echo "=== 执行建库SQL ==="
SQL_DIR="$(dirname "$0")"
mysql -h $DB_HOST -u $DB_USER -p$DB_PASS --force $DB_NAME < "$SQL_DIR/merge.sql" 2>&1 | grep -v "Warning" | grep -E "^ERROR" || true

echo "=== 建库完成 ==="
mysql -h $DB_HOST -u $DB_USER -p$DB_PASS -e "USE $DB_NAME; SHOW TABLES;" 2>/dev/null | wc -l
echo "个表已创建"
