mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-26 20:27:03 +01:00
459b1b20fe
Fix https://github.com/go-gitea/gitea/pull/29874#discussion_r1542227686 - The migration of v292 will miss many projects. These projects will have no default board. This PR introduced a new migration number and removed v292 migration. - This PR also added the missed transactions on project-related operations. - Only `SetDefaultBoard` will remove duplicated defaults but not in `GetDefaultBoard` (cherry picked from commit 40cdc84b368cce8328b4b49ea5ecf1c5fa040300)
44 lines
1.3 KiB
Go
44 lines
1.3 KiB
Go
// Copyright 2024 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package v1_22 //nolint
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"code.gitea.io/gitea/models/db"
|
|
"code.gitea.io/gitea/models/migrations/base"
|
|
"code.gitea.io/gitea/models/project"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func Test_CheckProjectColumnsConsistency(t *testing.T) {
|
|
// Prepare and load the testing database
|
|
x, deferable := base.PrepareTestEnv(t, 0, new(project.Project), new(project.Board))
|
|
defer deferable()
|
|
if x == nil || t.Failed() {
|
|
return
|
|
}
|
|
|
|
assert.NoError(t, CheckProjectColumnsConsistency(x))
|
|
|
|
// check if default board was added
|
|
var defaultBoard project.Board
|
|
has, err := x.Where("project_id=? AND `default` = ?", 1, true).Get(&defaultBoard)
|
|
assert.NoError(t, err)
|
|
assert.True(t, has)
|
|
assert.Equal(t, int64(1), defaultBoard.ProjectID)
|
|
assert.True(t, defaultBoard.Default)
|
|
|
|
// check if multiple defaults, previous were removed and last will be kept
|
|
expectDefaultBoard, err := project.GetBoard(db.DefaultContext, 2)
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, int64(2), expectDefaultBoard.ProjectID)
|
|
assert.False(t, expectDefaultBoard.Default)
|
|
|
|
expectNonDefaultBoard, err := project.GetBoard(db.DefaultContext, 3)
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, int64(2), expectNonDefaultBoard.ProjectID)
|
|
assert.True(t, expectNonDefaultBoard.Default)
|
|
}
|