export-stage3-sql.ps1 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. $ErrorActionPreference = "Stop"
  2. $projectRoot = Split-Path -Parent $PSScriptRoot
  3. $sourcePath = Join-Path $projectRoot "database\zhibaotong-stage1-stage2-stage3-mysql.sql"
  4. $targetPath = Join-Path $projectRoot "database\zhibaotong-stage3-mysql.sql"
  5. $content = [System.IO.File]::ReadAllText($sourcePath, [System.Text.Encoding]::UTF8)
  6. $sessionStartMarker = "/*!40101 SET @OLD_CHARACTER_SET_CLIENT"
  7. $firstDatabaseMarker = '-- Current Database: `insurance_s1_core`'
  8. $stage3Marker = '-- Current Database: `insurance_s3_core`'
  9. $sessionStart = $content.IndexOf($sessionStartMarker, [System.StringComparison]::Ordinal)
  10. $firstDatabaseStart = $content.IndexOf(
  11. $firstDatabaseMarker,
  12. [System.StringComparison]::Ordinal
  13. )
  14. $stage3Start = $content.IndexOf($stage3Marker, [System.StringComparison]::Ordinal)
  15. if ($sessionStart -lt 0 -or $firstDatabaseStart -lt 0 -or $stage3Start -lt 0) {
  16. throw "Expected stage boundaries were not found in the unified SQL."
  17. }
  18. $sessionPreamble = $content.Substring(
  19. $sessionStart,
  20. $firstDatabaseStart - $sessionStart
  21. )
  22. $stage3Body = $content.Substring($stage3Start)
  23. $header = @"
  24. -- Zhibaotong Stage 3 MySQL initialization script
  25. -- Source: zhibaotong-stage1-stage2-stage3-mysql.sql
  26. -- Databases: insurance_s3_core, insurance_s3_agent, insurance_s3_analytics
  27. -- Warning: importing this file rebuilds same-named tables in these databases.
  28. "@
  29. $output = $header + $sessionPreamble + $stage3Body
  30. $utf8WithoutBom = [System.Text.UTF8Encoding]::new($false)
  31. [System.IO.File]::WriteAllText($targetPath, $output, $utf8WithoutBom)
  32. Write-Host "Generated: $targetPath"