feat: 添加 migrateProxyRouteEnableHTTPSColumn 方法以重命名 ProxyRoute 中的 enable_http_s 列为 enable_https,并在 InitDB 中调用该方法

This commit is contained in:
ryan
2026-03-11 11:14:40 +08:00
parent efcc6b5337
commit 16ea572183
2 changed files with 14 additions and 1 deletions
+13
View File
@@ -10,6 +10,16 @@ import (
var DB *gorm.DB
func migrateProxyRouteEnableHTTPSColumn(db *gorm.DB) error {
if !db.Migrator().HasTable(&ProxyRoute{}) {
return nil
}
if db.Migrator().HasColumn(&ProxyRoute{}, "enable_https") || !db.Migrator().HasColumn(&ProxyRoute{}, "enable_http_s") {
return nil
}
return db.Migrator().RenameColumn(&ProxyRoute{}, "enable_http_s", "enable_https")
}
func createRootAccountIfNeed() error {
var user User
//if user.Status != common.UserStatusEnabled {
@@ -52,6 +62,9 @@ func InitDB() (err error) {
}
if err == nil {
DB = db
if err = migrateProxyRouteEnableHTTPSColumn(db); err != nil {
return err
}
err := db.AutoMigrate(&File{})
if err != nil {
return err
+1 -1
View File
@@ -7,7 +7,7 @@ type ProxyRoute struct {
Domain string `json:"domain" gorm:"uniqueIndex;size:255;not null"`
OriginURL string `json:"origin_url" gorm:"size:2048;not null"`
Enabled bool `json:"enabled" gorm:"not null;default:true"`
EnableHTTPS bool `json:"enable_https" gorm:"not null;default:false"`
EnableHTTPS bool `json:"enable_https" gorm:"column:enable_https;not null;default:false"`
CertID *uint `json:"cert_id"`
RedirectHTTP bool `json:"redirect_http" gorm:"not null;default:false"`
CustomHeaders string `json:"custom_headers" gorm:"type:text;not null;default:'[]'"`