forked from forgejo/forgejo
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>
This commit is contained in:
parent
41f0668da8
commit
71ca3067bc
11 changed files with 55 additions and 203 deletions
|
@ -7,13 +7,11 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strconv"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/foreignreference"
|
||||
issues_model "code.gitea.io/gitea/models/issues"
|
||||
"code.gitea.io/gitea/models/organization"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
|
@ -501,38 +499,6 @@ func TestCorrectIssueStats(t *testing.T) {
|
|||
assert.EqualValues(t, issueStats.OpenCount, issueAmount)
|
||||
}
|
||||
|
||||
func TestIssueForeignReference(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 4})
|
||||
assert.NotEqualValues(t, issue.Index, issue.ID) // make sure they are different to avoid false positive
|
||||
|
||||
// it is fine for an issue to not have a foreign reference
|
||||
err := issue.LoadAttributes(db.DefaultContext)
|
||||
assert.NoError(t, err)
|
||||
assert.Nil(t, issue.ForeignReference)
|
||||
|
||||
var foreignIndex int64 = 12345
|
||||
_, err = issues_model.GetIssueByForeignIndex(context.Background(), issue.RepoID, foreignIndex)
|
||||
assert.True(t, foreignreference.IsErrLocalIndexNotExist(err))
|
||||
|
||||
err = db.Insert(db.DefaultContext, &foreignreference.ForeignReference{
|
||||
LocalIndex: issue.Index,
|
||||
ForeignIndex: strconv.FormatInt(foreignIndex, 10),
|
||||
RepoID: issue.RepoID,
|
||||
Type: foreignreference.TypeIssue,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = issue.LoadAttributes(db.DefaultContext)
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.EqualValues(t, issue.ForeignReference.ForeignIndex, strconv.FormatInt(foreignIndex, 10))
|
||||
|
||||
found, err := issues_model.GetIssueByForeignIndex(context.Background(), issue.RepoID, foreignIndex)
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, found.Index, issue.Index)
|
||||
}
|
||||
|
||||
func TestMilestoneList_LoadTotalTrackedTimes(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
miles := issues_model.MilestoneList{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue