Skip to content

Commit 85eada2

Browse files
lunnywxiaoguang
andcommitted
Explicitly not update indexes when sync database schemas (go-gitea#34281)
Fix go-gitea#34275 --------- Co-authored-by: wxiaoguang <[email protected]>
1 parent 4e5aca6 commit 85eada2

File tree

8 files changed

+109
-8
lines changed

8 files changed

+109
-8
lines changed

models/migrations/v1_23/v299.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,9 @@ func AddContentVersionToIssueAndComment(x *xorm.Engine) error {
1414
ContentVersion int `xorm:"NOT NULL DEFAULT 0"`
1515
}
1616

17-
return x.Sync(new(Comment), new(Issue))
17+
_, err := x.SyncWithOptions(xorm.SyncOptions{
18+
IgnoreConstrains: true,
19+
IgnoreIndices: true,
20+
}, new(Comment), new(Issue))
21+
return err
1822
}

models/migrations/v1_23/v300.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,9 @@ func AddForcePushBranchProtection(x *xorm.Engine) error {
1313
ForcePushAllowlistTeamIDs []int64 `xorm:"JSON TEXT"`
1414
ForcePushAllowlistDeployKeys bool `xorm:"NOT NULL DEFAULT false"`
1515
}
16-
return x.Sync(new(ProtectedBranch))
16+
_, err := x.SyncWithOptions(xorm.SyncOptions{
17+
IgnoreConstrains: true,
18+
IgnoreIndices: true,
19+
}, new(ProtectedBranch))
20+
return err
1721
}

models/migrations/v1_23/v301.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,9 @@ func AddSkipSecondaryAuthColumnToOAuth2ApplicationTable(x *xorm.Engine) error {
1010
type oauth2Application struct {
1111
SkipSecondaryAuthorization bool `xorm:"NOT NULL DEFAULT FALSE"`
1212
}
13-
return x.Sync(new(oauth2Application))
13+
_, err := x.SyncWithOptions(xorm.SyncOptions{
14+
IgnoreConstrains: true,
15+
IgnoreIndices: true,
16+
}, new(oauth2Application))
17+
return err
1418
}

models/migrations/v1_23/v303.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,9 @@ func AddCommentMetaDataColumn(x *xorm.Engine) error {
1919
CommentMetaData *CommentMetaData `xorm:"JSON TEXT"` // put all non-index metadata in a single field
2020
}
2121

22-
return x.Sync(new(Comment))
22+
_, err := x.SyncWithOptions(xorm.SyncOptions{
23+
IgnoreConstrains: true,
24+
IgnoreIndices: true,
25+
}, new(Comment))
26+
return err
2327
}

models/migrations/v1_23/v306.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,9 @@ func AddBlockAdminMergeOverrideBranchProtection(x *xorm.Engine) error {
99
type ProtectedBranch struct {
1010
BlockAdminMergeOverride bool `xorm:"NOT NULL DEFAULT false"`
1111
}
12-
return x.Sync(new(ProtectedBranch))
12+
_, err := x.SyncWithOptions(xorm.SyncOptions{
13+
IgnoreConstrains: true,
14+
IgnoreIndices: true,
15+
}, new(ProtectedBranch))
16+
return err
1317
}

models/migrations/v1_23/v310.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,9 @@ func AddPriorityToProtectedBranch(x *xorm.Engine) error {
1212
Priority int64 `xorm:"NOT NULL DEFAULT 0"`
1313
}
1414

15-
return x.Sync(new(ProtectedBranch))
15+
_, err := x.SyncWithOptions(xorm.SyncOptions{
16+
IgnoreConstrains: true,
17+
IgnoreIndices: true,
18+
}, new(ProtectedBranch))
19+
return err
1620
}

models/migrations/v1_23/v311.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ func AddTimeEstimateColumnToIssueTable(x *xorm.Engine) error {
1111
type Issue struct {
1212
TimeEstimate int64 `xorm:"NOT NULL DEFAULT 0"`
1313
}
14-
15-
return x.Sync(new(Issue))
14+
_, err := x.SyncWithOptions(xorm.SyncOptions{
15+
IgnoreConstrains: true,
16+
IgnoreIndices: true,
17+
}, new(Issue))
18+
return err
1619
}

tests/integration/pull_status_test.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,3 +165,77 @@ func TestPullCreate_EmptyChangesWithSameCommits(t *testing.T) {
165165
assert.Contains(t, text, "This branch is already included in the target branch. There is nothing to merge.")
166166
})
167167
}
168+
<<<<<<< HEAD
169+
=======
170+
171+
func TestPullStatusDelayCheck(t *testing.T) {
172+
onGiteaRun(t, func(t *testing.T, u *url.URL) {
173+
defer test.MockVariableValue(&setting.Repository.PullRequest.DelayCheckForInactiveDays, 1)()
174+
defer test.MockVariableValue(&pull.AddPullRequestToCheckQueue)()
175+
176+
session := loginUser(t, "user2")
177+
178+
run := func(t *testing.T, fn func(*testing.T)) (issue3 *issues.Issue, checkedPrID int64) {
179+
pull.AddPullRequestToCheckQueue = func(prID int64) {
180+
checkedPrID = prID
181+
}
182+
fn(t)
183+
issue3 = unittest.AssertExistsAndLoadBean(t, &issues.Issue{RepoID: 1, Index: 3})
184+
_ = issue3.LoadPullRequest(t.Context())
185+
return issue3, checkedPrID
186+
}
187+
188+
assertReloadingInterval := func(t *testing.T, interval string) {
189+
req := NewRequest(t, "GET", "/user2/repo1/pulls/3")
190+
resp := session.MakeRequest(t, req, http.StatusOK)
191+
attr := "data-pull-merge-box-reloading-interval"
192+
if interval == "" {
193+
assert.NotContains(t, resp.Body.String(), attr)
194+
} else {
195+
assert.Contains(t, resp.Body.String(), fmt.Sprintf(`%s="%v"`, attr, interval))
196+
}
197+
}
198+
199+
// PR issue3 is merageable at the beginning
200+
issue3, checkedPrID := run(t, func(t *testing.T) {})
201+
assert.Equal(t, issues.PullRequestStatusMergeable, issue3.PullRequest.Status)
202+
assert.Zero(t, checkedPrID)
203+
assertReloadingInterval(t, "") // the PR is mergeable, so no need to reload the merge box
204+
205+
// setting.IsProd = false // it would cause data-race because the queue handlers might be running and reading its value
206+
// assertReloadingInterval(t, "1") // make sure dev mode always do merge box reloading, to make sure the UI logic won't break
207+
// setting.IsProd = true
208+
209+
// when base branch changes, PR status should be updated, but it is inactive for long time, so no real check
210+
issue3, checkedPrID = run(t, func(t *testing.T) {
211+
testEditFile(t, session, "user2", "repo1", "master", "README.md", "new content 1")
212+
})
213+
assert.Equal(t, issues.PullRequestStatusChecking, issue3.PullRequest.Status)
214+
assert.Zero(t, checkedPrID)
215+
assertReloadingInterval(t, "2000") // the PR status is "checking", so try to reload the merge box
216+
217+
// view a PR with status=checking, it starts the real check
218+
issue3, checkedPrID = run(t, func(t *testing.T) {
219+
req := NewRequest(t, "GET", "/user2/repo1/pulls/3")
220+
session.MakeRequest(t, req, http.StatusOK)
221+
})
222+
assert.Equal(t, issues.PullRequestStatusChecking, issue3.PullRequest.Status)
223+
assert.Equal(t, issue3.PullRequest.ID, checkedPrID)
224+
225+
// when base branch changes, still so no real check
226+
issue3, checkedPrID = run(t, func(t *testing.T) {
227+
testEditFile(t, session, "user2", "repo1", "master", "README.md", "new content 2")
228+
})
229+
assert.Equal(t, issues.PullRequestStatusChecking, issue3.PullRequest.Status)
230+
assert.Zero(t, checkedPrID)
231+
232+
// then allow to check PRs without delay, when base branch changes, the PRs will be checked
233+
setting.Repository.PullRequest.DelayCheckForInactiveDays = -1
234+
issue3, checkedPrID = run(t, func(t *testing.T) {
235+
testEditFile(t, session, "user2", "repo1", "master", "README.md", "new content 3")
236+
})
237+
assert.Equal(t, issues.PullRequestStatusChecking, issue3.PullRequest.Status)
238+
assert.Equal(t, issue3.PullRequest.ID, checkedPrID)
239+
})
240+
}
241+
>>>>>>> 44ece1e6f3 (Explicitly not update indexes when sync database schemas (#34281))

0 commit comments

Comments
 (0)