idempotency_record.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package schema
  2. import (
  3. "github.com/Wei-Shaw/sub2api/ent/schema/mixins"
  4. "entgo.io/ent"
  5. "entgo.io/ent/dialect/entsql"
  6. "entgo.io/ent/schema"
  7. "entgo.io/ent/schema/field"
  8. "entgo.io/ent/schema/index"
  9. )
  10. // IdempotencyRecord 幂等请求记录表。
  11. type IdempotencyRecord struct {
  12. ent.Schema
  13. }
  14. func (IdempotencyRecord) Annotations() []schema.Annotation {
  15. return []schema.Annotation{
  16. entsql.Annotation{Table: "idempotency_records"},
  17. }
  18. }
  19. func (IdempotencyRecord) Mixin() []ent.Mixin {
  20. return []ent.Mixin{
  21. mixins.TimeMixin{},
  22. }
  23. }
  24. func (IdempotencyRecord) Fields() []ent.Field {
  25. return []ent.Field{
  26. field.String("scope").MaxLen(128),
  27. field.String("idempotency_key_hash").MaxLen(64),
  28. field.String("request_fingerprint").MaxLen(64),
  29. field.String("status").MaxLen(32),
  30. field.Int("response_status").Optional().Nillable(),
  31. field.String("response_body").Optional().Nillable(),
  32. field.String("error_reason").MaxLen(128).Optional().Nillable(),
  33. field.Time("locked_until").Optional().Nillable(),
  34. field.Time("expires_at"),
  35. }
  36. }
  37. func (IdempotencyRecord) Indexes() []ent.Index {
  38. return []ent.Index{
  39. index.Fields("scope", "idempotency_key_hash").Unique(),
  40. index.Fields("expires_at"),
  41. index.Fields("status", "locked_until"),
  42. }
  43. }