Skip to content

Commit 44ece1e

Browse files
lunnywxiaoguang
andauthored
Explicitly not update indexes when sync database schemas (#34281)
Fix #34275 --------- Co-authored-by: wxiaoguang <[email protected]>
1 parent 27ff5e2 commit 44ece1e

File tree

13 files changed

+64
-20
lines changed

13 files changed

+64
-20
lines changed

models/migrations/v1_23/v299.go

+5-1
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

+5-1
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

+5-1
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

+5-1
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

+5-1
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

+5-1
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

+5-2
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
}

models/migrations/v1_24/v312.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,9 @@ func (pullAutoMerge) TableName() string {
1717
}
1818

1919
func AddDeleteBranchAfterMergeForAutoMerge(x *xorm.Engine) error {
20-
return x.Sync(new(pullAutoMerge))
20+
_, err := x.SyncWithOptions(xorm.SyncOptions{
21+
IgnoreConstrains: true,
22+
IgnoreIndices: true,
23+
}, new(pullAutoMerge))
24+
return err
2125
}

models/migrations/v1_24/v315.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ func AddEphemeralToActionRunner(x *xorm.Engine) error {
1111
type ActionRunner struct {
1212
Ephemeral bool `xorm:"ephemeral NOT NULL DEFAULT false"`
1313
}
14-
15-
return x.Sync(new(ActionRunner))
14+
_, err := x.SyncWithOptions(xorm.SyncOptions{
15+
IgnoreConstrains: true,
16+
IgnoreIndices: true,
17+
}, new(ActionRunner))
18+
return err
1619
}

models/migrations/v1_24/v316.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,9 @@ func AddDescriptionForSecretsAndVariables(x *xorm.Engine) error {
1616
Description string `xorm:"TEXT"`
1717
}
1818

19-
return x.Sync(new(Secret), new(ActionVariable))
19+
_, err := x.SyncWithOptions(xorm.SyncOptions{
20+
IgnoreConstrains: true,
21+
IgnoreIndices: true,
22+
}, new(Secret), new(ActionVariable))
23+
return err
2024
}

models/migrations/v1_24/v318.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,9 @@ func AddRepoUnitAnonymousAccessMode(x *xorm.Engine) error {
1313
type RepoUnit struct { //revive:disable-line:exported
1414
AnonymousAccessMode perm.AccessMode `xorm:"NOT NULL DEFAULT 0"`
1515
}
16-
return x.Sync(&RepoUnit{})
16+
_, err := x.SyncWithOptions(xorm.SyncOptions{
17+
IgnoreConstrains: true,
18+
IgnoreIndices: true,
19+
}, new(RepoUnit))
20+
return err
1721
}

models/migrations/v1_24/v319.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ func AddExclusiveOrderColumnToLabelTable(x *xorm.Engine) error {
1111
type Label struct {
1212
ExclusiveOrder int `xorm:"DEFAULT 0"`
1313
}
14-
15-
return x.Sync(new(Label))
14+
_, err := x.SyncWithOptions(xorm.SyncOptions{
15+
IgnoreConstrains: true,
16+
IgnoreIndices: true,
17+
}, new(Label))
18+
return err
1619
}

tests/integration/pull_status_test.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ func TestPullCreate_EmptyChangesWithSameCommits(t *testing.T) {
172172

173173
func TestPullStatusDelayCheck(t *testing.T) {
174174
onGiteaRun(t, func(t *testing.T, u *url.URL) {
175-
defer test.MockVariableValue(&setting.IsProd)()
176175
defer test.MockVariableValue(&setting.Repository.PullRequest.DelayCheckForInactiveDays, 1)()
177176
defer test.MockVariableValue(&pull.AddPullRequestToCheckQueue)()
178177

@@ -203,11 +202,11 @@ func TestPullStatusDelayCheck(t *testing.T) {
203202
issue3, checkedPrID := run(t, func(t *testing.T) {})
204203
assert.Equal(t, issues.PullRequestStatusMergeable, issue3.PullRequest.Status)
205204
assert.Zero(t, checkedPrID)
206-
setting.IsProd = true
207205
assertReloadingInterval(t, "") // the PR is mergeable, so no need to reload the merge box
208-
setting.IsProd = false
209-
assertReloadingInterval(t, "1") // make sure dev mode always do merge box reloading, to make sure the UI logic won't break
210-
setting.IsProd = true
206+
207+
// setting.IsProd = false // it would cause data-race because the queue handlers might be running and reading its value
208+
// assertReloadingInterval(t, "1") // make sure dev mode always do merge box reloading, to make sure the UI logic won't break
209+
// setting.IsProd = true
211210

212211
// when base branch changes, PR status should be updated, but it is inactive for long time, so no real check
213212
issue3, checkedPrID = run(t, func(t *testing.T) {

0 commit comments

Comments
 (0)