[优化] 代码优化

This commit is contained in:
ryan
2026-06-04 10:12:53 +08:00
parent bd659d493d
commit 29fdc378a1
8 changed files with 46 additions and 23 deletions
@@ -52,7 +52,7 @@ func validatePagesStaticHosting(db *gorm.DB) error {
return fmt.Errorf("column pages_projects.%s is missing", column)
}
}
for _, column := range []string{"project_id", "checksum", "artifact_path", "entry_file"} {
for _, column := range []string{"project_id", "checksum", "artifact_path"} {
if !db.Migrator().HasColumn("pages_deployments", column) {
return fmt.Errorf("column pages_deployments.%s is missing", column)
}
@@ -1,8 +1,6 @@
package goose
import (
"fmt"
presslygoose "github.com/pressly/goose/v3"
"gorm.io/gorm"
)
@@ -24,9 +22,5 @@ func migratePagesDeploymentRootDir(ctx Context, db *gorm.DB, backend string) err
if err := ctx.ApplyCurrentSchema(db, backend); err != nil {
return err
}
// Verify that the column exists
if !db.Migrator().HasColumn("pages_deployments", "root_dir") {
return fmt.Errorf("column pages_deployments.root_dir is missing")
}
return nil
}
@@ -0,0 +1,36 @@
package goose
import (
"fmt"
presslygoose "github.com/pressly/goose/v3"
"gorm.io/gorm"
)
const versionPagesDeploymentDropUnusedFields int64 = 202606040003
// migration202606040003 drops RootDir and EntryFile fields from Pages deployments.
func migration202606040003(backend string, ctx Context) *presslygoose.Migration {
return newGORMMigration(
versionPagesDeploymentDropUnusedFields,
"202606040003_drop_pages_deployment_unused_fields.go",
backend,
ctx,
migratePagesDeploymentDropUnusedFields,
)
}
func migratePagesDeploymentDropUnusedFields(ctx Context, db *gorm.DB, backend string) error {
// Drop columns root_dir and entry_file from pages_deployments
if db.Migrator().HasColumn("pages_deployments", "root_dir") {
if err := db.Migrator().DropColumn("pages_deployments", "root_dir"); err != nil {
return fmt.Errorf("failed to drop pages_deployments.root_dir: %w", err)
}
}
if db.Migrator().HasColumn("pages_deployments", "entry_file") {
if err := db.Migrator().DropColumn("pages_deployments", "entry_file"); err != nil {
return fmt.Errorf("failed to drop pages_deployments.entry_file: %w", err)
}
}
return nil
}
@@ -47,6 +47,7 @@ func registeredMigrations(backend string, ctx Context) []*presslygoose.Migration
migration202606030004(backend, ctx),
migration202606040001(backend, ctx),
migration202606040002(backend, ctx),
migration202606040003(backend, ctx),
}
}
-2
View File
@@ -35,8 +35,6 @@ type PagesDeployment struct {
ArtifactPath string `json:"artifact_path" gorm:"size:2048;not null"`
FileCount int `json:"file_count" gorm:"not null;default:0"`
TotalSize int64 `json:"total_size" gorm:"not null;default:0"`
RootDir string `json:"root_dir" gorm:"size:512;not null;default:''"`
EntryFile string `json:"entry_file" gorm:"size:512;not null;default:'index.html'"`
CreatedBy string `json:"created_by" gorm:"size:64;not null;default:''"`
CreatedAt time.Time `json:"created_at"`
ActivatedAt *time.Time `json:"activated_at"`