Skip to content

Commit 0a157ed

Browse files
GiteaBotearl-warren
authored andcommitted
Upgrade xorm to new version which supported update join for all supported databases (#28590) (#28668)
Backport #28590 by @lunny Fix go-gitea/gitea#28547 (comment) Since https://gitea.com/xorm/xorm/pulls/2383 merged, xorm now supports UPDATE JOIN. To keep consistent from different databases, xorm use `engine.Join().Update`, but the actural generated SQL are different between different databases. For MySQL, it's `UPDATE talbe1 JOIN table2 ON join_conditions SET xxx Where xxx`. For MSSQL, it's `UPDATE table1 SET xxx FROM TABLE1, TABLE2 WHERE join_conditions`. For SQLITE per https://www.sqlite.org/lang_update.html, sqlite support `UPDATE table1 SET xxx FROM table2 WHERE join conditions` from 3.33.0(2020-8-14). POSTGRES is the same as SQLITE. Co-authored-by: Lunny Xiao <[email protected]> (cherry picked from commit 18da3f8)
1 parent fe3b294 commit 0a157ed

File tree

4 files changed

+15
-11
lines changed

4 files changed

+15
-11
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ require (
118118
mvdan.cc/xurls/v2 v2.5.0
119119
strk.kbt.io/projects/go/libravatar v0.0.0-20191008002943-06d1c002b251
120120
xorm.io/builder v0.3.13
121-
xorm.io/xorm v1.3.4
121+
xorm.io/xorm v1.3.6
122122
)
123123

124124
require (

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -1636,5 +1636,5 @@ strk.kbt.io/projects/go/libravatar v0.0.0-20191008002943-06d1c002b251/go.mod h1:
16361636
xorm.io/builder v0.3.11-0.20220531020008-1bd24a7dc978/go.mod h1:aUW0S9eb9VCaPohFCH3j7czOx1PMW3i1HrSzbLYGBSE=
16371637
xorm.io/builder v0.3.13 h1:a3jmiVVL19psGeXx8GIurTp7p0IIgqeDmwhcR6BAOAo=
16381638
xorm.io/builder v0.3.13/go.mod h1:aUW0S9eb9VCaPohFCH3j7czOx1PMW3i1HrSzbLYGBSE=
1639-
xorm.io/xorm v1.3.4 h1:vWFKzR3DhGUDl5b4srhUjhDwjxkZAc4C7BFszpu0swI=
1640-
xorm.io/xorm v1.3.4/go.mod h1:qFJGFoVYbbIdnz2vaL5OxSQ2raleMpyRRalnq3n9OJo=
1639+
xorm.io/xorm v1.3.6 h1:hfpWHkDIWWqUi8FRF2H2M9O8lO3Ov47rwFcS9gPzPkU=
1640+
xorm.io/xorm v1.3.6/go.mod h1:qFJGFoVYbbIdnz2vaL5OxSQ2raleMpyRRalnq3n9OJo=

models/issues/comment.go

+3-8
Original file line numberDiff line numberDiff line change
@@ -1166,14 +1166,9 @@ func DeleteComment(ctx context.Context, comment *Comment) error {
11661166
// UpdateCommentsMigrationsByType updates comments' migrations information via given git service type and original id and poster id
11671167
func UpdateCommentsMigrationsByType(ctx context.Context, tp structs.GitServiceType, originalAuthorID string, posterID int64) error {
11681168
_, err := db.GetEngine(ctx).Table("comment").
1169-
Where(builder.In("issue_id",
1170-
builder.Select("issue.id").
1171-
From("issue").
1172-
InnerJoin("repository", "issue.repo_id = repository.id").
1173-
Where(builder.Eq{
1174-
"repository.original_service_type": tp,
1175-
}),
1176-
)).
1169+
Join("INNER", "issue", "issue.id = comment.issue_id").
1170+
Join("INNER", "repository", "issue.repo_id = repository.id").
1171+
Where("repository.original_service_type = ?", tp).
11771172
And("comment.original_author_id = ?", originalAuthorID).
11781173
Update(map[string]any{
11791174
"poster_id": posterID,

tests/integration/migrate_test.go

+9
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import (
1212
"testing"
1313

1414
auth_model "code.gitea.io/gitea/models/auth"
15+
"code.gitea.io/gitea/models/db"
16+
issues_model "code.gitea.io/gitea/models/issues"
1517
repo_model "code.gitea.io/gitea/models/repo"
1618
"code.gitea.io/gitea/models/unittest"
1719
user_model "code.gitea.io/gitea/models/user"
@@ -99,3 +101,10 @@ func TestMigrateGiteaForm(t *testing.T) {
99101
unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{Name: migratedRepoName})
100102
})
101103
}
104+
105+
func Test_UpdateCommentsMigrationsByType(t *testing.T) {
106+
assert.NoError(t, unittest.PrepareTestDatabase())
107+
108+
err := issues_model.UpdateCommentsMigrationsByType(db.DefaultContext, structs.GithubService, "1", 1)
109+
assert.NoError(t, err)
110+
}

0 commit comments

Comments
 (0)