mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-09-29 14:06:36 +08:00
[优化] 修复一个升级数据库的错误
This commit is contained in:
@@ -92,6 +92,12 @@ func migrateV16(ctx Context, db *gorm.DB, backend string) error {
|
||||
if err := db.Model(&proxyRouteV16{}).Where("upstream_type = ?", "tunnel").Update("upstream_type", "direct").Error; err != nil {
|
||||
return fmt.Errorf("reset pre-release tunnel proxy routes: %w", err)
|
||||
}
|
||||
// Drop the legacy index idx_proxy_routes_tunnel_id if it exists, to avoid errors on dropping the tunnel_id column (especially on SQLite).
|
||||
if migrator.HasIndex(&proxyRouteV16{}, "idx_proxy_routes_tunnel_id") {
|
||||
if err := migrator.DropIndex(&proxyRouteV16{}, "idx_proxy_routes_tunnel_id"); err != nil {
|
||||
return fmt.Errorf("drop index idx_proxy_routes_tunnel_id failed: %w", err)
|
||||
}
|
||||
}
|
||||
if err := migrator.DropColumn(&proxyRouteV16{}, "tunnel_id"); err != nil {
|
||||
return fmt.Errorf("drop pre-release proxy_routes.tunnel_id: %w", err)
|
||||
}
|
||||
|
||||
@@ -204,6 +204,12 @@ func dropLegacyNodeColumns(db *gorm.DB, backend string) error {
|
||||
if db == nil || !db.Migrator().HasTable(&Node{}) {
|
||||
return nil
|
||||
}
|
||||
// Drop the legacy index idx_nodes_agent_token if it exists, to avoid errors on dropping the agent_token column (especially on SQLite).
|
||||
if db.Migrator().HasIndex(&Node{}, "idx_nodes_agent_token") {
|
||||
if err := db.Migrator().DropIndex(&Node{}, "idx_nodes_agent_token"); err != nil {
|
||||
return fmt.Errorf("drop index idx_nodes_agent_token failed: %w", err)
|
||||
}
|
||||
}
|
||||
legacyColumns := []struct {
|
||||
column string
|
||||
}{
|
||||
|
||||
Reference in New Issue
Block a user