This commit is contained in:
2026-08-27 11:04:56 +08:00
parent 0ca8f4c3ab
commit bb7bac3dee
30 changed files with 171 additions and 260 deletions
+40 -1
View File
@@ -24,7 +24,7 @@ func main() {
s := g.Server()
// Android APK 下载静态托管:app.apkDir 目录下固定文件 observer-latest.apk
// URL 固定 /download/observer-latest.apk(绕过统一响应包装,纯二进制流);
// 模型热更新文件同根 /download/models/<数据集名>/latest.tflitedatasetDir 下 models 目录)
// 模型热更新文件同根 /download/trainings/<数据集名>.tflitedatasetDir 下 trainings 目录)
if err := os.MkdirAll(common.ApkDir(ctx), 0o755); err != nil {
g.Log().Fatalf(ctx, "创建 APK 目录失败: %+v", err)
}
@@ -198,6 +198,45 @@ func initDatabase(ctx context.Context) {
}
g.Log().Infof(ctx, "数据库初始化完成(version=11)")
}
if version < 12 {
// v12:清理孤儿字段 —— dataset 删 6 列(AI 标注/训练机 SSH 配置统一走 config.yml 的
// localAi/training.ssh,零读写)+ model_version 删 artifact_filezip 产物布局移除后无人写)
// + label_task 删 boxes_file(标注已入库,候选框文件机制废弃)。
// PRAGMA table_info 逐列检测存在才 DROP,新库建表已无此列直接跳过
dropCols := []struct{ table, col string }{
{"dataset", "ai_endpoint"},
{"dataset", "ai_model"},
{"dataset", "train_host"},
{"dataset", "train_user"},
{"dataset", "train_password"},
{"dataset", "train_key"},
{"model_version", "artifact_file"},
{"label_task", "boxes_file"},
}
for _, c := range dropCols {
cols, err := g.DB().GetAll(ctx, "PRAGMA table_info("+c.table+")")
if err != nil {
g.Log().Fatalf(ctx, "读取 %s 表结构失败: %+v", c.table, err)
}
exists := false
for _, col := range cols {
if gconv.String(col["name"]) == c.col {
exists = true
break
}
}
if !exists {
continue
}
if _, err := g.DB().Exec(ctx, "ALTER TABLE "+c.table+" DROP COLUMN "+c.col); err != nil {
g.Log().Fatalf(ctx, "删除 %s.%s 列失败: %+v", c.table, c.col, err)
}
}
if _, err := g.DB().Exec(ctx, "PRAGMA user_version = 12"); err != nil {
g.Log().Fatalf(ctx, "库版本写入失败: %+v", err)
}
g.Log().Infof(ctx, "数据库初始化完成(version=12)")
}
// 死表清理:app_config 全局训练配置表已撤销(配置走 config.yml),存量库残留表启动即删
if _, err := g.DB().Exec(ctx, "DROP TABLE IF EXISTS app_config"); err != nil {
g.Log().Fatalf(ctx, "删除残留 app_config 表失败: %+v", err)