diff --git a/backend/app/model/base.go b/backend/app/model/base.go new file mode 100644 index 000000000..fd9d09b3a --- /dev/null +++ b/backend/app/model/base.go @@ -0,0 +1,9 @@ +package model + +import "time" + +type BaseModel struct { + ID uint `gorm:"primarykey"` + CreatedAt time.Time + UpdatedAt time.Time +} diff --git a/backend/app/model/command.go b/backend/app/model/command.go index 4f7864914..482ca9e28 100644 --- a/backend/app/model/command.go +++ b/backend/app/model/command.go @@ -1,9 +1,7 @@ package model -import "gorm.io/gorm" - type Command struct { - gorm.Model + BaseModel Name string `gorm:"type:varchar(64);unique;not null" json:"name"` Command string `gorm:"type:varchar(256);not null" json:"command"` } diff --git a/backend/app/model/group.go b/backend/app/model/group.go index 46d53c48a..8a9fe00b1 100644 --- a/backend/app/model/group.go +++ b/backend/app/model/group.go @@ -1,9 +1,7 @@ package model -import "gorm.io/gorm" - type Group struct { - gorm.Model + BaseModel Name string `gorm:"type:varchar(64);not null" json:"name"` Type string `gorm:"type:varchar(16);not null" json:"type"` } diff --git a/backend/app/model/host.go b/backend/app/model/host.go index 4b813135d..39d5e90c3 100644 --- a/backend/app/model/host.go +++ b/backend/app/model/host.go @@ -1,9 +1,7 @@ package model -import "gorm.io/gorm" - type Host struct { - gorm.Model + BaseModel GroupBelong string `gorm:"type:varchar(64);not null" json:"groupBelong"` Name string `gorm:"type:varchar(64);unique;not null" json:"name"` Addr string `gorm:"type:varchar(16);unique;not null" json:"addr"` diff --git a/backend/app/model/operate_log.go b/backend/app/model/operate_log.go index ae48fa347..7683b8a4f 100644 --- a/backend/app/model/operate_log.go +++ b/backend/app/model/operate_log.go @@ -2,12 +2,10 @@ package model import ( "time" - - "gorm.io/gorm" ) type OperationLog struct { - gorm.Model + BaseModel Group string `gorm:"type:varchar(64)" json:"group"` Source string `gorm:"type:varchar(64)" json:"source"` Action string `gorm:"type:varchar(64)" json:"action"` diff --git a/backend/init/migration/migrations/init.go b/backend/init/migration/migrations/init.go index defaf0ca5..88fd8cb71 100644 --- a/backend/init/migration/migrations/init.go +++ b/backend/init/migration/migrations/init.go @@ -15,7 +15,7 @@ var InitTable = &gormigrate.Migration{ } var user = model.User{ - Name: "admin", Email: "admin@fit2cloud.com", Password: "Calong@2015", + Name: "admin", Email: "admin@fit2cloud.com", Password: "5WYEZ4XcitdomVvAyimt9WwJwBJJSbTTHncZoqyOraQ=", } var AddData = &gormigrate.Migration{ @@ -44,6 +44,12 @@ var AddTableHost = &gormigrate.Migration{ if err := tx.AutoMigrate(&model.Command{}); err != nil { return err } + group := model.Group{ + Name: "default", Type: "host", + } + if err := tx.Create(&group).Error; err != nil { + return err + } return nil }, }