yeg
2026-09-08 00f89659201b393df7ea8cf2215ec23dfda62ca2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
param(
    [string]$Source = (Join-Path $PSScriptRoot '..\battery_detection.sql'),
    [string]$Output = (Join-Path $PSScriptRoot '..\ruoyi-admin\src\main\resources\db\migration\V1__ruoyi_platform_baseline.sql')
)
 
$sourcePath = [System.IO.Path]::GetFullPath($Source)
$outputPath = [System.IO.Path]::GetFullPath($Output)
$sql = [System.IO.File]::ReadAllText($sourcePath)
 
$tablePattern = '(?ms)^CREATE TABLE `(?<name>[^`]+)`\s+\(.*?^\).*?;\s*$'
$platformTables = [regex]::Matches($sql, $tablePattern) |
    Where-Object {
        $name = $_.Groups['name'].Value
        $name.StartsWith('QRTZ_') -or $name.StartsWith('gen_') -or $name.StartsWith('sys_')
    }
 
if ($platformTables.Count -eq 0) {
    throw "No platform table definitions found in $sourcePath"
}
 
$seedRules = @{
    'sys_config' = '^INSERT INTO `sys_config`'
    'sys_dept' = '^INSERT INTO `sys_dept` VALUES \((100|101|103),'
    'sys_dict_data' = '^INSERT INTO `sys_dict_data`'
    'sys_dict_type' = '^INSERT INTO `sys_dict_type`'
    'sys_menu' = '^INSERT INTO `sys_menu`'
    'sys_post' = '^INSERT INTO `sys_post` VALUES \(1,'
    'sys_role' = '^INSERT INTO `sys_role` VALUES \(1,'
    'sys_user' = '^INSERT INTO `sys_user` VALUES \(1,'
    'sys_user_post' = '^INSERT INTO `sys_user_post` VALUES \(1,'
    'sys_user_role' = '^INSERT INTO `sys_user_role` VALUES \(1,'
}
 
$sourceLines = [System.IO.File]::ReadAllLines($sourcePath)
$seedLines = foreach ($rule in $seedRules.GetEnumerator() | Sort-Object Name) {
    $sourceLines | Where-Object { $_ -match $rule.Value }
}
 
$parts = [System.Collections.Generic.List[string]]::new()
$parts.Add('-- Generated by scripts/Build-FlywayBaseline.ps1 from the checked-in schema dump.')
$parts.Add('-- Contains platform structure and minimal development seed data only.')
$parts.Add('SET NAMES utf8mb4;')
$parts.Add('SET FOREIGN_KEY_CHECKS = 0;')
$parts.Add('')
 
foreach ($table in $platformTables) {
    $parts.Add($table.Value.Trim())
    $parts.Add('')
}
 
$parts.Add('-- Minimal development seed data')
foreach ($line in $seedLines) {
    $parts.Add($line)
}
$parts.Add('')
$parts.Add('SET FOREIGN_KEY_CHECKS = 1;')
$parts.Add('')
 
$outputDirectory = [System.IO.Path]::GetDirectoryName($outputPath)
[System.IO.Directory]::CreateDirectory($outputDirectory) | Out-Null
[System.IO.File]::WriteAllText($outputPath, ($parts -join "`r`n"), [System.Text.UTF8Encoding]::new($false))
 
Write-Output $outputPath