mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-07 16:16:37 +08:00
[优化] 代码优化
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
+36
@@ -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),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user