mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-03 07:06:36 +08:00
[优化] go 引用调整
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
package migrate
|
||||
|
||||
import (
|
||||
"sort"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
const BaseDatabaseSchemaVersion = 7
|
||||
|
||||
type Context interface {
|
||||
ApplyCurrentSchema(db *gorm.DB, backend string) error
|
||||
ApplyCurrentSchemaExcept(db *gorm.DB, backend string, excludedTables ...string) error
|
||||
BackfillOriginsFromProxyRoutes(db *gorm.DB) error
|
||||
BackfillProxyRouteSiteFields(db *gorm.DB) error
|
||||
EnsureProxyRouteSiteNameUniqueIndex(db *gorm.DB) error
|
||||
BackfillProxyRouteCertificateFields(db *gorm.DB) error
|
||||
BackfillProxyRouteDomainCertificateFields(db *gorm.DB) error
|
||||
EnsureDefaultGitHubAuthSource(db *gorm.DB) error
|
||||
EnsureDefaultWAFRuleGroup(db *gorm.DB) error
|
||||
DropLegacyNodeColumns(db *gorm.DB, backend string) error
|
||||
ValidateDatabaseSchemaVersion(db *gorm.DB, backend string, version int) error
|
||||
}
|
||||
|
||||
type Migration struct {
|
||||
FromVersion int
|
||||
ToVersion int
|
||||
Migrate func(ctx Context, db *gorm.DB, backend string) error
|
||||
Validate func(ctx Context, db *gorm.DB, backend string) error
|
||||
}
|
||||
|
||||
var registeredMigrations []Migration
|
||||
|
||||
func Register(migration Migration) {
|
||||
registeredMigrations = append(registeredMigrations, migration)
|
||||
}
|
||||
|
||||
func Migrations() []Migration {
|
||||
migrations := append([]Migration{}, registeredMigrations...)
|
||||
sort.Slice(migrations, func(i int, j int) bool {
|
||||
return migrations[i].FromVersion < migrations[j].FromVersion
|
||||
})
|
||||
return migrations
|
||||
}
|
||||
|
||||
func CurrentVersion() int {
|
||||
version := BaseDatabaseSchemaVersion
|
||||
for _, migration := range registeredMigrations {
|
||||
if migration.ToVersion > version {
|
||||
version = migration.ToVersion
|
||||
}
|
||||
}
|
||||
return version
|
||||
}
|
||||
Reference in New Issue
Block a user