forked from baron/baron-sso
33 lines
927 B
Go
33 lines
927 B
Go
package domain
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// TenantGroup represents a collection of tenants.
|
|
type TenantGroup struct {
|
|
ID string `gorm:"primaryKey;type:uuid;default:gen_random_uuid()" json:"id"`
|
|
Name string `gorm:"not null" json:"name"`
|
|
Slug string `gorm:"uniqueIndex;not null" json:"slug"`
|
|
Description string `json:"description"`
|
|
Tenants []Tenant `gorm:"foreignKey:TenantGroupID" json:"tenants,omitempty"`
|
|
Config JSONMap `gorm:"type:jsonb" json:"config,omitempty"`
|
|
CreatedAt time.Time `json:"createdAt"`
|
|
UpdatedAt time.Time `json:"updatedAt"`
|
|
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
|
}
|
|
|
|
func (tg *TenantGroup) TableName() string {
|
|
return "tenant_groups"
|
|
}
|
|
|
|
func (tg *TenantGroup) BeforeCreate(tx *gorm.DB) (err error) {
|
|
if tg.ID == "" {
|
|
tg.ID = uuid.NewString()
|
|
}
|
|
return
|
|
}
|