feat: 改软删除为硬删除

This commit is contained in:
ssongliu 2022-09-01 16:48:43 +08:00 committed by ssongliu
parent 3c770ce63b
commit 5b9372a148
6 changed files with 20 additions and 13 deletions

View File

@ -0,0 +1,9 @@
package model
import "time"
type BaseModel struct {
ID uint `gorm:"primarykey"`
CreatedAt time.Time
UpdatedAt time.Time
}

View File

@ -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"`
}

View File

@ -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"`
}

View File

@ -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"`

View File

@ -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"`

View File

@ -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
},
}