Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6225614

Browse files
lunnysilverwind
authored andcommittedFeb 20, 2024
Upgrade xorm to new version which supported update join for all supported databases (go-gitea#28590)
Fix go-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.
1 parent d60279e commit 6225614

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
@@ -121,7 +121,7 @@ require (
121121
mvdan.cc/xurls/v2 v2.5.0
122122
strk.kbt.io/projects/go/libravatar v0.0.0-20191008002943-06d1c002b251
123123
xorm.io/builder v0.3.13
124-
xorm.io/xorm v1.3.4
124+
xorm.io/xorm v1.3.6
125125
)
126126

127127
require (

‎go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -1510,5 +1510,5 @@ strk.kbt.io/projects/go/libravatar v0.0.0-20191008002943-06d1c002b251/go.mod h1:
15101510
xorm.io/builder v0.3.11-0.20220531020008-1bd24a7dc978/go.mod h1:aUW0S9eb9VCaPohFCH3j7czOx1PMW3i1HrSzbLYGBSE=
15111511
xorm.io/builder v0.3.13 h1:a3jmiVVL19psGeXx8GIurTp7p0IIgqeDmwhcR6BAOAo=
15121512
xorm.io/builder v0.3.13/go.mod h1:aUW0S9eb9VCaPohFCH3j7czOx1PMW3i1HrSzbLYGBSE=
1513-
xorm.io/xorm v1.3.4 h1:vWFKzR3DhGUDl5b4srhUjhDwjxkZAc4C7BFszpu0swI=
1514-
xorm.io/xorm v1.3.4/go.mod h1:qFJGFoVYbbIdnz2vaL5OxSQ2raleMpyRRalnq3n9OJo=
1513+
xorm.io/xorm v1.3.6 h1:hfpWHkDIWWqUi8FRF2H2M9O8lO3Ov47rwFcS9gPzPkU=
1514+
xorm.io/xorm v1.3.6/go.mod h1:qFJGFoVYbbIdnz2vaL5OxSQ2raleMpyRRalnq3n9OJo=

‎models/issues/comment.go

+3-8
Original file line numberDiff line numberDiff line change
@@ -1161,14 +1161,9 @@ func DeleteComment(ctx context.Context, comment *Comment) error {
11611161
// UpdateCommentsMigrationsByType updates comments' migrations information via given git service type and original id and poster id
11621162
func UpdateCommentsMigrationsByType(ctx context.Context, tp structs.GitServiceType, originalAuthorID string, posterID int64) error {
11631163
_, err := db.GetEngine(ctx).Table("comment").
1164-
Where(builder.In("issue_id",
1165-
builder.Select("issue.id").
1166-
From("issue").
1167-
InnerJoin("repository", "issue.repo_id = repository.id").
1168-
Where(builder.Eq{
1169-
"repository.original_service_type": tp,
1170-
}),
1171-
)).
1164+
Join("INNER", "issue", "issue.id = comment.issue_id").
1165+
Join("INNER", "repository", "issue.repo_id = repository.id").
1166+
Where("repository.original_service_type = ?", tp).
11721167
And("comment.original_author_id = ?", originalAuthorID).
11731168
Update(map[string]any{
11741169
"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)
Please sign in to comment.