* Removed Tenanting from base objects as some models may be tenantless * Admins are naturally not restricted by tenants * Users *ARE* the tenants (for now) so they don't require a tenant ID either * User-owned models should all include the Tenanted model as their base * Created .Create and .Save methods attached to base model
31 lines
504 B
Go
31 lines
504 B
Go
package models
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type Base struct {
|
|
Uid uuid.UUID `gorm:"type:uuid;primary_key;<-:create"`
|
|
Created time.Time `gorm:"<-:create"`
|
|
Updated time.Time
|
|
Deleted time.Time `gorm:"index"`
|
|
}
|
|
|
|
func (b *Base) BeforeCreate(scope *gorm.DB) error {
|
|
b.Uid = uuid.New()
|
|
b.Created = time.Now()
|
|
return nil
|
|
}
|
|
|
|
func (b *Base) BeforeSave(scope *gorm.DB) error {
|
|
b.Updated = time.Now()
|
|
return nil
|
|
}
|
|
|
|
func (b *Base) Delete() {
|
|
b.Deleted = time.Now()
|
|
}
|