Files
Losita 3b6fca44a6 Version: 0.9.77.dev.260505
后端:
1.阶段 6 CP4/CP5 目录收口与共享边界纯化
- 将 backend 根目录收口为 services、client、gateway、cmd、shared 五个一级目录
- 收拢 bootstrap、inits、infra/kafka、infra/outbox、conv、respond、pkg、middleware,移除根目录旧实现与空目录
- 将 utils 下沉到 services/userauth/internal/auth,将 logic 下沉到 services/schedule/core/planning
- 将迁移期 runtime 桥接实现统一收拢到 services/runtime/{conv,dao,eventsvc,model},删除 shared/legacy 与未再被 import 的旧 service 实现
- 将 gateway/shared/respond 收口为 HTTP/Gin 错误写回适配,shared/respond 仅保留共享错误语义与状态映射
- 将 HTTP IdempotencyMiddleware 与 RateLimitMiddleware 收口到 gateway/middleware
- 将 GormCachePlugin 下沉到 shared/infra/gormcache,将共享 RateLimiter 下沉到 shared/infra/ratelimit,将 agent token budget 下沉到 services/agent/shared
- 删除 InitEino 兼容壳,收缩 cmd/internal/coreinit 仅保留旧组合壳残留域初始化语义
- 更新微服务迁移计划与桌面 checklist,补齐 CP4/CP5 当前切流点、目录终态与验证结果
- 完成 go test ./...、git diff --check 与最终真实 smoke;health、register/login、task/create+get、schedule/today、task-class/list、memory/items、agent chat/meta/timeline/context-stats 全部 200,SSE 合并结果为 CP5_OK 且 [DONE] 只有 1 个
2026-05-05 23:25:07 +08:00

49 lines
1.9 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package dao
import (
"fmt"
notificationmodel "github.com/LoveLosita/smartflow/backend/services/notification/model"
coremodel "github.com/LoveLosita/smartflow/backend/services/runtime/model"
mysqlinfra "github.com/LoveLosita/smartflow/backend/shared/infra/mysql"
outboxinfra "github.com/LoveLosita/smartflow/backend/shared/infra/outbox"
"gorm.io/gorm"
)
// OpenDBFromConfig 创建 notification 服务自己的数据库句柄。
//
// 职责边界:
// 1. 只迁移 notification_records 与 user_notification_channels
// 2. 不迁移主动调度、agent、userauth 或其它服务表;
// 3. 返回的 *gorm.DB 供 notification 服务内 DAO 和 outbox consumer 复用。
func OpenDBFromConfig() (*gorm.DB, error) {
db, err := mysqlinfra.OpenDBFromConfig()
if err != nil {
return nil, err
}
if err = db.AutoMigrate(&notificationmodel.NotificationRecord{}, &notificationmodel.UserNotificationChannel{}); err != nil {
return nil, fmt.Errorf("auto migrate notification tables failed: %w", err)
}
if err = autoMigrateNotificationOutboxTable(db); err != nil {
return nil, err
}
return db, nil
}
// autoMigrateNotificationOutboxTable 只迁移 notification 服务自己的 outbox 物理表。
//
// 职责边界:
// 1. 只负责 notification.outbox 对应表,不碰单体残留的其他业务表;
// 2. 让独立 notification 服务可以单独启动和消费 outbox不依赖 backend/inits 的全量迁移;
// 3. 若后续调整 outbox 表名,只改 service catalog不在这里硬编码。
func autoMigrateNotificationOutboxTable(db *gorm.DB) error {
cfg, ok := outboxinfra.ResolveServiceConfig(outboxinfra.ServiceNotification)
if !ok {
return fmt.Errorf("resolve notification outbox config failed")
}
if err := db.Table(cfg.TableName).AutoMigrate(&coremodel.AgentOutboxMessage{}); err != nil {
return fmt.Errorf("auto migrate notification outbox table failed for %s (%s): %w", cfg.Name, cfg.TableName, err)
}
return nil
}