package models import "time" // SaAIRateBucket 保存用户在固定窗口内已占用的 AI 请求配额。 // 复合唯一键让单条 UPSERT 在数据库层完成跨进程并发仲裁。 type SaAIRateBucket struct { ID uint `gorm:"primaryKey"` UserID uint `gorm:"not null;uniqueIndex:uidx_sa_ai_rate_bucket,priority:1"` Action string `gorm:"size:100;not null;uniqueIndex:uidx_sa_ai_rate_bucket,priority:2"` WindowStart time.Time `gorm:"not null;uniqueIndex:uidx_sa_ai_rate_bucket,priority:3"` Count int `gorm:"not null"` CreatedAt time.Time UpdatedAt time.Time } func (SaAIRateBucket) TableName() string { return "sa_ai_rate_buckets" }