refactor(notification): 通知实体抽成独立包

`video` 与 `worker` 各有一份 `notifications` 表的实体。
两份定义会漂移,所以合并到 `internal/notification`。
新增 `entity.go` 保存唯一一份列标签。

`worker`、`ssehub`、`comment_repo`、`db` 与两个集成测试改为引用新包。
`db` 包不再 import `worker`。
去重键仍是 `*string`,因此 NULL 才能共存。

验证:go test -count=1 ./... 全绿;集成测试三包全绿。
This commit is contained in:
2026-10-30 23:48:43 +08:00
parent 07f3166ab7
commit 151faf25fa
9 changed files with 87 additions and 83 deletions

View File

@@ -2,7 +2,6 @@ package video
import (
"context"
"time"
)
// Mention 是一条"提及通知"的写入意图。
@@ -19,31 +18,6 @@ type Mention struct {
DedupeKey string
}
// NotificationRow 是 notifications 表在 video 包里的投影。
//
// 为什么不直接 import worker.Notification:worker 包 import 了 video
// (CommentWorker 依赖 CommentStore),反向 import 会成环。这张投影只需要
// "写一行通知"所需的字段,schema 的权威定义仍在 worker.Notification,
// 因此下面每个列标签都必须与它逐字一致——不一致时 AutoMigrate 会试图改动
// 生产列类型,那是本方案最不希望引入的意外。
type NotificationRow struct {
ID uint `gorm:"primaryKey"`
RecipientID uint `gorm:"index;not null"`
SenderID uint `gorm:"not null"`
Type string `gorm:"type:varchar(50);not null"`
TargetID uint `gorm:"column:target_id"`
Content string `gorm:"type:varchar(255)"`
IsRead bool `gorm:"default:false"`
CreatedAt time.Time `gorm:"autoCreateTime"`
// DedupeKey 与 worker.Notification.DedupeKey 指向同一个唯一索引
// uk_notifications_dedupe。为 nil 时不参与判重(MySQL 不约束 NULL),
// 这正是"没有意图键的旧路径"仍然能写入的原因。
DedupeKey *string `gorm:"column:dedupe_key;type:varchar(128);uniqueIndex:uk_notifications_dedupe"`
}
func (NotificationRow) TableName() string { return "notifications" }
// CommentStore 是 CommentService 与 CommentWorker 依赖的窄接口。
//
// 抽接口不是为了"面向接口编程",而是为了给"判重与写入必须发生在同一条 SQL