2024-03-12 03:04:08 +00:00
|
|
|
package migrations
|
|
|
|
|
|
|
|
import (
|
2024-05-17 09:54:38 +00:00
|
|
|
"encoding/json"
|
2024-05-17 14:36:38 +00:00
|
|
|
|
2024-05-17 09:54:38 +00:00
|
|
|
"github.com/1Panel-dev/1Panel/backend/app/dto"
|
2024-03-12 03:04:08 +00:00
|
|
|
"github.com/1Panel-dev/1Panel/backend/app/model"
|
2024-04-08 05:48:07 +00:00
|
|
|
"github.com/1Panel-dev/1Panel/backend/global"
|
2024-03-12 03:04:08 +00:00
|
|
|
"github.com/go-gormigrate/gormigrate/v2"
|
|
|
|
"gorm.io/gorm"
|
|
|
|
)
|
|
|
|
|
|
|
|
var AddSnapshotIgnore = &gormigrate.Migration{
|
|
|
|
ID: "20240311-add-snapshot-ignore",
|
|
|
|
Migrate: func(tx *gorm.DB) error {
|
|
|
|
if err := tx.Create(&model.Setting{Key: "SnapshotIgnore", Value: "*.sock"}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
2024-03-14 10:22:07 +00:00
|
|
|
|
|
|
|
var AddDatabaseIsDelete = &gormigrate.Migration{
|
|
|
|
ID: "20240314-add-database-is-delete",
|
|
|
|
Migrate: func(tx *gorm.DB) error {
|
|
|
|
if err := tx.AutoMigrate(&model.DatabaseMysql{}, &model.DatabasePostgresql{}); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
2024-04-03 06:11:12 +00:00
|
|
|
|
|
|
|
var AddXpackHideMenu = &gormigrate.Migration{
|
|
|
|
ID: "20240328-add-xpack-hide-menu",
|
|
|
|
Migrate: func(tx *gorm.DB) error {
|
2024-04-03 09:27:55 +00:00
|
|
|
if err := tx.Create(&model.Setting{Key: "XpackHideMenu", Value: "{\"id\":\"1\",\"label\":\"/xpack\",\"isCheck\":true,\"title\":\"xpack.menu\",\"children\":[{\"id\":\"2\",\"title\":\"xpack.waf.name\",\"path\":\"/xpack/waf/dashboard\",\"label\":\"Dashboard\",\"isCheck\":true},{\"id\":\"3\",\"title\":\"xpack.tamper.tamper\",\"path\":\"/xpack/tamper\",\"label\":\"Tamper\",\"isCheck\":true},{\"id\":\"4\",\"title\":\"xpack.setting.setting\",\"path\":\"/xpack/setting\",\"label\":\"XSetting\",\"isCheck\":true}]}"}).Error; err != nil {
|
2024-04-03 06:11:12 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
2024-04-03 08:50:07 +00:00
|
|
|
|
|
|
|
var AddCronjobCommand = &gormigrate.Migration{
|
|
|
|
ID: "20240403-add-cronjob-command",
|
|
|
|
Migrate: func(tx *gorm.DB) error {
|
|
|
|
if err := tx.AutoMigrate(&model.Cronjob{}); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
2024-04-08 05:48:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var NewMonitorDB = &gormigrate.Migration{
|
|
|
|
ID: "20240408-new-monitor-db",
|
|
|
|
Migrate: func(tx *gorm.DB) error {
|
|
|
|
var (
|
|
|
|
bases []model.MonitorBase
|
|
|
|
ios []model.MonitorIO
|
|
|
|
networks []model.MonitorNetwork
|
|
|
|
)
|
2024-04-10 06:06:08 +00:00
|
|
|
_ = tx.Find(&bases).Error
|
|
|
|
_ = tx.Find(&ios).Error
|
|
|
|
_ = tx.Find(&networks).Error
|
|
|
|
|
2024-04-08 05:48:07 +00:00
|
|
|
if err := global.MonitorDB.AutoMigrate(&model.MonitorBase{}, &model.MonitorIO{}, &model.MonitorNetwork{}); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
_ = global.MonitorDB.Exec("DELETE FROM monitor_bases").Error
|
|
|
|
_ = global.MonitorDB.Exec("DELETE FROM monitor_ios").Error
|
|
|
|
_ = global.MonitorDB.Exec("DELETE FROM monitor_networks").Error
|
|
|
|
|
2024-04-10 06:06:08 +00:00
|
|
|
if len(bases) != 0 {
|
|
|
|
for i := 0; i <= len(bases)/200; i++ {
|
|
|
|
var itemData []model.MonitorBase
|
|
|
|
if 200*(i+1) <= len(bases) {
|
|
|
|
itemData = bases[200*i : 200*(i+1)]
|
|
|
|
} else {
|
|
|
|
itemData = bases[200*i:]
|
|
|
|
}
|
2024-04-18 14:38:06 +00:00
|
|
|
if len(itemData) != 0 {
|
|
|
|
if err := global.MonitorDB.Create(&itemData).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2024-04-10 06:06:08 +00:00
|
|
|
}
|
2024-04-08 05:48:07 +00:00
|
|
|
}
|
|
|
|
}
|
2024-04-10 06:06:08 +00:00
|
|
|
if len(ios) != 0 {
|
|
|
|
for i := 0; i <= len(ios)/200; i++ {
|
|
|
|
var itemData []model.MonitorIO
|
|
|
|
if 200*(i+1) <= len(ios) {
|
|
|
|
itemData = ios[200*i : 200*(i+1)]
|
|
|
|
} else {
|
|
|
|
itemData = ios[200*i:]
|
|
|
|
}
|
2024-04-18 14:38:06 +00:00
|
|
|
if len(itemData) != 0 {
|
|
|
|
if err := global.MonitorDB.Create(&itemData).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2024-04-10 06:06:08 +00:00
|
|
|
}
|
2024-04-08 05:48:07 +00:00
|
|
|
}
|
|
|
|
}
|
2024-04-10 06:06:08 +00:00
|
|
|
if len(networks) != 0 {
|
|
|
|
for i := 0; i <= len(networks)/200; i++ {
|
|
|
|
var itemData []model.MonitorNetwork
|
|
|
|
if 200*(i+1) <= len(networks) {
|
|
|
|
itemData = networks[200*i : 200*(i+1)]
|
|
|
|
} else {
|
|
|
|
itemData = networks[200*i:]
|
|
|
|
}
|
2024-04-18 14:38:06 +00:00
|
|
|
if len(itemData) != 0 {
|
|
|
|
if err := global.MonitorDB.Create(&itemData).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2024-04-10 06:06:08 +00:00
|
|
|
}
|
2024-04-08 05:48:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
2024-04-09 14:46:09 +00:00
|
|
|
|
|
|
|
var AddNoAuthSetting = &gormigrate.Migration{
|
|
|
|
ID: "20240328-add-no-auth-setting",
|
|
|
|
Migrate: func(tx *gorm.DB) error {
|
|
|
|
if err := tx.Create(&model.Setting{Key: "NoAuthSetting", Value: "200"}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
2024-04-11 06:16:10 +00:00
|
|
|
|
|
|
|
var UpdateXpackHideMenu = &gormigrate.Migration{
|
|
|
|
ID: "20240411-update-xpack-hide-menu",
|
|
|
|
Migrate: func(tx *gorm.DB) error {
|
|
|
|
if err := tx.Model(&model.Setting{}).Where("key", "XpackHideMenu").Updates(map[string]interface{}{"value": "{\"id\":\"1\",\"label\":\"/xpack\",\"isCheck\":true,\"title\":\"xpack.menu\",\"children\":[{\"id\":\"2\",\"title\":\"xpack.waf.name\",\"path\":\"/xpack/waf/dashboard\",\"label\":\"Dashboard\",\"isCheck\":true},{\"id\":\"3\",\"title\":\"xpack.tamper.tamper\",\"path\":\"/xpack/tamper\",\"label\":\"Tamper\",\"isCheck\":true},{\"id\":\"4\",\"title\":\"xpack.gpu.gpu\",\"path\":\"/xpack/gpu\",\"label\":\"GPU\",\"isCheck\":true},{\"id\":\"5\",\"title\":\"xpack.setting.setting\",\"path\":\"/xpack/setting\",\"label\":\"XSetting\",\"isCheck\":true}]}"}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
2024-04-15 07:10:24 +00:00
|
|
|
|
|
|
|
var AddMenuTabsSetting = &gormigrate.Migration{
|
|
|
|
ID: "20240415-add-menu-tabs-setting",
|
|
|
|
Migrate: func(tx *gorm.DB) error {
|
|
|
|
if err := tx.Create(&model.Setting{Key: "MenuTabs", Value: "disable"}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
2024-04-24 15:12:12 +00:00
|
|
|
|
|
|
|
var AddDeveloperSetting = &gormigrate.Migration{
|
|
|
|
ID: "20240423-add-developer-setting",
|
|
|
|
Migrate: func(tx *gorm.DB) error {
|
|
|
|
if err := tx.Create(&model.Setting{Key: "DeveloperMode", Value: "disable"}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
2024-05-07 10:26:34 +00:00
|
|
|
|
|
|
|
var AddWebsiteSSLColumn = &gormigrate.Migration{
|
|
|
|
ID: "20240508-update-website-ssl",
|
|
|
|
Migrate: func(tx *gorm.DB) error {
|
|
|
|
if err := tx.AutoMigrate(&model.WebsiteSSL{}); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
2024-05-15 15:02:35 +00:00
|
|
|
|
|
|
|
var AddRedisCommand = &gormigrate.Migration{
|
|
|
|
ID: "20240515-add-redis-command",
|
|
|
|
Migrate: func(tx *gorm.DB) error {
|
|
|
|
if err := tx.AutoMigrate(&model.RedisCommand{}); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
2024-05-17 09:54:38 +00:00
|
|
|
|
|
|
|
var AddMonitorMenu = &gormigrate.Migration{
|
|
|
|
ID: "20240517-update-xpack-hide-menu",
|
|
|
|
Migrate: func(tx *gorm.DB) error {
|
|
|
|
var (
|
|
|
|
setting model.Setting
|
|
|
|
menu dto.XpackHideMenu
|
|
|
|
)
|
|
|
|
tx.Model(&model.Setting{}).Where("key", "XpackHideMenu").First(&setting)
|
|
|
|
if err := json.Unmarshal([]byte(setting.Value), &menu); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
menu.Children = append(menu.Children, dto.XpackHideMenu{
|
|
|
|
ID: "6",
|
|
|
|
Title: "xpack.monitor.name",
|
|
|
|
Path: "/xpack/monitor/dashboard",
|
|
|
|
Label: "MonitorDashboard",
|
|
|
|
IsCheck: true,
|
|
|
|
})
|
|
|
|
data, err := json.Marshal(menu)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return tx.Model(&model.Setting{}).Where("key", "XpackHideMenu").Updates(map[string]interface{}{"value": string(data)}).Error
|
|
|
|
},
|
|
|
|
}
|
2024-05-17 14:36:38 +00:00
|
|
|
|
|
|
|
var AddFtp = &gormigrate.Migration{
|
2024-05-21 08:42:46 +00:00
|
|
|
ID: "20240521-add-ftp",
|
2024-05-17 14:36:38 +00:00
|
|
|
Migrate: func(tx *gorm.DB) error {
|
2024-05-21 08:42:46 +00:00
|
|
|
if err := tx.AutoMigrate(&model.Ftp{}, model.Website{}); err != nil {
|
2024-05-17 14:36:38 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
2024-05-29 03:05:09 +00:00
|
|
|
|
|
|
|
var AddProxy = &gormigrate.Migration{
|
|
|
|
ID: "20240528-add-proxy",
|
|
|
|
Migrate: func(tx *gorm.DB) error {
|
|
|
|
if err := tx.Create(&model.Setting{Key: "ProxyType", Value: ""}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := tx.Create(&model.Setting{Key: "ProxyUrl", Value: ""}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := tx.Create(&model.Setting{Key: "ProxyPort", Value: ""}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := tx.Create(&model.Setting{Key: "ProxyUser", Value: ""}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := tx.Create(&model.Setting{Key: "ProxyPasswd", Value: ""}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := tx.Create(&model.Setting{Key: "ProxyPasswdKeep", Value: ""}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
2024-06-04 08:48:31 +00:00
|
|
|
|
2024-06-15 14:28:03 +00:00
|
|
|
var AddForward = &gormigrate.Migration{
|
|
|
|
ID: "202400611-add-forward",
|
|
|
|
Migrate: func(tx *gorm.DB) error {
|
|
|
|
if err := tx.AutoMigrate(&model.Forward{}); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2024-06-04 08:48:31 +00:00
|
|
|
var AddCronJobColumn = &gormigrate.Migration{
|
|
|
|
ID: "20240524-add-cronjob-command",
|
|
|
|
Migrate: func(tx *gorm.DB) error {
|
|
|
|
if err := tx.AutoMigrate(&model.Cronjob{}); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
2024-06-20 14:18:07 +00:00
|
|
|
|
|
|
|
var AddShellColumn = &gormigrate.Migration{
|
|
|
|
ID: "20240620-update-website-ssl",
|
|
|
|
Migrate: func(tx *gorm.DB) error {
|
|
|
|
if err := tx.AutoMigrate(&model.WebsiteSSL{}); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
2024-06-24 05:52:42 +00:00
|
|
|
|
|
|
|
var AddClam = &gormigrate.Migration{
|
2024-07-02 09:25:25 +00:00
|
|
|
ID: "20240701-add-clam",
|
2024-06-24 05:52:42 +00:00
|
|
|
Migrate: func(tx *gorm.DB) error {
|
|
|
|
if err := tx.AutoMigrate(&model.Clam{}); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
2024-07-17 08:55:28 +00:00
|
|
|
|
|
|
|
var AddClamStatus = &gormigrate.Migration{
|
|
|
|
ID: "20240716-add-clam-status",
|
|
|
|
Migrate: func(tx *gorm.DB) error {
|
|
|
|
if err := tx.AutoMigrate(&model.Clam{}); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
2024-08-20 14:11:13 +00:00
|
|
|
|
|
|
|
var AddAlertMenu = &gormigrate.Migration{
|
|
|
|
ID: "20240706-update-xpack-hide-menu",
|
|
|
|
Migrate: func(tx *gorm.DB) error {
|
|
|
|
var (
|
|
|
|
setting model.Setting
|
|
|
|
menu dto.XpackHideMenu
|
|
|
|
)
|
|
|
|
tx.Model(&model.Setting{}).Where("key", "XpackHideMenu").First(&setting)
|
|
|
|
if err := json.Unmarshal([]byte(setting.Value), &menu); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
menu.Children = append(menu.Children, dto.XpackHideMenu{
|
|
|
|
ID: "7",
|
|
|
|
Title: "xpack.alert.alert",
|
|
|
|
Path: "/xpack/alert/dashboard",
|
|
|
|
Label: "XAlertDashboard",
|
|
|
|
IsCheck: true,
|
|
|
|
})
|
|
|
|
data, err := json.Marshal(menu)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return tx.Model(&model.Setting{}).Where("key", "XpackHideMenu").Updates(map[string]interface{}{"value": string(data)}).Error
|
|
|
|
},
|
|
|
|
}
|
2024-09-12 10:06:22 +00:00
|
|
|
|
|
|
|
var AddComposeColumn = &gormigrate.Migration{
|
|
|
|
ID: "20240906-add-compose-command",
|
|
|
|
Migrate: func(tx *gorm.DB) error {
|
|
|
|
if err := tx.AutoMigrate(&model.Compose{}); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
2024-10-21 14:47:14 +00:00
|
|
|
|
|
|
|
var AddAutoRestart = &gormigrate.Migration{
|
|
|
|
ID: "20241021-add-auto-restart",
|
|
|
|
Migrate: func(tx *gorm.DB) error {
|
|
|
|
if err := tx.Create(&model.Setting{Key: "AutoRestart", Value: "enable"}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
2024-11-21 14:09:00 +00:00
|
|
|
|
|
|
|
var AddApiInterfaceConfig = &gormigrate.Migration{
|
|
|
|
ID: "202411-add-api-interface-config",
|
|
|
|
Migrate: func(tx *gorm.DB) error {
|
|
|
|
if err := tx.Create(&model.Setting{Key: "ApiInterfaceStatus", Value: "disable"}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := tx.Create(&model.Setting{Key: "ApiKey", Value: ""}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := tx.Create(&model.Setting{Key: "IpWhiteList", Value: ""}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|