# 清理 Flyway 迁移历史的 PowerShell 脚本
# 使用 MySQL Connector/NET 执行 SQL

$mysqlExe = "C:\Program Files\MySQL\MySQL Server 8.0\bin\mysql.exe"

# 如果 mysql.exe 不存在，尝试其他常见路径
if (!(Test-Path $mysqlExe)) {
    $mysqlExe = "C:\Program Files\MySQL\MySQL Workbench 8.0\mysql.exe"
}

if (!(Test-Path $mysqlExe)) {
    Write-Host "未找到 MySQL 客户端，请手动执行以下 SQL："
    Write-Host ""
    Write-Host "USE reading_platform;"
    Write-Host "DROP TABLE IF EXISTS flyway_schema_history;"
    Write-Host ""
    exit 1
}

Write-Host "正在清理 Flyway 迁移历史..."
Write-Host "MySQL 路径：$mysqlExe"

$sql = "USE reading_platform; DROP TABLE IF EXISTS flyway_schema_history; SELECT '清理完成' AS status;"

& $mysqlExe -h 8.148.151.56 -u root -p"reading_platform_pwd" -e $sql

if ($LASTEXITCODE -eq 0) {
    Write-Host "清理成功！" -ForegroundColor Green
} else {
    Write-Host "清理失败，请检查数据库连接" -ForegroundColor Red
}
