identity_adoption_decision.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package schema
  2. import (
  3. "time"
  4. "github.com/Wei-Shaw/sub2api/ent/schema/mixins"
  5. "entgo.io/ent"
  6. "entgo.io/ent/dialect"
  7. "entgo.io/ent/dialect/entsql"
  8. "entgo.io/ent/schema"
  9. "entgo.io/ent/schema/edge"
  10. "entgo.io/ent/schema/field"
  11. "entgo.io/ent/schema/index"
  12. )
  13. // IdentityAdoptionDecision stores the one-time profile adoption choice captured during a pending auth flow.
  14. type IdentityAdoptionDecision struct {
  15. ent.Schema
  16. }
  17. func (IdentityAdoptionDecision) Annotations() []schema.Annotation {
  18. return []schema.Annotation{
  19. entsql.Annotation{Table: "identity_adoption_decisions"},
  20. }
  21. }
  22. func (IdentityAdoptionDecision) Mixin() []ent.Mixin {
  23. return []ent.Mixin{
  24. mixins.TimeMixin{},
  25. }
  26. }
  27. func (IdentityAdoptionDecision) Fields() []ent.Field {
  28. return []ent.Field{
  29. field.Int64("pending_auth_session_id"),
  30. field.Int64("identity_id").
  31. Optional().
  32. Nillable(),
  33. field.Bool("adopt_display_name").
  34. Default(false),
  35. field.Bool("adopt_avatar").
  36. Default(false),
  37. field.Time("decided_at").
  38. Immutable().
  39. Default(time.Now).
  40. SchemaType(map[string]string{dialect.Postgres: "timestamptz"}),
  41. }
  42. }
  43. func (IdentityAdoptionDecision) Edges() []ent.Edge {
  44. return []ent.Edge{
  45. edge.From("pending_auth_session", PendingAuthSession.Type).
  46. Ref("adoption_decision").
  47. Field("pending_auth_session_id").
  48. Required().
  49. Unique(),
  50. edge.From("identity", AuthIdentity.Type).
  51. Ref("adoption_decisions").
  52. Field("identity_id").
  53. Unique(),
  54. }
  55. }
  56. func (IdentityAdoptionDecision) Indexes() []ent.Index {
  57. return []ent.Index{
  58. index.Fields("pending_auth_session_id").Unique(),
  59. index.Fields("identity_id"),
  60. }
  61. }