verify_wx_sop_flyway.ps1 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. # Wx SOP Flyway migration verification
  2. # Usage: cd d:\ylrz_saas_new\java\scripts ; .\verify_wx_sop_flyway.ps1
  3. $ErrorActionPreference = "Stop"
  4. $root = Split-Path (Split-Path $PSScriptRoot -Parent) -Parent
  5. $tenantDir = Join-Path $root "java\fs-saas-admin\src\main\resources\db\migration\tenant"
  6. $masterDir = Join-Path $root "java\sql\master"
  7. $manual = Join-Path $root "java\sql\wx_sop_tenant_menu_full_sync_june2026.sql"
  8. Write-Host "=== Wx SOP Flyway verify ===" -ForegroundColor Cyan
  9. $requiredTenant = @(
  10. "V20260614_03__wx_sop_menu_sync.sql",
  11. "V20260614_04__wx_sop_role_menu_grant.sql"
  12. )
  13. $requiredMaster = @("V20260614_03__wx_sop_master_menu_sync.sql")
  14. $fail = 0
  15. foreach ($f in $requiredTenant) {
  16. $path = Join-Path $tenantDir $f
  17. if (-not (Test-Path $path)) {
  18. Write-Host "[FAIL] missing tenant migration: $f" -ForegroundColor Red
  19. $fail++
  20. } else {
  21. Write-Host "[OK] tenant migration: $f" -ForegroundColor Green
  22. }
  23. }
  24. foreach ($f in $requiredMaster) {
  25. $path = Join-Path $masterDir $f
  26. if (-not (Test-Path $path)) {
  27. Write-Host "[FAIL] missing master migration: $f" -ForegroundColor Red
  28. $fail++
  29. } else {
  30. Write-Host "[OK] master migration: $f" -ForegroundColor Green
  31. }
  32. }
  33. if (-not (Test-Path $manual)) {
  34. Write-Host "[FAIL] missing manual sync script" -ForegroundColor Red
  35. $fail++
  36. } else {
  37. Write-Host "[OK] manual sync script" -ForegroundColor Green
  38. }
  39. $versions = Get-ChildItem $tenantDir -Filter "V*__*.sql" | ForEach-Object {
  40. $_.Name.Substring(0, $_.Name.IndexOf("__"))
  41. } | Sort-Object
  42. $dup = $versions | Group-Object | Where-Object { $_.Count -gt 1 }
  43. if ($dup) {
  44. Write-Host "[FAIL] duplicate migration versions" -ForegroundColor Red
  45. $fail++
  46. } else {
  47. Write-Host "[OK] tenant migration versions unique ($($versions.Count) scripts)" -ForegroundColor Green
  48. }
  49. if ("V20260614_03" -ge "V20260614_04") {
  50. Write-Host "[FAIL] V20260614_04 must sort after V20260614_03" -ForegroundColor Red
  51. $fail++
  52. } else {
  53. Write-Host "[OK] V20260614_03 then V20260614_04 order" -ForegroundColor Green
  54. }
  55. $menuIds = @(32901..32904) + @(32911..32920) + @(32921..32925) + @(32931..32935) + @(32941..32945)
  56. $tenantScripts = @(
  57. "V20260614_03__wx_sop_menu_sync.sql",
  58. "V20260614_04__wx_sop_role_menu_grant.sql"
  59. )
  60. foreach ($name in $tenantScripts) {
  61. $path = Join-Path $tenantDir $name
  62. if (-not (Test-Path $path)) { continue }
  63. $text = [System.IO.File]::ReadAllText($path)
  64. if ($text.IndexOf("wx:wxSop:list") -lt 0 -and $text.IndexOf("sys_role_menu") -lt 0) {
  65. Write-Host "[FAIL] $name missing expected SQL markers" -ForegroundColor Red
  66. $fail++
  67. } else {
  68. Write-Host "[OK] $name SQL markers" -ForegroundColor Green
  69. }
  70. if ($name -like "*03*") {
  71. foreach ($id in $menuIds) {
  72. $needle = "($id,"
  73. if ($text.IndexOf($needle) -lt 0) {
  74. Write-Host "[FAIL] $name missing menu_id $id" -ForegroundColor Red
  75. $fail++
  76. }
  77. }
  78. }
  79. }
  80. $rolePath = Join-Path $tenantDir "V20260614_04__wx_sop_role_menu_grant.sql"
  81. if (Test-Path $rolePath) {
  82. $rt = [System.IO.File]::ReadAllText($rolePath)
  83. foreach ($kw in @("sys_role_menu", "company_role_menu", "role_key = 'admin'")) {
  84. if ($rt.IndexOf($kw) -lt 0) {
  85. Write-Host "[FAIL] role grant missing: $kw" -ForegroundColor Red
  86. $fail++
  87. } else {
  88. Write-Host "[OK] role grant contains: $kw" -ForegroundColor Green
  89. }
  90. }
  91. }
  92. $wxLoaded = Get-ChildItem (Join-Path $tenantDir "V*__*.sql") | ForEach-Object { $_.Name } |
  93. Where-Object { $_ -like "V20260614_03*" -or $_ -like "V20260614_04*" } |
  94. Sort-Object
  95. Write-Host "[OK] TenantUpgrade wx scripts: $($wxLoaded -join ', ')" -ForegroundColor Green
  96. $adminPom = Join-Path $root "java\fs-saas-admin\pom.xml"
  97. if (Test-Path $adminPom) {
  98. Push-Location (Join-Path $root "java")
  99. try {
  100. & mvn -q -pl fs-saas-admin -am test-compile -DskipTests
  101. if ($LASTEXITCODE -eq 0) {
  102. Write-Host "[OK] mvn test-compile fs-saas-admin" -ForegroundColor Green
  103. } else {
  104. Write-Host "[FAIL] mvn test-compile exit code $LASTEXITCODE" -ForegroundColor Red
  105. $fail++
  106. }
  107. } finally {
  108. Pop-Location
  109. }
  110. }
  111. Write-Host ""
  112. if ($fail -eq 0) {
  113. Write-Host "=== PASS ===" -ForegroundColor Green
  114. Write-Host "Next steps:"
  115. Write-Host " 1) Master DB: run sql/master/V20260614_03__wx_sop_master_menu_sync.sql"
  116. Write-Host " 2) Tenant upgrade: fromVersion empty, toVersion V20260614_04"
  117. exit 0
  118. } else {
  119. Write-Host "=== FAIL ($fail issue(s)) ===" -ForegroundColor Red
  120. exit 1
  121. }