/
plan.go
41 lines (35 loc) · 1.03 KB
/
plan.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package model
import (
"errors"
"github.com/KubeOperator/KubeOperator/pkg/model/common"
"github.com/jinzhu/gorm"
uuid "github.com/satori/go.uuid"
)
var (
DeleteFailedByProject = "DELETE_FAILED_BY_PROJECT"
)
type Plan struct {
common.BaseModel
ID string `json:"id" gorm:"type:varchar(64)"`
Name string `json:"name" gorm:"type:varchar(64)"`
RegionID string `json:"regionId" grom:"type:varchar(64)"`
DeployTemplate string `json:"deployTemplate" grom:"type:varchar(64)"`
Vars string `json:"vars" gorm:"type text(65535)"`
Zones []Zone `json:"-" gorm:"many2many:plan_zones"`
Region Region `json:"-"`
}
func (p *Plan) BeforeCreate() (err error) {
p.ID = uuid.NewV4().String()
return err
}
func (p *Plan) BeforeDelete(tx *gorm.DB) (err error) {
var PlanResources []ProjectResource
err = tx.Where(ProjectResource{ResourceID: p.ID}).Find(&PlanResources).Error
if err != nil {
return err
}
if len(PlanResources) > 0 {
return errors.New(DeleteFailedByProject)
}
return err
}