# Merge server/schema.sql + database/sql/*.sql (INSERT dumps) -> database/sql/wuhan_saga_init.sql # Run from repo root: powershell -ExecutionPolicy Bypass -File scripts/build-init-from-sql-dumps.ps1 $ErrorActionPreference = 'Stop' $root = Split-Path -Parent $PSScriptRoot $schemaPath = Join-Path $root "server/src/main/resources/schema.sql" $sqlDir = Join-Path $root "database/sql" $outPath = Join-Path $sqlDir "wuhan_saga_init.sql" $dataFiles = @( "sys_user.sql", "f_company_info.sql", "f_contact.sql", "f_about.sql", "f_banner.sql", "f_workshop.sql", "f_case_category.sql", "f_case_study.sql", "f_case_media.sql", "f_core_technology.sql", "f_news_category.sql", "f_news.sql", "f_media_library.sql", "f_product_category.sql", "f_product_line.sql", "f_single_equipment.sql", "f_spare_part.sql", "f_product_line_equipment.sql", "f_product_media.sql" ) if (-not (Test-Path $schemaPath)) { Write-Error "Missing schema: $schemaPath" } $sb = New-Object System.Text.StringBuilder [void]$sb.AppendLine(@" -- ====================================================================== -- Wuhan Saga FULL init: schema (from resources) + data (from database/sql exports) -- Generated: scripts/build-init-from-sql-dumps.ps1 -- Run: mysql -u root -p < database/sql/wuhan_saga_init.sql -- ====================================================================== SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci; SET FOREIGN_KEY_CHECKS = 0; CREATE DATABASE IF NOT EXISTS wuhan_saga CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; USE wuhan_saga; -- ---------- SCHEMA ---------- "@) $schema = Get-Content -Raw -Encoding UTF8 $schemaPath [void]$sb.AppendLine($schema.TrimEnd()) [void]$sb.AppendLine("") [void]$sb.AppendLine("-- ---------- DATA (INSERT dumps, FK-safe order) ----------") foreach ($name in $dataFiles) { $p = Join-Path $sqlDir $name if (-not (Test-Path $p)) { Write-Warning "Skip (missing): $name" continue } $raw = Get-Content -Raw -Encoding UTF8 $p if ([string]::IsNullOrWhiteSpace($raw)) { Write-Warning "Skip (empty): $name" continue } [void]$sb.AppendLine("") [void]$sb.AppendLine("-- ---- $name ----") [void]$sb.AppendLine($raw.TrimEnd()) } [void]$sb.AppendLine("") [void]$sb.AppendLine("SET FOREIGN_KEY_CHECKS = 1;") $utf8NoBom = New-Object System.Text.UTF8Encoding $false [System.IO.File]::WriteAllText($outPath, $sb.ToString(), $utf8NoBom) Write-Host "Wrote" $outPath