Check primary keys for all tables and drop ForeignReference (#21721)
Some dbs require that all tables have primary keys, see - #16802 - #21086 We can add a test to keep it from being broken again. Edit: ~Added missing primary key for `ForeignReference`~ Dropped the `ForeignReference` table to satisfy the check, so it closes #21086. More context can be found in comments. Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: zeripath <art27@cantab.net>forgejo
parent
41f0668da8
commit
71ca3067bc
@ -1 +0,0 @@
|
|||||||
[] # empty
|
|
@ -1,52 +0,0 @@
|
|||||||
// Copyright 2022 Gitea. All rights reserved.
|
|
||||||
// SPDX-License-Identifier: MIT
|
|
||||||
|
|
||||||
package foreignreference
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"code.gitea.io/gitea/modules/util"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ErrLocalIndexNotExist represents a "LocalIndexNotExist" kind of error.
|
|
||||||
type ErrLocalIndexNotExist struct {
|
|
||||||
RepoID int64
|
|
||||||
ForeignIndex int64
|
|
||||||
Type string
|
|
||||||
}
|
|
||||||
|
|
||||||
// ErrLocalIndexNotExist checks if an error is a ErrLocalIndexNotExist.
|
|
||||||
func IsErrLocalIndexNotExist(err error) bool {
|
|
||||||
_, ok := err.(ErrLocalIndexNotExist)
|
|
||||||
return ok
|
|
||||||
}
|
|
||||||
|
|
||||||
func (err ErrLocalIndexNotExist) Error() string {
|
|
||||||
return fmt.Sprintf("repository %d has no LocalIndex for ForeignIndex %d of type %s", err.RepoID, err.ForeignIndex, err.Type)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (err ErrLocalIndexNotExist) Unwrap() error {
|
|
||||||
return util.ErrNotExist
|
|
||||||
}
|
|
||||||
|
|
||||||
// ErrForeignIndexNotExist represents a "ForeignIndexNotExist" kind of error.
|
|
||||||
type ErrForeignIndexNotExist struct {
|
|
||||||
RepoID int64
|
|
||||||
LocalIndex int64
|
|
||||||
Type string
|
|
||||||
}
|
|
||||||
|
|
||||||
// ErrForeignIndexNotExist checks if an error is a ErrForeignIndexNotExist.
|
|
||||||
func IsErrForeignIndexNotExist(err error) bool {
|
|
||||||
_, ok := err.(ErrForeignIndexNotExist)
|
|
||||||
return ok
|
|
||||||
}
|
|
||||||
|
|
||||||
func (err ErrForeignIndexNotExist) Error() string {
|
|
||||||
return fmt.Sprintf("repository %d has no ForeignIndex for LocalIndex %d of type %s", err.RepoID, err.LocalIndex, err.Type)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (err ErrForeignIndexNotExist) Unwrap() error {
|
|
||||||
return util.ErrNotExist
|
|
||||||
}
|
|
@ -1,31 +0,0 @@
|
|||||||
// Copyright 2022 Gitea. All rights reserved.
|
|
||||||
// SPDX-License-Identifier: MIT
|
|
||||||
|
|
||||||
package foreignreference
|
|
||||||
|
|
||||||
import (
|
|
||||||
"code.gitea.io/gitea/models/db"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Type* are valid values for the Type field of ForeignReference
|
|
||||||
const (
|
|
||||||
TypeIssue = "issue"
|
|
||||||
TypePullRequest = "pull_request"
|
|
||||||
TypeComment = "comment"
|
|
||||||
TypeReview = "review"
|
|
||||||
TypeReviewComment = "review_comment"
|
|
||||||
TypeRelease = "release"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ForeignReference represents external references
|
|
||||||
type ForeignReference struct {
|
|
||||||
// RepoID is the first column in all indices. now we only need 2 indices: (repo, local) and (repo, foreign, type)
|
|
||||||
RepoID int64 `xorm:"UNIQUE(repo_foreign_type) INDEX(repo_local)" `
|
|
||||||
LocalIndex int64 `xorm:"INDEX(repo_local)"` // the resource key inside Gitea, it can be IssueIndex, or some model ID.
|
|
||||||
ForeignIndex string `xorm:"INDEX UNIQUE(repo_foreign_type)"`
|
|
||||||
Type string `xorm:"VARCHAR(16) INDEX UNIQUE(repo_foreign_type)"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
db.RegisterModel(new(ForeignReference))
|
|
||||||
}
|
|
@ -0,0 +1,15 @@
|
|||||||
|
// Copyright 2022 The Gitea Authors. All rights reserved.
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
package v1_19 //nolint
|
||||||
|
|
||||||
|
import (
|
||||||
|
"xorm.io/xorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
func DropForeignReferenceTable(x *xorm.Engine) error {
|
||||||
|
// Drop the table introduced in `v211`, it's considered badly designed and doesn't look like to be used.
|
||||||
|
// See: https://github.com/go-gitea/gitea/issues/21086#issuecomment-1318217453
|
||||||
|
type ForeignReference struct{}
|
||||||
|
return x.DropTables(new(ForeignReference))
|
||||||
|
}
|
Loading…
Reference in New Issue