chore: add device hierarchy
This commit is contained in:
@@ -26,8 +26,10 @@ func KickoffDatabase(workDir string) (*gorm.DB, error) {
|
|||||||
// try to use GORM automigrate if the schema changes
|
// try to use GORM automigrate if the schema changes
|
||||||
if err := db.AutoMigrate(
|
if err := db.AutoMigrate(
|
||||||
&Command{},
|
&Command{},
|
||||||
&Device{},
|
|
||||||
&File{},
|
&File{},
|
||||||
|
&Tenant{},
|
||||||
|
&Group{},
|
||||||
|
&Device{},
|
||||||
); err != nil {
|
); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,8 +38,26 @@ type AccessKey struct {
|
|||||||
Timestamps
|
Timestamps
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Tenant struct {
|
||||||
|
ID int `gorm:"primaryKey;not null;"`
|
||||||
|
TenantName string `gorm:"not null"`
|
||||||
|
TenantDescription string
|
||||||
|
Groups []Group `gorm:"foreignKey:TenantID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
|
||||||
|
Timestamps
|
||||||
|
}
|
||||||
|
|
||||||
|
type Group struct {
|
||||||
|
ID int `gorm:"primaryKey;not null;"`
|
||||||
|
TenantID uint `gorm:"not null;index"`
|
||||||
|
GroupName string `gorm:"not null;"`
|
||||||
|
GroupDescription string
|
||||||
|
Devices []Device `gorm:"foreignKey:GroupID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
|
||||||
|
Timestamps
|
||||||
|
}
|
||||||
|
|
||||||
type Device struct {
|
type Device struct {
|
||||||
ID int `gorm:"primaryKey;not null;"`
|
ID int `gorm:"primaryKey;not null;"`
|
||||||
|
GroupID uint `gorm:"not null;index"`
|
||||||
// Device type is meant as a field where can be specified what type of device this is
|
// Device type is meant as a field where can be specified what type of device this is
|
||||||
// eg Raspberry Pi, PC, things like that
|
// eg Raspberry Pi, PC, things like that
|
||||||
DeviceType string
|
DeviceType string
|
||||||
|
|||||||
Reference in New Issue
Block a user