forgejo/models/migrations/v1_23/v303.go
forgejo-backport-action 39843ee2b3 [v10.0/forgejo] fix: avoid Gitea migration warnings (take 2) (#6578)
**Backport:** https://codeberg.org/forgejo/forgejo/pulls/6577

274bc480b4 introduced a regression in https://codeberg.org/forgejo/forgejo/pulls/6343

Trying to remove fields that have already been removed by

dd1523c72e/models/forgejo_migrations/v14.go

Is a noop for SQLite and went undetected by the upgrade tests.

Fixes: https://codeberg.org/forgejo/forgejo/issues/6575
Co-authored-by: Earl Warren <contact@earl-warren.org>
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6578
Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>
Co-authored-by: forgejo-backport-action <forgejo-backport-action@noreply.codeberg.org>
Co-committed-by: forgejo-backport-action <forgejo-backport-action@noreply.codeberg.org>
2025-01-15 22:48:56 +00:00

41 lines
1 KiB
Go

// Copyright 2024 The Forgejo Authors.
// SPDX-License-Identifier: MIT
package v1_23 //nolint
import (
"fmt"
"code.gitea.io/gitea/models/migrations/base"
"xorm.io/xorm"
)
func GiteaLastDrop(x *xorm.Engine) error {
sess := x.NewSession()
defer sess.Close()
for _, drop := range []struct {
table string
field string
}{
{"badge", "slug"},
{"oauth2_application", "skip_secondary_authorization"},
{"repository", "default_wiki_branch"},
{"repo_unit", "everyone_access_mode"},
{"protected_branch", "can_force_push"},
{"protected_branch", "enable_force_push_allowlist"},
{"protected_branch", "force_push_allowlist_user_i_ds"},
{"protected_branch", "force_push_allowlist_team_i_ds"},
{"protected_branch", "force_push_allowlist_deploy_keys"},
} {
if _, err := sess.Exec(fmt.Sprintf("SELECT `%s` FROM `%s` WHERE 0 = 1", drop.field, drop.table)); err != nil {
continue
}
if err := base.DropTableColumns(sess, drop.table, drop.field); err != nil {
return err
}
}
return sess.Commit()
}