forgejo_backup/models/forgejo_migrations/v31.go
Maks1mS 070e782519 fix: ensure consistent empty repository topics field (#7920)
Resolves #7878

An empty repository topic was not stored consistently across databases, this caused the `ONLY_SHOW_RELEVANT_REPOS` feature to not work correctly. Always store empty repository topics as an empty array to fix this.

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7920
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
Co-authored-by: Maks1mS <maks1ms@noreply.codeberg.org>
Co-committed-by: Maks1mS <maks1ms@noreply.codeberg.org>
2025-06-02 14:13:27 +02:00

29 lines
680 B
Go

// Copyright 2025 The Forgejo Authors.
// SPDX-License-Identifier: GPL-3.0-or-later
package forgejo_migrations //nolint:revive
import (
"xorm.io/xorm"
"xorm.io/xorm/schemas"
)
func SetTopicsAsEmptySlice(x *xorm.Engine) error {
var err error
if x.Dialect().URI().DBType == schemas.POSTGRES {
_, err = x.Exec("UPDATE `repository` SET topics = '[]' WHERE topics IS NULL OR topics::text = 'null'")
} else {
_, err = x.Exec("UPDATE `repository` SET topics = '[]' WHERE topics IS NULL")
}
if err != nil {
return err
}
type Repository struct {
ID int64 `xorm:"pk autoincr"`
Topics []string `xorm:"TEXT JSON NOT NULL"`
}
return x.Sync(new(Repository))
}