Ei kuvausta
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

config_invitation_code.go 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package tables
  2. import (
  3. "time"
  4. "git.x2erp.com/qdy/go-db/sqldef"
  5. )
  6. func init() {
  7. sqldef.AddRegistration(func(r *sqldef.Registry) {
  8. tb := sqldef.NewTable("config_invitation_code", "邀请码表").
  9. ID("id", 128).NotNull().Comment("主键").End().
  10. String("code", 64).NotNull().Comment("邀请码").End().
  11. String("tenant_id", 128).NotNull().Comment("租户ID").End().
  12. String("role_id", 128).NotNull().Comment("角色ID").End().
  13. DateTime("expires_at").NotNull().Comment("过期时间").End().
  14. TinyInt("used").NotNull().Default("0").Comment("是否已使用:0未使用,1已使用").End().
  15. String("used_by", 128).NotNull().Default("''").Comment("使用人用户ID").End().
  16. String("creator", 32).NotNull().Comment("创建人").End().
  17. DateTime("created_at").NotNull().Default("CURRENT_TIMESTAMP").Comment("创建时间").End()
  18. tb.AddIndex("idx_code", "code")
  19. tb.AddUniqueIndex("uk_code", "code")
  20. tb.AddIndex("idx_tenant_id", "tenant_id")
  21. tb.AddIndex("idx_expires_at", "expires_at")
  22. r.RegisterTable(tb.Build())
  23. })
  24. }
  25. type InvitationCode struct {
  26. Code string `gorm:"column:code;type:varchar(64);not null;primaryKey;comment:邀请码"`
  27. TenantID string `gorm:"column:tenant_id;type:varchar(128);not null;comment:租户ID"`
  28. RoleID string `gorm:"column:role_id;type:varchar(128);not null;comment:角色ID"`
  29. ExpiresAt time.Time `gorm:"column:expires_at;not null;comment:过期时间"`
  30. Used int8 `gorm:"column:used;type:tinyint;not null;default:0;comment:是否已使用:0未使用,1已使用"`
  31. UsedBy string `gorm:"column:used_by;type:varchar(128);not null;default:'';comment:使用人用户ID"`
  32. Creator string `gorm:"column:creator;type:varchar(32);not null;comment:创建人"`
  33. CreatedAt time.Time `gorm:"column:created_at;not null;default:CURRENT_TIMESTAMP;comment:创建时间"`
  34. }
  35. type InvitationCodeDB struct {
  36. ID string `db:"id" json:"id"`
  37. Code string `db:"code" json:"code"`
  38. TenantID string `db:"tenant_id" json:"tenantID"`
  39. RoleID string `db:"role_id" json:"roleID"`
  40. ExpiresAt time.Time `db:"expires_at" json:"expiresAt"`
  41. Used int8 `db:"used" json:"used"`
  42. UsedBy string `db:"used_by" json:"usedBy"`
  43. Creator string `db:"creator" json:"creator"`
  44. CreatedAt time.Time `db:"created_at" json:"createdAt"`
  45. }
  46. func (InvitationCode) TableName() string {
  47. return "config_invitation_code"
  48. }