Files
tamabox/internal/db/user_block.go
T
2026-09-08 10:10:44 +08:00

22 lines
943 B
Go

// Copyright 2022 E99p1ant. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package db
import "time"
// UserBlock 记录用户拉黑关系(UserID 拉黑了 BlockedID)。
// 使用独立关联表而非在 users 上存 JSON,以获得:
// - (user_id, blocked_id) 唯一索引保证幂等,并发拉黑不会互相覆盖;
// - 判断是否拉黑走索引查询,无需反序列化整串 JSON。
//
// 注意:本表采用物理删除(取消拉黑即删行),不使用 gorm.DeletedAt 软删除,
// 否则「拉黑 → 取消 → 再拉黑」会因软删记录仍占用唯一索引而插入冲突。
type UserBlock struct {
ID uint `gorm:"primarykey"`
UserID uint `gorm:"not null;uniqueIndex:idx_user_block_unique"`
BlockedID uint `gorm:"not null;uniqueIndex:idx_user_block_unique"`
CreatedAt time.Time `json:"-"`
}