分离五项配置与运行数据并实现无损目录迁移
Security Checks / security (push) Waiting to run

This commit is contained in:
xuans committed 2026-09-08 17:16:09 +08:00
1 parent dc188b1ed8
commit d6cc81ed87
53 files changed
+909 -127

No files matched your search

+23
View File
@@ -7,6 +7,7 @@ import (
"path/filepath"
"git.pcux.cn/xuans/Smail/config"
"git.pcux.cn/xuans/Smail/utils/runtimepath"
)
// main 提供部署端显式配置迁移,不在网页或普通启动中自动改写配置。
@@ -21,6 +22,7 @@ func run(args []string) error {
flags := flag.NewFlagSet("smail-config", flag.ContinueOnError)
root := flags.String("root", "", "Smail 服务根目录,包含 config 子目录")
apply := flags.Bool("apply", false, "确认已停止后端,备份并执行迁移;默认只检查")
runtimeData := flags.Bool("runtime-data", false, "将运行数据迁到 data,保留当前五个配置文件")
if err := flags.Parse(args); err != nil {
return err
}
@@ -32,6 +34,27 @@ func run(args []string) error {
return fmt.Errorf("服务根目录无效")
}
options := config.RuntimeValidationOptions{HasSuperAdmin: true, Production: true}
if *runtimeData {
moves, err := runtimepath.Plan(absolute)
if err != nil {
return err
}
if !*apply {
fmt.Printf("检查通过,共 %d 项待迁移;停止后端后加 --apply 执行。\n", len(moves))
return nil
}
if _, err := config.NewConfigLoader(absolute, config.ConfigLoaderOptions{Validation: options}).Load(); err != nil {
// 旧单文件部署先搬运行数据,再执行原有的分区配置迁移。
if _, legacyErr := config.PlanLegacyMigration(absolute, options); legacyErr != nil {
return fmt.Errorf("当前配置校验失败,未执行迁移")
}
}
if _, err := runtimepath.Migrate(absolute); err != nil {
return err
}
fmt.Printf("运行数据迁移完成,共 %d 项;当前五个配置文件未改写,废弃配置保留在 data/legacy-config。\n", len(moves))
return nil
}
plan, err := config.PlanLegacyMigration(absolute, options)
if err != nil {
// 不输出配置原文、未知字段或底层错误,避免凭据进入终端记录。