| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- # Wx SOP Flyway migration verification
- # Usage: cd d:\ylrz_saas_new\java\scripts ; .\verify_wx_sop_flyway.ps1
- $ErrorActionPreference = "Stop"
- $root = Split-Path (Split-Path $PSScriptRoot -Parent) -Parent
- $tenantDir = Join-Path $root "java\fs-saas-admin\src\main\resources\db\migration\tenant"
- $masterDir = Join-Path $root "java\sql\master"
- $manual = Join-Path $root "java\sql\wx_sop_tenant_menu_full_sync_june2026.sql"
- Write-Host "=== Wx SOP Flyway verify ===" -ForegroundColor Cyan
- $requiredTenant = @(
- "V20260614_03__wx_sop_menu_sync.sql",
- "V20260614_04__wx_sop_role_menu_grant.sql"
- )
- $requiredMaster = @("V20260614_03__wx_sop_master_menu_sync.sql")
- $fail = 0
- foreach ($f in $requiredTenant) {
- $path = Join-Path $tenantDir $f
- if (-not (Test-Path $path)) {
- Write-Host "[FAIL] missing tenant migration: $f" -ForegroundColor Red
- $fail++
- } else {
- Write-Host "[OK] tenant migration: $f" -ForegroundColor Green
- }
- }
- foreach ($f in $requiredMaster) {
- $path = Join-Path $masterDir $f
- if (-not (Test-Path $path)) {
- Write-Host "[FAIL] missing master migration: $f" -ForegroundColor Red
- $fail++
- } else {
- Write-Host "[OK] master migration: $f" -ForegroundColor Green
- }
- }
- if (-not (Test-Path $manual)) {
- Write-Host "[FAIL] missing manual sync script" -ForegroundColor Red
- $fail++
- } else {
- Write-Host "[OK] manual sync script" -ForegroundColor Green
- }
- $versions = Get-ChildItem $tenantDir -Filter "V*__*.sql" | ForEach-Object {
- $_.Name.Substring(0, $_.Name.IndexOf("__"))
- } | Sort-Object
- $dup = $versions | Group-Object | Where-Object { $_.Count -gt 1 }
- if ($dup) {
- Write-Host "[FAIL] duplicate migration versions" -ForegroundColor Red
- $fail++
- } else {
- Write-Host "[OK] tenant migration versions unique ($($versions.Count) scripts)" -ForegroundColor Green
- }
- if ("V20260614_03" -ge "V20260614_04") {
- Write-Host "[FAIL] V20260614_04 must sort after V20260614_03" -ForegroundColor Red
- $fail++
- } else {
- Write-Host "[OK] V20260614_03 then V20260614_04 order" -ForegroundColor Green
- }
- $menuIds = @(32901..32904) + @(32911..32920) + @(32921..32925) + @(32931..32935) + @(32941..32945)
- $tenantScripts = @(
- "V20260614_03__wx_sop_menu_sync.sql",
- "V20260614_04__wx_sop_role_menu_grant.sql"
- )
- foreach ($name in $tenantScripts) {
- $path = Join-Path $tenantDir $name
- if (-not (Test-Path $path)) { continue }
- $text = [System.IO.File]::ReadAllText($path)
- if ($text.IndexOf("wx:wxSop:list") -lt 0 -and $text.IndexOf("sys_role_menu") -lt 0) {
- Write-Host "[FAIL] $name missing expected SQL markers" -ForegroundColor Red
- $fail++
- } else {
- Write-Host "[OK] $name SQL markers" -ForegroundColor Green
- }
- if ($name -like "*03*") {
- foreach ($id in $menuIds) {
- $needle = "($id,"
- if ($text.IndexOf($needle) -lt 0) {
- Write-Host "[FAIL] $name missing menu_id $id" -ForegroundColor Red
- $fail++
- }
- }
- }
- }
- $rolePath = Join-Path $tenantDir "V20260614_04__wx_sop_role_menu_grant.sql"
- if (Test-Path $rolePath) {
- $rt = [System.IO.File]::ReadAllText($rolePath)
- foreach ($kw in @("sys_role_menu", "company_role_menu", "role_key = 'admin'")) {
- if ($rt.IndexOf($kw) -lt 0) {
- Write-Host "[FAIL] role grant missing: $kw" -ForegroundColor Red
- $fail++
- } else {
- Write-Host "[OK] role grant contains: $kw" -ForegroundColor Green
- }
- }
- }
- $wxLoaded = Get-ChildItem (Join-Path $tenantDir "V*__*.sql") | ForEach-Object { $_.Name } |
- Where-Object { $_ -like "V20260614_03*" -or $_ -like "V20260614_04*" } |
- Sort-Object
- Write-Host "[OK] TenantUpgrade wx scripts: $($wxLoaded -join ', ')" -ForegroundColor Green
- $adminPom = Join-Path $root "java\fs-saas-admin\pom.xml"
- if (Test-Path $adminPom) {
- Push-Location (Join-Path $root "java")
- try {
- & mvn -q -pl fs-saas-admin -am test-compile -DskipTests
- if ($LASTEXITCODE -eq 0) {
- Write-Host "[OK] mvn test-compile fs-saas-admin" -ForegroundColor Green
- } else {
- Write-Host "[FAIL] mvn test-compile exit code $LASTEXITCODE" -ForegroundColor Red
- $fail++
- }
- } finally {
- Pop-Location
- }
- }
- Write-Host ""
- if ($fail -eq 0) {
- Write-Host "=== PASS ===" -ForegroundColor Green
- Write-Host "Next steps:"
- Write-Host " 1) Master DB: run sql/master/V20260614_03__wx_sop_master_menu_sync.sql"
- Write-Host " 2) Tenant upgrade: fromVersion empty, toVersion V20260614_04"
- exit 0
- } else {
- Write-Host "=== FAIL ($fail issue(s)) ===" -ForegroundColor Red
- exit 1
- }
|