diff --git a/models/migrations/v1_27/v358.go b/models/migrations/v1_27/v358.go index d70b9bb117..dfcbe8499c 100644 --- a/models/migrations/v1_27/v358.go +++ b/models/migrations/v1_27/v358.go @@ -8,9 +8,17 @@ import "xorm.io/xorm" // DropDisplayNameColumns removes the display_name column from repo_manifest // and update_stream_config. Display name is now computed from extension_type + name. func DropDisplayNameColumns(x *xorm.Engine) error { - if _, err := x.Exec("ALTER TABLE repo_manifest DROP COLUMN IF EXISTS display_name"); err != nil { - return err + // MySQL 8.0.x does not support DROP COLUMN IF EXISTS — check first. + for _, table := range []string{"repo_manifest", "update_stream_config"} { + var count int + if _, err := x.SQL("SELECT COUNT(*) FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = ? AND COLUMN_NAME = 'display_name'", table).Get(&count); err != nil { + return err + } + if count > 0 { + if _, err := x.Exec("ALTER TABLE `" + table + "` DROP COLUMN `display_name`"); err != nil { + return err + } + } } - _, err := x.Exec("ALTER TABLE update_stream_config DROP COLUMN IF EXISTS display_name") - return err + return nil }