Fix: Add unique index to prevent duplicate monthly stats records

This commit is contained in:
DullJZ
2025-11-03 22:00:35 +08:00
parent 7e8b10880f
commit dc6916f3df

View File

@@ -48,9 +48,9 @@ func (BucketStats) TableName() string {
// BucketMonthlyStats 存储桶月度统计信息模型
type BucketMonthlyStats struct {
ID uint `gorm:"primaryKey" json:"id"`
BucketName string `gorm:"index:idx_bucket_month;size:255;not null" json:"bucket_name"`
Year int `gorm:"index:idx_bucket_month;not null" json:"year"`
Month int `gorm:"index:idx_bucket_month;not null" json:"month"`
BucketName string `gorm:"uniqueIndex:idx_bucket_month;size:255;not null" json:"bucket_name"`
Year int `gorm:"uniqueIndex:idx_bucket_month;not null" json:"year"`
Month int `gorm:"uniqueIndex:idx_bucket_month;not null" json:"month"`
OperationCountA int64 `gorm:"not null;default:0" json:"operation_count_a"`
OperationCountB int64 `gorm:"not null;default:0" json:"operation_count_b"`
CreatedAt time.Time `json:"created_at"`