| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- package tables
-
- import (
- "time"
-
- "git.x2erp.com/qdy/go-db/sqldef"
- )
-
- func init() {
- sqldef.AddRegistration(func(r *sqldef.Registry) {
- tb := sqldef.NewTable("config_invitation_code", "邀请码表").
- ID("id", 128).NotNull().Comment("主键").End().
- String("code", 64).NotNull().Comment("邀请码").End().
- String("tenant_id", 128).NotNull().Comment("租户ID").End().
- String("role_id", 128).NotNull().Comment("角色ID").End().
- DateTime("expires_at").NotNull().Comment("过期时间").End().
- TinyInt("used").NotNull().Default("0").Comment("是否已使用:0未使用,1已使用").End().
- String("used_by", 128).NotNull().Default("''").Comment("使用人用户ID").End().
- String("creator", 32).NotNull().Comment("创建人").End().
- DateTime("created_at").NotNull().Default("CURRENT_TIMESTAMP").Comment("创建时间").End()
-
- tb.AddIndex("idx_code", "code")
- tb.AddUniqueIndex("uk_code", "code")
- tb.AddIndex("idx_tenant_id", "tenant_id")
- tb.AddIndex("idx_expires_at", "expires_at")
-
- r.RegisterTable(tb.Build())
- })
- }
-
- type InvitationCode struct {
- Code string `gorm:"column:code;type:varchar(64);not null;primaryKey;comment:邀请码"`
- TenantID string `gorm:"column:tenant_id;type:varchar(128);not null;comment:租户ID"`
- RoleID string `gorm:"column:role_id;type:varchar(128);not null;comment:角色ID"`
- ExpiresAt time.Time `gorm:"column:expires_at;not null;comment:过期时间"`
- Used int8 `gorm:"column:used;type:tinyint;not null;default:0;comment:是否已使用:0未使用,1已使用"`
- UsedBy string `gorm:"column:used_by;type:varchar(128);not null;default:'';comment:使用人用户ID"`
- Creator string `gorm:"column:creator;type:varchar(32);not null;comment:创建人"`
- CreatedAt time.Time `gorm:"column:created_at;not null;default:CURRENT_TIMESTAMP;comment:创建时间"`
- }
-
- type InvitationCodeDB struct {
- ID string `db:"id" json:"id"`
- Code string `db:"code" json:"code"`
- TenantID string `db:"tenant_id" json:"tenantID"`
- RoleID string `db:"role_id" json:"roleID"`
- ExpiresAt time.Time `db:"expires_at" json:"expiresAt"`
- Used int8 `db:"used" json:"used"`
- UsedBy string `db:"used_by" json:"usedBy"`
- Creator string `db:"creator" json:"creator"`
- CreatedAt time.Time `db:"created_at" json:"createdAt"`
- }
-
- func (InvitationCode) TableName() string {
- return "config_invitation_code"
- }
|