1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-01-19 16:29:17 +08:00

56 lines
1.2 KiB
Go
Raw Normal View History

2022-08-16 23:30:23 +08:00
package migrations
import (
"github.com/1Panel-dev/1Panel/app/model"
"github.com/go-gormigrate/gormigrate/v2"
"gorm.io/gorm"
)
var InitTable = &gormigrate.Migration{
ID: "20220803-init-table",
Migrate: func(tx *gorm.DB) error {
return tx.AutoMigrate(&model.User{})
},
}
var user = model.User{
2022-09-01 16:48:43 +08:00
Name: "admin", Email: "admin@fit2cloud.com", Password: "5WYEZ4XcitdomVvAyimt9WwJwBJJSbTTHncZoqyOraQ=",
2022-08-16 23:30:23 +08:00
}
var AddData = &gormigrate.Migration{
ID: "20200803-add-data",
Migrate: func(tx *gorm.DB) error {
return tx.Create(&user).Error
},
}
var AddTableOperationLog = &gormigrate.Migration{
ID: "20200809-add-table-operation-log",
Migrate: func(tx *gorm.DB) error {
return tx.AutoMigrate(&model.OperationLog{})
},
}
var AddTableHost = &gormigrate.Migration{
ID: "20200818-add-table-host",
Migrate: func(tx *gorm.DB) error {
2022-08-31 23:16:10 +08:00
if err := tx.AutoMigrate(&model.Host{}); err != nil {
return err
}
if err := tx.AutoMigrate(&model.Group{}); err != nil {
return err
}
if err := tx.AutoMigrate(&model.Command{}); err != nil {
return err
}
2022-09-01 16:48:43 +08:00
group := model.Group{
Name: "default", Type: "host",
}
if err := tx.Create(&group).Error; err != nil {
return err
}
2022-08-31 23:16:10 +08:00
return nil
},
}