[优化] 操作优化

This commit is contained in:
ryan
2026-06-04 10:07:40 +08:00
parent 6a2a6028c3
commit bd659d493d
10 changed files with 273 additions and 54 deletions
@@ -0,0 +1,43 @@
package goose
import (
"fmt"
presslygoose "github.com/pressly/goose/v3"
"gorm.io/gorm"
)
const versionPagesProjectRootDir int64 = 202606040002
// migration202606040002 adds RootDir and EntryFile fields to Pages projects.
func migration202606040002(backend string, ctx Context) *presslygoose.Migration {
return newGORMMigration(
versionPagesProjectRootDir,
"202606040002_add_pages_project_root_dir.go",
backend,
ctx,
migratePagesProjectRootDir,
)
}
func migratePagesProjectRootDir(ctx Context, db *gorm.DB, backend string) error {
if err := ctx.ApplyCurrentSchema(db, backend); err != nil {
return err
}
// Verify that the columns exist
if !db.Migrator().HasColumn("pages_projects", "root_dir") {
return fmt.Errorf("column pages_projects.root_dir is missing")
}
if !db.Migrator().HasColumn("pages_projects", "entry_file") {
return fmt.Errorf("column pages_projects.entry_file is missing")
}
// Backfill existing rows: if entry_file is empty, set to 'index.html'
type PagesProject struct {
ID uint `gorm:"primaryKey"`
EntryFile string `gorm:"size:512;not null;default:'index.html'"`
}
if err := db.Model(&PagesProject{}).Where("entry_file = '' OR entry_file IS NULL").Update("entry_file", "index.html").Error; err != nil {
return fmt.Errorf("failed to backfill pages_projects.entry_file: %w", err)
}
return nil
}
@@ -46,6 +46,7 @@ func registeredMigrations(backend string, ctx Context) []*presslygoose.Migration
migration202606030003(backend, ctx),
migration202606030004(backend, ctx),
migration202606040001(backend, ctx),
migration202606040002(backend, ctx),
}
}
+2
View File
@@ -20,6 +20,8 @@ type PagesProject struct {
APIProxyPass string `json:"api_proxy_pass" gorm:"size:2048;not null;default:''"`
APIProxyRewrite string `json:"api_proxy_rewrite" gorm:"size:255;not null;default:''"`
ActiveDeploymentID *uint `json:"active_deployment_id" gorm:"index"`
RootDir string `json:"root_dir" gorm:"size:512;not null;default:''"`
EntryFile string `json:"entry_file" gorm:"size:512;not null;default:'index.html'"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}