batch_image_event.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package schema
  2. import (
  3. "time"
  4. "entgo.io/ent"
  5. "entgo.io/ent/dialect"
  6. "entgo.io/ent/dialect/entsql"
  7. "entgo.io/ent/schema"
  8. "entgo.io/ent/schema/field"
  9. "entgo.io/ent/schema/index"
  10. )
  11. // BatchImageEvent records append-only operational events for batch image jobs.
  12. type BatchImageEvent struct {
  13. ent.Schema
  14. }
  15. func (BatchImageEvent) Annotations() []schema.Annotation {
  16. return []schema.Annotation{
  17. entsql.Annotation{Table: "batch_image_events"},
  18. }
  19. }
  20. func (BatchImageEvent) Fields() []ent.Field {
  21. return []ent.Field{
  22. field.String("job_id").MaxLen(64),
  23. field.String("event_type").MaxLen(64),
  24. field.JSON("payload", map[string]any{}).
  25. Optional().
  26. SchemaType(map[string]string{dialect.Postgres: "jsonb"}),
  27. field.String("event_hash").Optional().Nillable().MaxLen(128),
  28. field.Time("created_at").Immutable().Default(time.Now).SchemaType(map[string]string{dialect.Postgres: "timestamptz"}),
  29. }
  30. }
  31. func (BatchImageEvent) Indexes() []ent.Index {
  32. return []ent.Index{
  33. index.Fields("job_id", "created_at"),
  34. index.Fields("event_type"),
  35. index.Fields("job_id", "event_hash").Unique().Annotations(entsql.IndexWhere("event_hash IS NOT NULL AND event_hash <> ''")),
  36. }
  37. }