2024-07-23 14:48:37 +08:00
|
|
|
package migration
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"github.com/1Panel-dev/1Panel/agent/global"
|
|
|
|
|
"github.com/1Panel-dev/1Panel/agent/init/migration/migrations"
|
|
|
|
|
|
|
|
|
|
"github.com/go-gormigrate/gormigrate/v2"
|
2026-09-02 14:49:20 +08:00
|
|
|
"gorm.io/gorm"
|
2024-07-23 14:48:37 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func Init() {
|
2024-12-27 14:55:03 +08:00
|
|
|
InitAgentDB()
|
|
|
|
|
InitTaskDB()
|
2026-06-03 10:49:04 +08:00
|
|
|
InitAlertDB()
|
2024-12-27 14:55:03 +08:00
|
|
|
global.LOG.Info("Migration run successfully")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func InitAgentDB() {
|
2026-08-24 12:51:34 +08:00
|
|
|
m := gormigrate.New(global.DB, gormigrate.DefaultOptions, agentDBMigrations())
|
|
|
|
|
if err := m.Migrate(); err != nil {
|
|
|
|
|
global.LOG.Error(err)
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func agentDBMigrations() []*gormigrate.Migration {
|
|
|
|
|
return []*gormigrate.Migration{
|
2024-07-23 14:48:37 +08:00
|
|
|
migrations.AddTable,
|
2024-08-14 10:15:55 +08:00
|
|
|
migrations.AddMonitorTable,
|
2024-07-23 14:48:37 +08:00
|
|
|
migrations.InitSetting,
|
|
|
|
|
migrations.InitImageRepo,
|
|
|
|
|
migrations.InitDefaultCA,
|
|
|
|
|
migrations.InitPHPExtensions,
|
2025-01-14 14:27:51 +08:00
|
|
|
migrations.InitBackup,
|
2025-03-03 16:18:47 +08:00
|
|
|
migrations.InitDefault,
|
2025-03-04 17:58:57 +08:00
|
|
|
migrations.UpdateWebsiteExpireDate,
|
2025-06-23 18:37:37 +08:00
|
|
|
migrations.UpdateRuntime,
|
2025-06-27 16:47:26 +08:00
|
|
|
migrations.AddSnapshotRule,
|
2025-06-27 16:56:13 +08:00
|
|
|
migrations.UpdatePHPRuntime,
|
2025-06-27 17:25:23 +08:00
|
|
|
migrations.AddSnapshotIgnore,
|
2025-07-02 17:41:36 +08:00
|
|
|
migrations.InitAppLauncher,
|
2025-07-18 11:44:20 +08:00
|
|
|
migrations.AddTableAlert,
|
|
|
|
|
migrations.InitAlertConfig,
|
|
|
|
|
migrations.AddMethodToAlertLog,
|
2025-07-23 16:58:24 +08:00
|
|
|
migrations.AddMethodToAlertTask,
|
2025-07-30 18:54:51 +08:00
|
|
|
migrations.UpdateMcpServer,
|
2025-08-05 23:15:03 +08:00
|
|
|
migrations.InitCronjobGroup,
|
2025-08-19 13:41:15 +08:00
|
|
|
migrations.AddColumnToAlert,
|
2025-08-20 16:41:19 +08:00
|
|
|
migrations.UpdateWebsiteSSL,
|
2025-09-02 17:58:10 +08:00
|
|
|
migrations.AddQuickJump,
|
2025-09-04 15:21:33 +08:00
|
|
|
migrations.UpdateMcpServerAddType,
|
2026-06-16 16:47:27 +08:00
|
|
|
migrations.UpdateMcpServerGatewayConfig,
|
2025-09-05 17:39:36 +08:00
|
|
|
migrations.InitLocalSSHConn,
|
2025-09-08 22:08:42 +08:00
|
|
|
migrations.InitLocalSSHShow,
|
2025-09-15 16:27:11 +08:00
|
|
|
migrations.InitRecordStatus,
|
2025-09-17 17:51:59 +08:00
|
|
|
migrations.AddShowNameForQuickJump,
|
2026-03-12 17:31:33 +08:00
|
|
|
migrations.AddAgentQuickJump,
|
2025-09-23 11:56:04 +08:00
|
|
|
migrations.AddTimeoutForClam,
|
2025-09-28 18:16:18 +08:00
|
|
|
migrations.UpdateCronjobSpec,
|
|
|
|
|
migrations.UpdateWebsiteSSLAddColumn,
|
2025-10-27 18:04:17 +08:00
|
|
|
migrations.UpdateMonitorInterval,
|
2025-10-30 16:48:18 +08:00
|
|
|
migrations.AddMonitorProcess,
|
2025-11-05 18:08:25 +08:00
|
|
|
migrations.UpdateCronJob,
|
2025-11-24 15:55:14 +08:00
|
|
|
migrations.AddCommonDescription,
|
2025-11-17 00:30:55 -08:00
|
|
|
migrations.UpdateDatabase,
|
2025-11-24 15:59:15 +08:00
|
|
|
migrations.AddGPUMonitor,
|
2025-11-24 16:07:14 +08:00
|
|
|
migrations.UpdateDatabaseMysql,
|
2026-04-14 18:40:44 +08:00
|
|
|
migrations.AddDatabaseMongodb,
|
2025-12-01 14:33:38 +08:00
|
|
|
migrations.InitIptablesStatus,
|
2025-12-11 18:33:03 +08:00
|
|
|
migrations.UpdateWebsite,
|
2025-12-23 13:35:38 +08:00
|
|
|
migrations.AddisIPtoWebsiteSSL,
|
2025-12-29 17:35:36 +08:00
|
|
|
migrations.InitPingStatus,
|
2026-01-04 13:43:40 +08:00
|
|
|
migrations.UpdateApp,
|
2026-01-06 16:41:55 +08:00
|
|
|
migrations.AddCronjobArgs,
|
2026-01-21 18:02:19 +08:00
|
|
|
migrations.AddWebsiteAcmeAccountColumn,
|
2026-02-05 16:54:55 +08:00
|
|
|
migrations.AddAgentTables,
|
2026-02-24 18:26:02 +08:00
|
|
|
migrations.AddAgentCustomModelFields,
|
2026-02-25 10:35:29 +08:00
|
|
|
migrations.AddAppInstallSortOrder,
|
2026-02-25 13:53:45 +08:00
|
|
|
migrations.AddAgentAccountRememberAPIKey,
|
2026-02-28 10:38:35 +08:00
|
|
|
migrations.AddEditionSetting,
|
2026-03-02 14:53:58 +08:00
|
|
|
migrations.AddAgentTypeForAgents,
|
2026-03-03 11:00:53 +08:00
|
|
|
migrations.NormalizeAgentAccountVerifiedStatus,
|
2026-03-03 11:57:17 +08:00
|
|
|
migrations.NormalizeOllamaAccountAPIType,
|
2026-03-18 18:36:11 +08:00
|
|
|
migrations.InitAgentAccountModelPool,
|
2026-06-05 14:48:53 +08:00
|
|
|
migrations.AddAgentAccountMasterID,
|
2026-07-17 13:47:49 +08:00
|
|
|
migrations.NormalizeAgentAccountModelIDs,
|
|
|
|
|
migrations.AddAgentAccountVerifyModel,
|
|
|
|
|
migrations.AddAgentAccountAuthMode,
|
2026-03-19 15:25:19 +08:00
|
|
|
migrations.AddHostTable,
|
|
|
|
|
migrations.AddAITerminalSettings,
|
2026-03-24 18:56:30 +08:00
|
|
|
migrations.UpdateAgentQuickJumpTitle,
|
2026-03-25 14:02:17 +08:00
|
|
|
migrations.FixOpenclaw20260323HTTPPort,
|
2026-03-30 14:53:05 +08:00
|
|
|
migrations.AddAgentRemarkColumn,
|
2026-04-03 17:15:54 +08:00
|
|
|
migrations.AddAgentWebsiteBinding,
|
2026-04-03 22:11:01 +08:00
|
|
|
migrations.AddFileManageAISettings,
|
2026-04-09 17:38:38 +08:00
|
|
|
migrations.AddFileShareTable,
|
2026-04-16 19:11:05 +08:00
|
|
|
migrations.AddFileHistoryTable,
|
2026-05-26 14:18:17 +08:00
|
|
|
migrations.MigrateLegoV5,
|
2026-07-15 15:53:44 +08:00
|
|
|
migrations.AddMcpServerGatewayArgs,
|
2026-06-01 18:26:54 +08:00
|
|
|
migrations.InitFirewallPortWhiteList,
|
2026-07-16 14:24:38 +08:00
|
|
|
migrations.AddDatabaseUserTable,
|
2026-07-29 10:42:21 +08:00
|
|
|
migrations.AddBackupRecordArgs,
|
2026-07-29 16:41:43 +08:00
|
|
|
migrations.AddFtpIdentity,
|
2026-07-31 10:01:20 +08:00
|
|
|
migrations.AddWebsiteTemplateTable,
|
2026-07-30 09:39:47 +08:00
|
|
|
migrations.AddComposePinned,
|
2026-08-24 12:51:34 +08:00
|
|
|
migrations.AddFirewallRuleTable,
|
|
|
|
|
migrations.InitDockerPortGuardStatus,
|
2026-08-27 10:31:39 +08:00
|
|
|
migrations.NormalizeFirewallBackendSelections,
|
2026-10-08 18:19:30 +08:00
|
|
|
migrations.MigrateFirewallDescriptions,
|
2026-09-15 23:55:01 +08:00
|
|
|
migrations.MigrateFirewallPortWhitelistSources,
|
2026-09-28 18:32:12 +08:00
|
|
|
migrations.AddAcceleratorMetrics,
|
2026-09-29 15:19:30 +08:00
|
|
|
migrations.AddMonitorSettings,
|
2026-10-21 17:25:38 +08:00
|
|
|
migrations.AddNativeAgentInstalls,
|
2026-10-21 16:21:07 +08:00
|
|
|
migrations.AddQuickDirectory,
|
2026-10-23 18:39:22 +08:00
|
|
|
migrations.AddLocalModelAccountLink,
|
2026-10-26 14:03:40 +08:00
|
|
|
migrations.AddOllamaModelAccountSync,
|
2026-10-28 17:38:05 +08:00
|
|
|
migrations.AddContainerImageCheckUpdates,
|
2026-11-09 23:54:25 +08:00
|
|
|
migrations.AddCronjobURLItems,
|
2026-10-30 22:46:20 +08:00
|
|
|
migrations.AddModelQuickJump,
|
2026-11-02 18:22:58 +08:00
|
|
|
migrations.MigrateVMDatabase,
|
2026-11-05 17:08:15 +08:00
|
|
|
migrations.UpdateModelServicesQuickJumpRouter,
|
2026-11-06 00:44:50 +08:00
|
|
|
migrations.AddAgentAccountVerificationResult,
|
2026-11-13 14:04:11 +08:00
|
|
|
migrations.AddAgentAccountType,
|
2026-11-09 09:54:02 +08:00
|
|
|
migrations.AddGPUGroup,
|
2026-11-16 14:49:32 +08:00
|
|
|
migrations.AddAgentAccountStatus,
|
2024-07-23 14:48:37 +08:00
|
|
|
}
|
2024-12-27 14:55:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func InitTaskDB() {
|
|
|
|
|
m := gormigrate.New(global.TaskDB, gormigrate.DefaultOptions, []*gormigrate.Migration{
|
|
|
|
|
migrations.AddTaskTable,
|
|
|
|
|
})
|
|
|
|
|
if err := m.Migrate(); err != nil {
|
|
|
|
|
global.LOG.Error(err)
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
2024-07-23 14:48:37 +08:00
|
|
|
}
|
2026-06-03 10:49:04 +08:00
|
|
|
|
|
|
|
|
func InitAlertDB() {
|
2026-09-02 14:49:20 +08:00
|
|
|
if err := migrateAlertDB(global.AlertDB); err != nil {
|
2026-06-03 10:49:04 +08:00
|
|
|
global.LOG.Error(err)
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-09-02 14:49:20 +08:00
|
|
|
|
|
|
|
|
func migrateAlertDB(db *gorm.DB) error {
|
|
|
|
|
options := *gormigrate.DefaultOptions
|
|
|
|
|
options.UseTransaction = true
|
|
|
|
|
m := gormigrate.New(db, &options, []*gormigrate.Migration{
|
|
|
|
|
migrations.AddAlertConfigUIDAndSecret,
|
|
|
|
|
migrations.MigrateAlertMethodConfigIDs,
|
|
|
|
|
migrations.MigrateAlertLogTaskMethodConfigIDs,
|
|
|
|
|
migrations.AddAlertAuditUser,
|
|
|
|
|
migrations.AddAlertTaskDeliveryLogID,
|
|
|
|
|
})
|
|
|
|
|
return m.Migrate()
|
|
|
|
|
}
|