2022-04-25 00:03:26 +00:00
|
|
|
package sql
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"runner-manager/config"
|
2022-04-27 16:56:28 +00:00
|
|
|
"runner-manager/runner/providers/common"
|
2022-04-25 00:03:26 +00:00
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
uuid "github.com/satori/go.uuid"
|
|
|
|
|
"gorm.io/gorm"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type Base struct {
|
|
|
|
|
ID uuid.UUID `gorm:"type:uuid;primary_key;"`
|
|
|
|
|
CreatedAt time.Time
|
|
|
|
|
UpdatedAt time.Time
|
|
|
|
|
DeletedAt gorm.DeletedAt `gorm:"index"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (b *Base) BeforeCreate(tx *gorm.DB) error {
|
2022-04-26 20:29:58 +00:00
|
|
|
emptyId := uuid.UUID{}
|
|
|
|
|
if b.ID != emptyId {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
2022-04-25 00:03:26 +00:00
|
|
|
b.ID = uuid.NewV4()
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type Tag struct {
|
|
|
|
|
Base
|
|
|
|
|
|
2022-04-26 20:29:58 +00:00
|
|
|
Name string `gorm:"type:varchar(64);uniqueIndex"`
|
|
|
|
|
Pools []*Pool `gorm:"many2many:pool_tags;"`
|
2022-04-25 00:03:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type Pool struct {
|
|
|
|
|
Base
|
|
|
|
|
|
|
|
|
|
ProviderName string `gorm:"index:idx_pool_type,unique"`
|
|
|
|
|
MaxRunners uint
|
|
|
|
|
MinIdleRunners uint
|
|
|
|
|
Image string `gorm:"index:idx_pool_type,unique"`
|
|
|
|
|
Flavor string `gorm:"index:idx_pool_type,unique"`
|
|
|
|
|
OSType config.OSType
|
|
|
|
|
OSArch config.OSArch
|
2022-04-26 20:29:58 +00:00
|
|
|
Tags []*Tag `gorm:"many2many:pool_tags;"`
|
2022-04-27 16:56:28 +00:00
|
|
|
Enabled bool
|
2022-04-26 20:29:58 +00:00
|
|
|
|
|
|
|
|
RepoID uuid.UUID
|
|
|
|
|
Repository Repository `gorm:"foreignKey:RepoID"`
|
|
|
|
|
|
|
|
|
|
OrgID uuid.UUID
|
|
|
|
|
Organization Organization `gorm:"foreignKey:OrgID"`
|
2022-04-27 16:56:28 +00:00
|
|
|
|
|
|
|
|
Instances []Instance `gorm:"foreignKey:PoolID"`
|
2022-04-25 00:03:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type Repository struct {
|
|
|
|
|
Base
|
|
|
|
|
|
|
|
|
|
Owner string `gorm:"index:idx_owner,unique"`
|
|
|
|
|
Name string `gorm:"index:idx_owner,unique"`
|
|
|
|
|
WebhookSecret []byte
|
2022-04-26 20:29:58 +00:00
|
|
|
Pools []Pool `gorm:"foreignKey:RepoID"`
|
2022-04-25 00:03:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type Organization struct {
|
|
|
|
|
Base
|
|
|
|
|
|
|
|
|
|
Name string `gorm:"uniqueIndex"`
|
|
|
|
|
WebhookSecret []byte
|
2022-04-26 20:29:58 +00:00
|
|
|
Pools []Pool `gorm:"foreignKey:OrgID"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type Address struct {
|
|
|
|
|
Base
|
|
|
|
|
|
|
|
|
|
Address string
|
|
|
|
|
Type string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type Instance struct {
|
|
|
|
|
Base
|
|
|
|
|
|
2022-04-27 16:56:28 +00:00
|
|
|
ProviderID string `gorm:"uniqueIndex"`
|
|
|
|
|
Name string `gorm:"uniqueIndex"`
|
|
|
|
|
OSType config.OSType
|
|
|
|
|
OSArch config.OSArch
|
|
|
|
|
OSName string
|
|
|
|
|
OSVersion string
|
|
|
|
|
Addresses []Address `gorm:"foreignKey:id"`
|
|
|
|
|
Status common.InstanceStatus
|
|
|
|
|
RunnerStatus common.RunnerStatus
|
|
|
|
|
CallbackURL string
|
|
|
|
|
|
|
|
|
|
PoolID uuid.UUID
|
|
|
|
|
Pool Pool `gorm:"foreignKey:PoolID"`
|
2022-04-25 00:03:26 +00:00
|
|
|
}
|