2022-08-16 23:30:23 +08:00
|
|
|
package migrations
|
|
|
|
|
|
|
|
import (
|
2023-01-29 16:38:34 +08:00
|
|
|
"fmt"
|
2022-09-09 17:17:02 +08:00
|
|
|
"time"
|
|
|
|
|
2022-10-17 16:32:31 +08:00
|
|
|
"github.com/1Panel-dev/1Panel/backend/app/model"
|
2022-12-18 23:00:24 +08:00
|
|
|
"github.com/1Panel-dev/1Panel/backend/constant"
|
2023-01-29 16:38:34 +08:00
|
|
|
"github.com/1Panel-dev/1Panel/backend/global"
|
2023-02-10 16:10:40 +08:00
|
|
|
"github.com/1Panel-dev/1Panel/backend/utils/common"
|
2022-08-16 23:30:23 +08:00
|
|
|
|
|
|
|
"github.com/go-gormigrate/gormigrate/v2"
|
|
|
|
"gorm.io/gorm"
|
|
|
|
)
|
|
|
|
|
|
|
|
var AddTableOperationLog = &gormigrate.Migration{
|
|
|
|
ID: "20200809-add-table-operation-log",
|
|
|
|
Migrate: func(tx *gorm.DB) error {
|
2022-11-15 17:20:57 +08:00
|
|
|
return tx.AutoMigrate(&model.OperationLog{}, &model.LoginLog{})
|
2022-08-16 23:30:23 +08:00
|
|
|
},
|
|
|
|
}
|
2022-08-18 18:54:21 +08:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
2023-01-03 14:37:17 +08:00
|
|
|
host := model.Host{
|
|
|
|
Name: "localhost", Addr: "127.0.0.1", User: "root", Port: 22, GroupBelong: "default",
|
|
|
|
}
|
|
|
|
if err := tx.Create(&host).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-08-31 23:16:10 +08:00
|
|
|
return nil
|
2022-08-18 18:54:21 +08:00
|
|
|
},
|
|
|
|
}
|
2022-09-08 11:39:14 +08:00
|
|
|
|
2022-09-15 10:44:43 +08:00
|
|
|
var AddTableMonitor = &gormigrate.Migration{
|
2022-09-08 11:39:14 +08:00
|
|
|
ID: "20200905-add-table-monitor",
|
|
|
|
Migrate: func(tx *gorm.DB) error {
|
|
|
|
return tx.AutoMigrate(&model.MonitorBase{}, &model.MonitorIO{}, &model.MonitorNetwork{})
|
|
|
|
},
|
|
|
|
}
|
2022-09-15 10:44:43 +08:00
|
|
|
|
|
|
|
var AddTableSetting = &gormigrate.Migration{
|
|
|
|
ID: "20200908-add-table-setting",
|
|
|
|
Migrate: func(tx *gorm.DB) error {
|
|
|
|
if err := tx.AutoMigrate(&model.Setting{}); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-11-21 15:20:04 +08:00
|
|
|
if err := tx.Create(&model.Setting{Key: "UserName", Value: ""}).Error; err != nil {
|
2022-09-15 10:44:43 +08:00
|
|
|
return err
|
|
|
|
}
|
2022-11-21 15:20:04 +08:00
|
|
|
if err := tx.Create(&model.Setting{Key: "Password", Value: ""}).Error; err != nil {
|
2022-09-15 10:44:43 +08:00
|
|
|
return err
|
|
|
|
}
|
2022-11-21 15:20:04 +08:00
|
|
|
if err := tx.Create(&model.Setting{Key: "Email", Value: ""}).Error; err != nil {
|
2022-09-15 10:44:43 +08:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := tx.Create(&model.Setting{Key: "PanelName", Value: "1Panel"}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-09-13 18:45:03 +08:00
|
|
|
if err := tx.Create(&model.Setting{Key: "Language", Value: "zh"}).Error; err != nil {
|
2022-09-15 10:44:43 +08:00
|
|
|
return err
|
|
|
|
}
|
2022-11-16 18:27:22 +08:00
|
|
|
if err := tx.Create(&model.Setting{Key: "Theme", Value: "light"}).Error; err != nil {
|
2022-09-15 10:44:43 +08:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := tx.Create(&model.Setting{Key: "SessionTimeout", Value: "86400"}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-09-09 17:17:02 +08:00
|
|
|
if err := tx.Create(&model.Setting{Key: "LocalTime", Value: ""}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-09-15 10:44:43 +08:00
|
|
|
|
2023-01-29 16:38:34 +08:00
|
|
|
if err := tx.Create(&model.Setting{Key: "ServerPort", Value: "9999"}).Error; err != nil {
|
2022-09-15 10:44:43 +08:00
|
|
|
return err
|
|
|
|
}
|
2022-09-19 19:42:06 +08:00
|
|
|
if err := tx.Create(&model.Setting{Key: "SecurityEntrance", Value: "onepanel"}).Error; err != nil {
|
2022-09-15 10:44:43 +08:00
|
|
|
return err
|
|
|
|
}
|
2023-02-10 16:10:40 +08:00
|
|
|
if err := tx.Create(&model.Setting{Key: "JWTSigningKey", Value: common.RandStr(16)}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-02-13 11:04:14 +08:00
|
|
|
if err := tx.Create(&model.Setting{Key: "EncryptKey", Value: common.RandStr(16)}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-02-10 16:10:40 +08:00
|
|
|
|
2022-12-02 10:23:35 +08:00
|
|
|
if err := tx.Create(&model.Setting{Key: "ExpirationTime", Value: time.Now().AddDate(0, 0, 10).Format("2006-01-02 15:04:05")}).Error; err != nil {
|
2022-09-29 16:15:59 +08:00
|
|
|
return err
|
|
|
|
}
|
2022-11-23 19:23:41 +08:00
|
|
|
if err := tx.Create(&model.Setting{Key: "ExpirationDays", Value: "0"}).Error; err != nil {
|
2022-09-09 17:17:02 +08:00
|
|
|
return err
|
|
|
|
}
|
2023-02-02 15:01:37 +08:00
|
|
|
if err := tx.Create(&model.Setting{Key: "ComplexityVerification", Value: "disable"}).Error; err != nil {
|
2022-09-15 10:44:43 +08:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := tx.Create(&model.Setting{Key: "MFAStatus", Value: "disable"}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-09-14 23:27:17 +08:00
|
|
|
if err := tx.Create(&model.Setting{Key: "MFASecret", Value: ""}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-09-15 10:44:43 +08:00
|
|
|
|
|
|
|
if err := tx.Create(&model.Setting{Key: "MonitorStatus", Value: "enable"}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := tx.Create(&model.Setting{Key: "MonitorStoreDays", Value: "30"}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := tx.Create(&model.Setting{Key: "MessageType", Value: "none"}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := tx.Create(&model.Setting{Key: "EmailVars", Value: ""}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := tx.Create(&model.Setting{Key: "WeChatVars", Value: ""}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := tx.Create(&model.Setting{Key: "DingVars", Value: ""}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-01-09 22:55:10 +08:00
|
|
|
if err := tx.Create(&model.Setting{Key: "SystemVersion", Value: "v1.0.0"}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-02-02 15:01:37 +08:00
|
|
|
if err := tx.Create(&model.Setting{Key: "SystemStatus", Value: "Free"}).Error; err != nil {
|
2023-02-13 11:04:14 +08:00
|
|
|
tx.Rollback()
|
2023-02-02 15:01:37 +08:00
|
|
|
return err
|
|
|
|
}
|
2023-02-10 18:07:29 +08:00
|
|
|
if err := tx.Create(&model.Setting{Key: "AppStoreVersion", Value: "0"}).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-09-15 10:44:43 +08:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
2022-09-16 18:53:45 +08:00
|
|
|
|
|
|
|
var AddTableBackupAccount = &gormigrate.Migration{
|
|
|
|
ID: "20200916-add-table-backup",
|
|
|
|
Migrate: func(tx *gorm.DB) error {
|
2022-10-27 23:09:39 +08:00
|
|
|
if err := tx.AutoMigrate(&model.BackupAccount{}, &model.BackupRecord{}); err != nil {
|
2022-09-16 18:53:45 +08:00
|
|
|
return err
|
|
|
|
}
|
2023-01-29 16:38:34 +08:00
|
|
|
|
2022-09-16 18:53:45 +08:00
|
|
|
item := &model.BackupAccount{
|
2022-09-19 19:42:06 +08:00
|
|
|
Type: "LOCAL",
|
2023-01-29 16:38:34 +08:00
|
|
|
Vars: fmt.Sprintf("{\"dir\":\"%s\"}", global.CONF.System.Backup),
|
2022-09-16 18:53:45 +08:00
|
|
|
}
|
|
|
|
if err := tx.Create(item).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
2022-09-20 19:12:48 +08:00
|
|
|
|
|
|
|
var AddTableCronjob = &gormigrate.Migration{
|
|
|
|
ID: "20200921-add-table-cronjob",
|
|
|
|
Migrate: func(tx *gorm.DB) error {
|
2022-09-23 17:21:27 +08:00
|
|
|
return tx.AutoMigrate(&model.Cronjob{}, &model.JobRecords{})
|
2022-09-20 19:12:48 +08:00
|
|
|
},
|
|
|
|
}
|
2022-09-22 16:16:04 +08:00
|
|
|
|
|
|
|
var AddTableApp = &gormigrate.Migration{
|
|
|
|
ID: "20200921-add-table-app",
|
|
|
|
Migrate: func(tx *gorm.DB) error {
|
2022-11-18 17:50:52 +08:00
|
|
|
return tx.AutoMigrate(&model.App{}, &model.AppDetail{}, &model.Tag{}, &model.AppTag{}, &model.AppInstall{}, &model.AppInstallResource{}, &model.AppInstallBackup{})
|
2022-09-22 16:16:04 +08:00
|
|
|
},
|
|
|
|
}
|
2022-10-09 16:17:15 +08:00
|
|
|
|
|
|
|
var AddTableImageRepo = &gormigrate.Migration{
|
|
|
|
ID: "20201009-add-table-imagerepo",
|
|
|
|
Migrate: func(tx *gorm.DB) error {
|
2022-12-06 15:06:42 +08:00
|
|
|
if err := tx.AutoMigrate(&model.ImageRepo{}, &model.ComposeTemplate{}, &model.Compose{}); err != nil {
|
2022-10-09 16:17:15 +08:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
item := &model.ImageRepo{
|
|
|
|
Name: "Docker Hub",
|
2023-02-01 16:46:13 +08:00
|
|
|
Protocol: "https",
|
2022-10-09 16:17:15 +08:00
|
|
|
DownloadUrl: "docker.io",
|
2022-12-18 23:00:24 +08:00
|
|
|
Status: constant.StatusSuccess,
|
2022-10-09 16:17:15 +08:00
|
|
|
}
|
|
|
|
if err := tx.Create(item).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
2022-10-20 18:45:47 +08:00
|
|
|
|
|
|
|
var AddTableDatabaseMysql = &gormigrate.Migration{
|
|
|
|
ID: "20201020-add-table-database_mysql",
|
|
|
|
Migrate: func(tx *gorm.DB) error {
|
|
|
|
return tx.AutoMigrate(&model.DatabaseMysql{})
|
|
|
|
},
|
|
|
|
}
|
2022-10-28 17:04:57 +08:00
|
|
|
|
|
|
|
var AddTableWebsite = &gormigrate.Migration{
|
|
|
|
ID: "20201009-add-table-website",
|
|
|
|
Migrate: func(tx *gorm.DB) error {
|
2022-12-13 17:20:13 +08:00
|
|
|
if err := tx.AutoMigrate(&model.Website{}, &model.WebsiteDomain{}, &model.WebsiteGroup{}, &model.WebsiteDnsAccount{}, &model.WebsiteSSL{}, &model.WebsiteAcmeAccount{}); err != nil {
|
2022-10-28 17:04:57 +08:00
|
|
|
return err
|
|
|
|
}
|
2022-12-13 17:20:13 +08:00
|
|
|
item := &model.WebsiteGroup{
|
2022-10-28 17:04:57 +08:00
|
|
|
Name: "默认分组",
|
|
|
|
Default: true,
|
|
|
|
}
|
|
|
|
if err := tx.Create(item).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
2023-01-06 18:53:25 +08:00
|
|
|
|
2023-01-09 22:55:10 +08:00
|
|
|
var AddTableSnap = &gormigrate.Migration{
|
|
|
|
ID: "20230106-add-table-snap",
|
2023-01-06 18:53:25 +08:00
|
|
|
Migrate: func(tx *gorm.DB) error {
|
|
|
|
if err := tx.AutoMigrate(&model.Snapshot{}); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|