storage-layout-init.ps1 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. # 把旧版 qingjian/ 目录整理成 system + data 双区布局(Windows PowerShell)。
  2. #
  3. # 只迁移程序资产,不碰历史案件数据。
  4. # 用法:
  5. # powershell -ExecutionPolicy Bypass -File deploy/storage-layout-init.ps1 -DryRun
  6. # powershell -ExecutionPolicy Bypass -File deploy/storage-layout-init.ps1
  7. param(
  8. [switch]$DryRun
  9. )
  10. $ErrorActionPreference = "Stop"
  11. $Root = (Resolve-Path (Join-Path $PSScriptRoot "..")).Path
  12. $Base = Join-Path $Root "qingjian"
  13. function Run([scriptblock]$Action, [string]$Label) {
  14. if ($DryRun) {
  15. Write-Host "[dry-run] $Label"
  16. } else {
  17. Write-Host "[run] $Label"
  18. & $Action
  19. }
  20. }
  21. function EnsureDir([string]$Path) {
  22. Run { New-Item -ItemType Directory -Force -Path $Path | Out-Null } "mkdir $Path"
  23. }
  24. function MoveIfExists([string]$Src, [string]$Dst) {
  25. if (-not (Test-Path $Src)) { return }
  26. # 应用可能已提前创建空的目标目录(StorageBootstrap):空目录先摘掉再移动
  27. if ((Test-Path $Src -PathType Container) -and (Test-Path $Dst -PathType Container) -and
  28. -not (Get-ChildItem -LiteralPath $Dst -Force -ErrorAction SilentlyContinue)) {
  29. Run { Remove-Item -LiteralPath $Dst -Force } "rmdir $Dst"
  30. }
  31. if (Test-Path $Dst) {
  32. Write-Host "[skip] 目标已存在:$Dst(源 $Src 保留,请人工确认)"
  33. return
  34. }
  35. EnsureDir (Split-Path $Dst -Parent)
  36. Run { Move-Item -LiteralPath $Src -Destination $Dst } "move $Src -> $Dst"
  37. }
  38. # 1. 根目录大小写:Windows 大小写不敏感,先改成临时名再改成小写
  39. $legacy = Join-Path $Root "QingJian"
  40. if ((Test-Path $legacy) -and -not (Test-Path $Base)) {
  41. Run { Rename-Item -LiteralPath $legacy -NewName "qingjian" } "rename QingJian -> qingjian"
  42. } elseif (Test-Path $legacy) {
  43. $tmp = Join-Path $Root ".qingjian-case-tmp"
  44. Run { Rename-Item -LiteralPath $legacy -NewName ".qingjian-case-tmp" } "rename QingJian -> .qingjian-case-tmp"
  45. Run { Rename-Item -LiteralPath $tmp -NewName "qingjian" } "rename .qingjian-case-tmp -> qingjian"
  46. }
  47. # 2. 目录骨架
  48. EnsureDir (Join-Path $Base "system")
  49. EnsureDir (Join-Path $Base "system\db")
  50. EnsureDir (Join-Path $Base "system\rocksdb")
  51. EnsureDir (Join-Path $Base "system\libs")
  52. EnsureDir (Join-Path $Base "system\models")
  53. EnsureDir (Join-Path $Base "system\tools")
  54. EnsureDir (Join-Path $Base "system\extension")
  55. EnsureDir (Join-Path $Base "data\cases")
  56. EnsureDir (Join-Path $Base "data\users")
  57. EnsureDir (Join-Path $Base "data\tmp")
  58. EnsureDir (Join-Path $Base "data\index")
  59. # 3. 程序资产迁移
  60. MoveIfExists (Join-Path $Base "conf") (Join-Path $Base "system\conf")
  61. MoveIfExists (Join-Path $Base "db\5w8mf4kf") (Join-Path $Base "system\db\5w8mf4kf")
  62. MoveIfExists (Join-Path $Base "db\plat") (Join-Path $Base "system\db\plat")
  63. MoveIfExists (Join-Path $Base "db\temp") (Join-Path $Base "system\db\temp")
  64. MoveIfExists (Join-Path $Base "license") (Join-Path $Base "system\license")
  65. MoveIfExists (Join-Path $Base "d5e03ad1") (Join-Path $Base "system\rocksdb\d5e03ad1")
  66. MoveIfExists (Join-Path $Base "uy76tkp8") (Join-Path $Base "system\rocksdb\uy76tkp8")
  67. MoveIfExists (Join-Path $Base "w6df89sk") (Join-Path $Base "system\libs\cell")
  68. MoveIfExists (Join-Path $Base "7Zip") (Join-Path $Base "system\libs\7zip")
  69. MoveIfExists (Join-Path $Base "extension") (Join-Path $Base "system\extension")
  70. MoveIfExists (Join-Path $Root "data\native") (Join-Path $Base "system\native")
  71. MoveIfExists (Join-Path $Root "bge-m3") (Join-Path $Base "system\models\bge-m3")
  72. MoveIfExists (Join-Path $Root "vosk-model") (Join-Path $Base "system\models\vosk-model")
  73. MoveIfExists (Join-Path $Root "tools\ffmpeg") (Join-Path $Base "system\tools\ffmpeg")
  74. Write-Host ""
  75. Write-Host "完成。当前布局:"
  76. Write-Host " system : $Base\system"
  77. Write-Host " data : $Base\data"
  78. Write-Host "历史目录(未处理):$Base\workspace、$Base\chat-attachments、$Base\agent、$Base\tmp、$Base\graph_his、$Root\.agentscope、$Root\data\files"