mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-10-10 23:47:39 +08:00
fix: Simplify the migration information (#8614)
This commit is contained in:
parent
d3dfd72a39
commit
db02dbed16
4 changed files with 67 additions and 290 deletions
|
@ -22,19 +22,8 @@ func InitAgentDB() {
|
|||
migrations.InitDefaultCA,
|
||||
migrations.InitPHPExtensions,
|
||||
migrations.InitBackup,
|
||||
migrations.UpdateAppTag,
|
||||
migrations.UpdateApp,
|
||||
migrations.AddOllamaModel,
|
||||
migrations.UpdateSettingStatus,
|
||||
migrations.InitDefault,
|
||||
migrations.UpdateWebsiteExpireDate,
|
||||
migrations.AddLocalSSHSetting,
|
||||
migrations.AddAppIgnore,
|
||||
migrations.UpdateWebsite,
|
||||
migrations.UpdateWebsiteAcmeAccount,
|
||||
migrations.UpdateAppInstall,
|
||||
migrations.AddMcpServer,
|
||||
migrations.InitLanguageSetting,
|
||||
})
|
||||
if err := m.Migrate(); err != nil {
|
||||
global.LOG.Error(err)
|
||||
|
|
|
@ -29,6 +29,7 @@ var AddTable = &gormigrate.Migration{
|
|||
&model.Tag{},
|
||||
&model.App{},
|
||||
&model.AppLauncher{},
|
||||
&model.OllamaModel{},
|
||||
&model.BackupAccount{},
|
||||
&model.BackupRecord{},
|
||||
&model.Clam{},
|
||||
|
@ -115,6 +116,12 @@ var InitSetting = &gormigrate.Migration{
|
|||
if err := tx.Create(&model.Setting{Key: "SystemStatus", Value: "Free"}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if err := tx.Create(&model.Setting{Key: "Language", Value: "zh"}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if err := tx.Create(&model.Setting{Key: "SystemIP", Value: ""}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := tx.Create(&model.Setting{Key: "LocalTime", Value: ""}).Error; err != nil {
|
||||
return err
|
||||
|
@ -139,7 +146,7 @@ var InitSetting = &gormigrate.Migration{
|
|||
if err := tx.Create(&model.Setting{Key: "DefaultNetwork", Value: "all"}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if err := tx.Create(&model.Setting{Key: "MonitorStatus", Value: "enable"}).Error; err != nil {
|
||||
if err := tx.Create(&model.Setting{Key: "MonitorStatus", Value: constant.StatusEnable}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if err := tx.Create(&model.Setting{Key: "MonitorStoreDays", Value: "7"}).Error; err != nil {
|
||||
|
@ -159,13 +166,17 @@ var InitSetting = &gormigrate.Migration{
|
|||
return err
|
||||
}
|
||||
|
||||
if err := tx.Create(&model.Setting{Key: "FileRecycleBin", Value: "enable"}).Error; err != nil {
|
||||
if err := tx.Create(&model.Setting{Key: "FileRecycleBin", Value: constant.StatusEnable}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if err := tx.Create(&model.Setting{Key: "SnapshotIgnore", Value: "*.sock"}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := tx.Create(&model.Setting{Key: "LocalSSHConn", Value: ""}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
@ -248,49 +259,6 @@ var InitBackup = &gormigrate.Migration{
|
|||
},
|
||||
}
|
||||
|
||||
var UpdateAppTag = &gormigrate.Migration{
|
||||
ID: "20250206-update-app-tag",
|
||||
Migrate: func(tx *gorm.DB) error {
|
||||
if err := tx.AutoMigrate(&model.Tag{}); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
var UpdateApp = &gormigrate.Migration{
|
||||
ID: "20250206-update-app",
|
||||
Migrate: func(tx *gorm.DB) error {
|
||||
if err := tx.AutoMigrate(&model.App{}); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
var AddOllamaModel = &gormigrate.Migration{
|
||||
ID: "20250218-add-ollama-model",
|
||||
Migrate: func(tx *gorm.DB) error {
|
||||
if err := tx.AutoMigrate(&model.OllamaModel{}); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
var UpdateSettingStatus = &gormigrate.Migration{
|
||||
ID: "20250227-update-setting-status",
|
||||
Migrate: func(tx *gorm.DB) error {
|
||||
if err := tx.Model(model.Setting{}).Where("value = ?", "enable").Update("value", constant.StatusEnable).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if err := tx.Model(model.Setting{}).Where("value = ?", "disable").Update("value", constant.StatusDisable).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
var InitDefault = &gormigrate.Migration{
|
||||
ID: "20250301-init-default",
|
||||
Migrate: func(tx *gorm.DB) error {
|
||||
|
@ -314,85 +282,3 @@ var UpdateWebsiteExpireDate = &gormigrate.Migration{
|
|||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
var AddLocalSSHSetting = &gormigrate.Migration{
|
||||
ID: "20250417-add-local-ssh-setting",
|
||||
Migrate: func(tx *gorm.DB) error {
|
||||
if err := tx.Create(&model.Setting{Key: "LocalSSHConn", Value: ""}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
var AddAppIgnore = &gormigrate.Migration{
|
||||
ID: "20250408-add-app-ignore",
|
||||
Migrate: func(tx *gorm.DB) error {
|
||||
if err := tx.AutoMigrate(&model.AppIgnoreUpgrade{}); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
var UpdateWebsite = &gormigrate.Migration{
|
||||
ID: "20250424-update-website",
|
||||
Migrate: func(tx *gorm.DB) error {
|
||||
if err := tx.AutoMigrate(&model.Website{}); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
var UpdateWebsiteAcmeAccount = &gormigrate.Migration{
|
||||
ID: "20250425-update-websiteAcmeAccount",
|
||||
Migrate: func(tx *gorm.DB) error {
|
||||
if err := tx.AutoMigrate(&model.WebsiteAcmeAccount{}); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
var UpdateAppInstall = &gormigrate.Migration{
|
||||
ID: "20250425-update-appInstall",
|
||||
Migrate: func(tx *gorm.DB) error {
|
||||
if err := tx.AutoMigrate(&model.AppInstall{}); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
var AddMcpServer = &gormigrate.Migration{
|
||||
ID: "20250428-add-mcpServer",
|
||||
Migrate: func(tx *gorm.DB) error {
|
||||
if err := tx.AutoMigrate(&model.McpServer{}); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
var InitLanguageSetting = &gormigrate.Migration{
|
||||
ID: "20240722-init-language-setting",
|
||||
Migrate: func(tx *gorm.DB) error {
|
||||
var langSetting model.Setting
|
||||
_ = tx.Where("key = ?", "Language").First(&langSetting)
|
||||
if langSetting.ID == 0 {
|
||||
if err := tx.Create(&model.Setting{Key: "Language", Value: "zh"}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
var systemIPSetting model.Setting
|
||||
_ = tx.Where("key = ?", "SystemIP").First(&systemIPSetting)
|
||||
if systemIPSetting.ID == 0 {
|
||||
if err := tx.Create(&model.Setting{Key: "SystemIP", Value: ""}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
|
|
@ -14,18 +14,8 @@ func Init() {
|
|||
migrations.InitOneDrive,
|
||||
migrations.InitHost,
|
||||
migrations.InitTerminalSetting,
|
||||
migrations.InitBackup,
|
||||
migrations.InitGoogle,
|
||||
migrations.AddTaskDB,
|
||||
migrations.UpdateSettingStatus,
|
||||
migrations.RemoveLocalBackup,
|
||||
migrations.AddMFAInterval,
|
||||
migrations.UpdateXpackHideMemu,
|
||||
migrations.AddSystemIP,
|
||||
migrations.InitScriptLibrary,
|
||||
migrations.AddOperationNode,
|
||||
migrations.AddScriptVersion,
|
||||
migrations.AddAppStoreSetting,
|
||||
})
|
||||
if err := m.Migrate(); err != nil {
|
||||
global.LOG.Error(err)
|
||||
|
|
|
@ -95,8 +95,7 @@ var InitSetting = &gormigrate.Migration{
|
|||
if err := tx.Create(&model.Setting{Key: "ProxyPasswdKeep", Value: ""}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
val := `{"id":"1","label":"/xpack","isCheck":true,"title":"xpack.menu","children":[{"id":"2","label":"Dashboard","isCheck":true,"title":"xpack.waf.name","path":"/xpack/waf/dashboard"},{"id":"3","label":"Tamper","isCheck":true,"title":"xpack.tamper.tamper","path":"/xpack/tamper"},{"id":"4","label":"GPU","isCheck":true,"title":"xpack.gpu.gpu","path":"/xpack/gpu"},{"id":"5","label":"XSetting","isCheck":true,"title":"xpack.setting.setting","path":"/xpack/setting"},{"id":"6","label":"MonitorDashboard","isCheck":true,"title":"xpack.monitor.name","path":"/xpack/monitor/dashboard"},{"id":"7","label":"XAlertDashboard","isCheck":true,"title":"xpack.alert.alert","path":"/xpack/alert/dashboard"},{"id":"8","label":"Node","isCheck":true,"title":"xpack.node.nodeManagement","path":"/xpack/node"}]}`
|
||||
if err := tx.Create(&model.Setting{Key: "HideMenu", Value: val}).Error; err != nil {
|
||||
if err := tx.Create(&model.Setting{Key: "HideMenu", Value: helper.LoadMenus()}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -118,6 +117,9 @@ var InitSetting = &gormigrate.Migration{
|
|||
if err := tx.Create(&model.Setting{Key: "ExpirationDays", Value: "0"}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if err := tx.Create(&model.Setting{Key: "SystemIP", Value: ""}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if err := tx.Create(&model.Setting{Key: "ComplexityVerification", Value: constant.StatusEnable}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -127,6 +129,9 @@ var InitSetting = &gormigrate.Migration{
|
|||
if err := tx.Create(&model.Setting{Key: "MFASecret", Value: ""}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if err := tx.Create(&model.Setting{Key: "MFAInterval", Value: "30"}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if err := tx.Create(&model.Setting{Key: "SystemVersion", Value: global.CONF.Base.Version}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -160,46 +165,17 @@ var InitSetting = &gormigrate.Migration{
|
|||
if err := tx.Create(&model.Setting{Key: "ApiKeyValidityTime", Value: "120"}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
if err := tx.Create(&model.Setting{Key: "ScriptVersion", Value: ""}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var InitHost = &gormigrate.Migration{
|
||||
ID: "20240816-init-host",
|
||||
Migrate: func(tx *gorm.DB) error {
|
||||
if err := tx.Create(&model.Group{Name: "Default", Type: "host", IsDefault: true}).Error; err != nil {
|
||||
if err := tx.Create(&model.Setting{Key: "UninstallDeleteImage", Value: "Disable"}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if err := tx.Create(&model.Group{Name: "Default", Type: "node", IsDefault: true}).Error; err != nil {
|
||||
if err := tx.Create(&model.Setting{Key: "UpgradeBackup", Value: "Enable"}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if err := tx.Create(&model.Group{Name: "Default", Type: "command", IsDefault: true}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if err := tx.Create(&model.Group{Name: "Default", Type: "website", IsDefault: true}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if err := tx.Create(&model.Group{Name: "Default", Type: "redis", IsDefault: true}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
var InitOneDrive = &gormigrate.Migration{
|
||||
ID: "20240808-init-one-drive",
|
||||
Migrate: func(tx *gorm.DB) error {
|
||||
if err := tx.Create(&model.Setting{Key: "OneDriveID", Value: "MDEwOTM1YTktMWFhOS00ODU0LWExZGMtNmU0NWZlNjI4YzZi"}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if err := tx.Create(&model.Setting{Key: "OneDriveSc", Value: "akpuOFF+YkNXOU1OLWRzS1ZSRDdOcG1LT2ZRM0RLNmdvS1RkVWNGRA=="}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if err := tx.Create(&model.BackupAccount{
|
||||
Name: "localhost",
|
||||
Type: "LOCAL",
|
||||
Vars: fmt.Sprintf("{\"dir\":\"%s\"}", path.Join(global.CONF.Base.InstallDir, "1panel/backup")),
|
||||
}).Error; err != nil {
|
||||
if err := tx.Create(&model.Setting{Key: "UninstallDeleteBackup", Value: "Disable"}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
@ -234,10 +210,48 @@ var InitTerminalSetting = &gormigrate.Migration{
|
|||
},
|
||||
}
|
||||
|
||||
var InitBackup = &gormigrate.Migration{
|
||||
ID: "20241107-init-backup",
|
||||
var InitHost = &gormigrate.Migration{
|
||||
ID: "20240816-init-host",
|
||||
Migrate: func(tx *gorm.DB) error {
|
||||
return tx.AutoMigrate(&model.BackupAccount{})
|
||||
if err := tx.Create(&model.Group{Name: "Default", Type: "host", IsDefault: true}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if err := tx.Create(&model.Group{Name: "Default", Type: "node", IsDefault: true}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if err := tx.Create(&model.Group{Name: "Default", Type: "command", IsDefault: true}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if err := tx.Create(&model.Group{Name: "Default", Type: "website", IsDefault: true}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if err := tx.Create(&model.Group{Name: "Default", Type: "redis", IsDefault: true}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if err := tx.Create(&model.Group{Name: "Default", Type: "script", IsDefault: true}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
var InitOneDrive = &gormigrate.Migration{
|
||||
ID: "20240808-init-one-drive",
|
||||
Migrate: func(tx *gorm.DB) error {
|
||||
if err := tx.Create(&model.Setting{Key: "OneDriveID", Value: "MDEwOTM1YTktMWFhOS00ODU0LWExZGMtNmU0NWZlNjI4YzZi"}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if err := tx.Create(&model.Setting{Key: "OneDriveSc", Value: "akpuOFF+YkNXOU1OLWRzS1ZSRDdOcG1LT2ZRM0RLNmdvS1RkVWNGRA=="}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if err := tx.Create(&model.BackupAccount{
|
||||
Name: "localhost",
|
||||
Type: "LOCAL",
|
||||
Vars: fmt.Sprintf("{\"dir\":\"%s\"}", path.Join(global.CONF.Base.InstallDir, "1panel/backup")),
|
||||
}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -262,105 +276,3 @@ var AddTaskDB = &gormigrate.Migration{
|
|||
)
|
||||
},
|
||||
}
|
||||
|
||||
var UpdateSettingStatus = &gormigrate.Migration{
|
||||
ID: "20241218-update-setting-status",
|
||||
Migrate: func(tx *gorm.DB) error {
|
||||
if err := tx.Model(model.Setting{}).Where("value = ?", "enable").Update("value", constant.StatusEnable).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if err := tx.Model(model.Setting{}).Where("value = ?", "disable").Update("value", constant.StatusDisable).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
var RemoveLocalBackup = &gormigrate.Migration{
|
||||
ID: "20250109-remove-local-backup",
|
||||
Migrate: func(tx *gorm.DB) error {
|
||||
if err := tx.Where("`type` = ?", constant.Local).Delete(&model.BackupAccount{}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
var AddMFAInterval = &gormigrate.Migration{
|
||||
ID: "20250207-add-mfa-interval",
|
||||
Migrate: func(tx *gorm.DB) error {
|
||||
if err := tx.Create(&model.Setting{Key: "MFAInterval", Value: "30"}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
var UpdateXpackHideMemu = &gormigrate.Migration{
|
||||
ID: "20250511-update-xpack-hide-menu",
|
||||
Migrate: func(tx *gorm.DB) error {
|
||||
if err := tx.Model(&model.Setting{}).Where("key = ?", "HideMenu").Updates(map[string]interface{}{"key": "HideMenu", "value": helper.LoadMenus()}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
var AddSystemIP = &gormigrate.Migration{
|
||||
ID: "20250227-add-system-ip",
|
||||
Migrate: func(tx *gorm.DB) error {
|
||||
if err := tx.Create(&model.Setting{Key: "SystemIP", Value: ""}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
var InitScriptLibrary = &gormigrate.Migration{
|
||||
ID: "20250408-init-script-library",
|
||||
Migrate: func(tx *gorm.DB) error {
|
||||
if err := tx.AutoMigrate(&model.ScriptLibrary{}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := tx.Create(&model.Group{Name: "Default", Type: "script", IsDefault: true}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
var AddOperationNode = &gormigrate.Migration{
|
||||
ID: "20250321-add-operation-node",
|
||||
Migrate: func(tx *gorm.DB) error {
|
||||
if err := tx.AutoMigrate(&model.OperationLog{}); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
var AddScriptVersion = &gormigrate.Migration{
|
||||
ID: "20250410-add-script-version",
|
||||
Migrate: func(tx *gorm.DB) error {
|
||||
if err := tx.Create(&model.Setting{Key: "ScriptVersion", Value: ""}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
var AddAppStoreSetting = &gormigrate.Migration{
|
||||
ID: "20250506-add-appstore-setting",
|
||||
Migrate: func(tx *gorm.DB) error {
|
||||
if err := tx.Create(&model.Setting{Key: "UninstallDeleteImage", Value: "Disable"}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if err := tx.Create(&model.Setting{Key: "UpgradeBackup", Value: "Enable"}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if err := tx.Create(&model.Setting{Key: "UninstallDeleteBackup", Value: "Disable"}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue