| package schema |
|
|
| import ( |
| "github.com/Wei-Shaw/sub2api/ent/schema/mixins" |
| "github.com/Wei-Shaw/sub2api/internal/domain" |
|
|
| "entgo.io/ent" |
| "entgo.io/ent/dialect" |
| "entgo.io/ent/dialect/entsql" |
| "entgo.io/ent/schema" |
| "entgo.io/ent/schema/edge" |
| "entgo.io/ent/schema/field" |
| "entgo.io/ent/schema/index" |
| ) |
|
|
| |
| type User struct { |
| ent.Schema |
| } |
|
|
| func (User) Annotations() []schema.Annotation { |
| return []schema.Annotation{ |
| entsql.Annotation{Table: "users"}, |
| } |
| } |
|
|
| func (User) Mixin() []ent.Mixin { |
| return []ent.Mixin{ |
| mixins.TimeMixin{}, |
| mixins.SoftDeleteMixin{}, |
| } |
| } |
|
|
| func (User) Fields() []ent.Field { |
| return []ent.Field{ |
| |
| |
| field.String("email"). |
| MaxLen(255). |
| NotEmpty(), |
| field.String("password_hash"). |
| MaxLen(255). |
| NotEmpty(), |
| field.String("role"). |
| MaxLen(20). |
| Default(domain.RoleUser), |
| field.Float("balance"). |
| SchemaType(map[string]string{dialect.Postgres: "decimal(20,8)"}). |
| Default(0), |
| field.Int("concurrency"). |
| Default(5), |
| field.String("status"). |
| MaxLen(20). |
| Default(domain.StatusActive), |
|
|
| |
| field.String("username"). |
| MaxLen(100). |
| Default(""), |
| |
| field.String("notes"). |
| SchemaType(map[string]string{dialect.Postgres: "text"}). |
| Default(""), |
|
|
| |
| field.String("totp_secret_encrypted"). |
| SchemaType(map[string]string{dialect.Postgres: "text"}). |
| Optional(). |
| Nillable(), |
| field.Bool("totp_enabled"). |
| Default(false), |
| field.Time("totp_enabled_at"). |
| Optional(). |
| Nillable(), |
|
|
| |
| field.Int64("sora_storage_quota_bytes"). |
| Default(0), |
| field.Int64("sora_storage_used_bytes"). |
| Default(0), |
| } |
| } |
|
|
| func (User) Edges() []ent.Edge { |
| return []ent.Edge{ |
| edge.To("api_keys", APIKey.Type), |
| edge.To("redeem_codes", RedeemCode.Type), |
| edge.To("subscriptions", UserSubscription.Type), |
| edge.To("assigned_subscriptions", UserSubscription.Type), |
| edge.To("announcement_reads", AnnouncementRead.Type), |
| edge.To("allowed_groups", Group.Type). |
| Through("user_allowed_groups", UserAllowedGroup.Type), |
| edge.To("usage_logs", UsageLog.Type), |
| edge.To("attribute_values", UserAttributeValue.Type), |
| edge.To("promo_code_usages", PromoCodeUsage.Type), |
| } |
| } |
|
|
| func (User) Indexes() []ent.Index { |
| return []ent.Index{ |
| |
| index.Fields("status"), |
| index.Fields("deleted_at"), |
| } |
| } |
|
|