Skip to content

Commit e10ba5e

Browse files
authored
Rename Sync2 -> Sync (#26479)
The xorm `Sync2` has already been deprecated in favor of `Sync`, so let's do the same inside the Gitea codebase. Command used to replace everything: ```sh for i in $(ag Sync2 --files-with-matches); do vim $i -c ':%sno/Sync2/Sync/g' -c ':wq'; done ```
1 parent 50fc22e commit e10ba5e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+184
-184
lines changed

docs/content/administration/command-line.en-us.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ Sometimes when there are migrations the old columns and default values may be le
403403
unchanged in the database schema. This may lead to warning such as:
404404

405405
```
406-
2020/08/02 11:32:29 ...rm/session_schema.go:360:Sync2() [W] Table user Column keep_activity_private db default is , struct default is 0
406+
2020/08/02 11:32:29 ...rm/session_schema.go:360:Sync() [W] Table user Column keep_activity_private db default is , struct default is 0
407407
```
408408

409409
You can cause Gitea to recreate these tables and copy the old data into the new table

docs/content/administration/command-line.zh-cn.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ AuthorizedKeysCommand /path/to/gitea keys -e git -u %u -t %t -k %k
375375
有时,在迁移时,旧的列和默认值可能会在数据库模式中保持不变。这可能会导致警告,如下所示:
376376

377377
```
378-
2020/08/02 11:32:29 ...rm/session_schema.go:360:Sync2() [W] Table user Column keep_activity_private db default is , struct default is 0
378+
2020/08/02 11:32:29 ...rm/session_schema.go:360:Sync() [W] Table user Column keep_activity_private db default is , struct default is 0
379379
```
380380

381381
您可以通过以下方式让 Gitea 重新创建这些表,并将旧数据复制到新表中,并适当设置默认值:

docs/content/help/faq.en-us.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ Sometimes when there are migrations the old columns and default values may be le
410410
unchanged in the database schema. This may lead to warning such as:
411411

412412
```
413-
2020/08/02 11:32:29 ...rm/session_schema.go:360:Sync2() [W] Table user Column keep_activity_private db default is , struct default is 0
413+
2020/08/02 11:32:29 ...rm/session_schema.go:360:Sync() [W] Table user Column keep_activity_private db default is , struct default is 0
414414
```
415415

416416
These can safely be ignored, but you are able to stop these warnings by getting Gitea to recreate these tables using:

docs/content/help/faq.zh-cn.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ SystemD 上的标准输出默认会写入日志记录中。您可以尝试使用
424424
这可能会导致警告,例如:
425425

426426
```
427-
2020/08/02 11:32:29 ...rm/session_schema.go:360:Sync2() [W] Table user Column keep_activity_private db default is , struct default is 0
427+
2020/08/02 11:32:29 ...rm/session_schema.go:360:Sync() [W] Table user Column keep_activity_private db default is , struct default is 0
428428
```
429429

430430
可以安全地忽略这些警告,但您可以通过让 Gitea 重新创建这些表来停止这些警告,使用以下命令:

models/db/engine.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ type Engine interface {
5555
Limit(limit int, start ...int) *xorm.Session
5656
NoAutoTime() *xorm.Session
5757
SumInt(bean any, columnName string) (res int64, err error)
58-
Sync2(...any) error
58+
Sync(...any) error
5959
Select(string) *xorm.Session
6060
NotIn(string, ...any) *xorm.Session
6161
OrderBy(any, ...any) *xorm.Session
@@ -172,7 +172,7 @@ func UnsetDefaultEngine() {
172172
}
173173

174174
// InitEngineWithMigration initializes a new xorm.Engine and sets it as the db.DefaultContext
175-
// This function must never call .Sync2() if the provided migration function fails.
175+
// This function must never call .Sync() if the provided migration function fails.
176176
// When called from the "doctor" command, the migration function is a version check
177177
// that prevents the doctor from fixing anything in the database if the migration level
178178
// is different from the expected value.

models/db/engine_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func TestDumpDatabase(t *testing.T) {
2626
ID int64 `xorm:"pk autoincr"`
2727
Version int64
2828
}
29-
assert.NoError(t, db.GetEngine(db.DefaultContext).Sync2(new(Version)))
29+
assert.NoError(t, db.GetEngine(db.DefaultContext).Sync(new(Version)))
3030

3131
for _, dbType := range setting.SupportedDatabaseTypes {
3232
assert.NoError(t, db.DumpDatabase(filepath.Join(dir, dbType+".sql"), dbType))

models/issues/content_history_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func TestContentHistory(t *testing.T) {
4646
Name string
4747
FullName string
4848
}
49-
_ = db.GetEngine(dbCtx).Sync2(&User{})
49+
_ = db.GetEngine(dbCtx).Sync(&User{})
5050

5151
list1, _ := issues_model.FetchIssueContentHistoryList(dbCtx, 10, 0)
5252
assert.Len(t, list1, 3)

models/migrations/base/db_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func Test_DropTableColumns(t *testing.T) {
3838

3939
for i := range columns {
4040
x.SetMapper(names.GonicMapper{})
41-
if err := x.Sync2(new(DropTest)); err != nil {
41+
if err := x.Sync(new(DropTest)); err != nil {
4242
t.Errorf("unable to create DropTest table: %v", err)
4343
return
4444
}
@@ -65,7 +65,7 @@ func Test_DropTableColumns(t *testing.T) {
6565
}
6666
for j := range columns[i+1:] {
6767
x.SetMapper(names.GonicMapper{})
68-
if err := x.Sync2(new(DropTest)); err != nil {
68+
if err := x.Sync(new(DropTest)); err != nil {
6969
t.Errorf("unable to create DropTest table: %v", err)
7070
return
7171
}

models/migrations/base/tests.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func PrepareTestEnv(t *testing.T, skip int, syncModels ...any) (*xorm.Engine, fu
8181
}
8282

8383
if len(syncModels) > 0 {
84-
if err := x.Sync2(syncModels...); err != nil {
84+
if err := x.Sync(syncModels...); err != nil {
8585
t.Errorf("error during sync: %v", err)
8686
return x, deferFn
8787
}

models/migrations/v1_10/v100.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func UpdateMigrationServiceTypes(x *xorm.Engine) error {
1818
OriginalURL string `xorm:"VARCHAR(2048)"`
1919
}
2020

21-
if err := x.Sync2(new(Repository)); err != nil {
21+
if err := x.Sync(new(Repository)); err != nil {
2222
return err
2323
}
2424

@@ -78,5 +78,5 @@ func UpdateMigrationServiceTypes(x *xorm.Engine) error {
7878
ExpiresAt time.Time
7979
}
8080

81-
return x.Sync2(new(ExternalLoginUser))
81+
return x.Sync(new(ExternalLoginUser))
8282
}

models/migrations/v1_10/v101.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ func ChangeSomeColumnsLengthOfExternalLoginUser(x *xorm.Engine) error {
1414
RefreshToken string `xorm:"TEXT"`
1515
}
1616

17-
return x.Sync2(new(ExternalLoginUser))
17+
return x.Sync(new(ExternalLoginUser))
1818
}

models/migrations/v1_10/v88.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func AddCommitStatusContext(x *xorm.Engine) error {
2121
Context string `xorm:"TEXT"`
2222
}
2323

24-
if err := x.Sync2(new(CommitStatus)); err != nil {
24+
if err := x.Sync(new(CommitStatus)); err != nil {
2525
return err
2626
}
2727

models/migrations/v1_10/v89.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ func AddOriginalMigrationInfo(x *xorm.Engine) error {
1212
OriginalAuthorID int64
1313
}
1414

15-
if err := x.Sync2(new(Issue)); err != nil {
15+
if err := x.Sync(new(Issue)); err != nil {
1616
return err
1717
}
1818

@@ -22,7 +22,7 @@ func AddOriginalMigrationInfo(x *xorm.Engine) error {
2222
OriginalAuthorID int64
2323
}
2424

25-
if err := x.Sync2(new(Comment)); err != nil {
25+
if err := x.Sync(new(Comment)); err != nil {
2626
return err
2727
}
2828

@@ -31,5 +31,5 @@ func AddOriginalMigrationInfo(x *xorm.Engine) error {
3131
OriginalURL string
3232
}
3333

34-
return x.Sync2(new(Repository))
34+
return x.Sync(new(Repository))
3535
}

models/migrations/v1_10/v90.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ func ChangeSomeColumnsLengthOfRepo(x *xorm.Engine) error {
1313
OriginalURL string `xorm:"VARCHAR(2048)"`
1414
}
1515

16-
return x.Sync2(new(Repository))
16+
return x.Sync(new(Repository))
1717
}

models/migrations/v1_10/v91.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ func AddIndexOnRepositoryAndComment(x *xorm.Engine) error {
1111
OwnerID int64 `xorm:"index"`
1212
}
1313

14-
if err := x.Sync2(new(Repository)); err != nil {
14+
if err := x.Sync(new(Repository)); err != nil {
1515
return err
1616
}
1717

@@ -21,5 +21,5 @@ func AddIndexOnRepositoryAndComment(x *xorm.Engine) error {
2121
ReviewID int64 `xorm:"index"`
2222
}
2323

24-
return x.Sync2(new(Comment))
24+
return x.Sync(new(Comment))
2525
}

models/migrations/v1_10/v93.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ func AddEmailNotificationEnabledToUser(x *xorm.Engine) error {
1111
EmailNotificationsPreference string `xorm:"VARCHAR(20) NOT NULL DEFAULT 'enabled'"`
1212
}
1313

14-
return x.Sync2(new(User))
14+
return x.Sync(new(User))
1515
}

models/migrations/v1_10/v94.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ func AddStatusCheckColumnsForProtectedBranches(x *xorm.Engine) error {
1111
StatusCheckContexts []string `xorm:"JSON TEXT"`
1212
}
1313

14-
if err := x.Sync2(new(ProtectedBranch)); err != nil {
14+
if err := x.Sync(new(ProtectedBranch)); err != nil {
1515
return err
1616
}
1717

models/migrations/v1_10/v95.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ func AddCrossReferenceColumns(x *xorm.Engine) error {
1515
RefIsPull bool
1616
}
1717

18-
return x.Sync2(new(Comment))
18+
return x.Sync(new(Comment))
1919
}

models/migrations/v1_10/v97.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ func AddRepoAdminChangeTeamAccessColumnForUser(x *xorm.Engine) error {
1010
RepoAdminChangeTeamAccess bool `xorm:"NOT NULL DEFAULT false"`
1111
}
1212

13-
return x.Sync2(new(User))
13+
return x.Sync(new(User))
1414
}

models/migrations/v1_10/v98.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ func AddOriginalAuthorOnMigratedReleases(x *xorm.Engine) error {
1212
OriginalAuthorID int64 `xorm:"index"`
1313
}
1414

15-
return x.Sync2(new(Release))
15+
return x.Sync(new(Release))
1616
}

models/migrations/v1_10/v99.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@ func AddTaskTable(x *xorm.Engine) error {
3434
Status int `xorm:"NOT NULL DEFAULT 0"`
3535
}
3636

37-
return x.Sync2(new(Task), new(Repository))
37+
return x.Sync(new(Task), new(Repository))
3838
}

models/migrations/v1_11/v103.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ func AddWhitelistDeployKeysToBranches(x *xorm.Engine) error {
1313
WhitelistDeployKeys bool `xorm:"NOT NULL DEFAULT false"`
1414
}
1515

16-
return x.Sync2(new(ProtectedBranch))
16+
return x.Sync(new(ProtectedBranch))
1717
}

models/migrations/v1_11/v104.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func RemoveLabelUneededCols(x *xorm.Engine) error {
1515
QueryString string
1616
IsSelected bool
1717
}
18-
if err := x.Sync2(new(Label)); err != nil {
18+
if err := x.Sync(new(Label)); err != nil {
1919
return err
2020
}
2121

models/migrations/v1_11/v105.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func AddTeamIncludesAllRepositories(x *xorm.Engine) error {
1313
IncludesAllRepositories bool `xorm:"NOT NULL DEFAULT false"`
1414
}
1515

16-
if err := x.Sync2(new(Team)); err != nil {
16+
if err := x.Sync(new(Team)); err != nil {
1717
return err
1818
}
1919

models/migrations/v1_11/v106.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type Watch struct {
1717
}
1818

1919
func AddModeColumnToWatch(x *xorm.Engine) error {
20-
if err := x.Sync2(new(Watch)); err != nil {
20+
if err := x.Sync(new(Watch)); err != nil {
2121
return err
2222
}
2323
_, err := x.Exec("UPDATE `watch` SET `mode` = 1")

models/migrations/v1_11/v107.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ func AddTemplateToRepo(x *xorm.Engine) error {
1313
TemplateID int64 `xorm:"INDEX"`
1414
}
1515

16-
return x.Sync2(new(Repository))
16+
return x.Sync(new(Repository))
1717
}

models/migrations/v1_11/v108.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ func AddCommentIDOnNotification(x *xorm.Engine) error {
1313
CommentID int64
1414
}
1515

16-
return x.Sync2(new(Notification))
16+
return x.Sync(new(Notification))
1717
}

models/migrations/v1_11/v109.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ func AddCanCreateOrgRepoColumnForTeam(x *xorm.Engine) error {
1212
CanCreateOrgRepo bool `xorm:"NOT NULL DEFAULT false"`
1313
}
1414

15-
return x.Sync2(new(Team))
15+
return x.Sync(new(Team))
1616
}

models/migrations/v1_11/v111.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ func AddBranchProtectionCanPushAndEnableWhitelist(x *xorm.Engine) error {
3636
IssueID int64 `xorm:"index"`
3737
}
3838

39-
if err := x.Sync2(new(ProtectedBranch)); err != nil {
39+
if err := x.Sync(new(ProtectedBranch)); err != nil {
4040
return err
4141
}
4242

43-
if err := x.Sync2(new(Review)); err != nil {
43+
if err := x.Sync(new(Review)); err != nil {
4444
return err
4545
}
4646

models/migrations/v1_11/v113.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ func FeatureChangeTargetBranch(x *xorm.Engine) error {
1515
NewRef string
1616
}
1717

18-
if err := x.Sync2(new(Comment)); err != nil {
19-
return fmt.Errorf("Sync2: %w", err)
18+
if err := x.Sync(new(Comment)); err != nil {
19+
return fmt.Errorf("Sync: %w", err)
2020
}
2121
return nil
2222
}

models/migrations/v1_11/v116.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func ExtendTrackedTimes(x *xorm.Engine) error {
2424
return err
2525
}
2626

27-
if err := sess.Sync2(new(TrackedTime)); err != nil {
27+
if err := sess.Sync(new(TrackedTime)); err != nil {
2828
return err
2929
}
3030

models/migrations/v1_12/v117.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ func AddBlockOnRejectedReviews(x *xorm.Engine) error {
1212
BlockOnRejectedReviews bool `xorm:"NOT NULL DEFAULT false"`
1313
}
1414

15-
return x.Sync2(new(ProtectedBranch))
15+
return x.Sync(new(ProtectedBranch))
1616
}

models/migrations/v1_12/v118.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ func AddReviewCommitAndStale(x *xorm.Engine) error {
1818
}
1919

2020
// Old reviews will have commit ID set to "" and not stale
21-
if err := x.Sync2(new(Review)); err != nil {
21+
if err := x.Sync(new(Review)); err != nil {
2222
return err
2323
}
24-
return x.Sync2(new(ProtectedBranch))
24+
return x.Sync(new(ProtectedBranch))
2525
}

models/migrations/v1_12/v120.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ func AddOwnerNameOnRepository(x *xorm.Engine) error {
1111
type Repository struct {
1212
OwnerName string
1313
}
14-
if err := x.Sync2(new(Repository)); err != nil {
14+
if err := x.Sync(new(Repository)); err != nil {
1515
return err
1616
}
1717
_, err := x.Exec("UPDATE repository SET owner_name = (SELECT name FROM `user` WHERE `user`.id = repository.owner_id)")

models/migrations/v1_12/v121.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ func AddIsRestricted(x *xorm.Engine) error {
1212
IsRestricted bool `xorm:"NOT NULL DEFAULT false"`
1313
}
1414

15-
return x.Sync2(new(User))
15+
return x.Sync(new(User))
1616
}

models/migrations/v1_12/v122.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ func AddRequireSignedCommits(x *xorm.Engine) error {
1212
RequireSignedCommits bool `xorm:"NOT NULL DEFAULT false"`
1313
}
1414

15-
return x.Sync2(new(ProtectedBranch))
15+
return x.Sync(new(ProtectedBranch))
1616
}

models/migrations/v1_12/v123.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ func AddReactionOriginals(x *xorm.Engine) error {
1313
OriginalAuthor string
1414
}
1515

16-
return x.Sync2(new(Reaction))
16+
return x.Sync(new(Reaction))
1717
}

models/migrations/v1_12/v124.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ func AddUserRepoMissingColumns(x *xorm.Engine) error {
1919
Topics []string `xorm:"TEXT JSON"`
2020
}
2121

22-
return x.Sync2(new(User), new(Repository))
22+
return x.Sync(new(User), new(Repository))
2323
}

models/migrations/v1_12/v125.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ func AddReviewMigrateInfo(x *xorm.Engine) error {
1515
OriginalAuthorID int64
1616
}
1717

18-
if err := x.Sync2(new(Review)); err != nil {
19-
return fmt.Errorf("Sync2: %w", err)
18+
if err := x.Sync(new(Review)); err != nil {
19+
return fmt.Errorf("Sync: %w", err)
2020
}
2121
return nil
2222
}

models/migrations/v1_12/v127.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ func AddLanguageStats(x *xorm.Engine) error {
3434
IndexerType RepoIndexerType `xorm:"INDEX(s) NOT NULL DEFAULT 0"`
3535
}
3636

37-
if err := x.Sync2(new(LanguageStat)); err != nil {
38-
return fmt.Errorf("Sync2: %w", err)
37+
if err := x.Sync(new(LanguageStat)); err != nil {
38+
return fmt.Errorf("Sync: %w", err)
3939
}
40-
if err := x.Sync2(new(RepoIndexerStatus)); err != nil {
41-
return fmt.Errorf("Sync2: %w", err)
40+
if err := x.Sync(new(RepoIndexerStatus)); err != nil {
41+
return fmt.Errorf("Sync: %w", err)
4242
}
4343
return nil
4444
}

0 commit comments

Comments
 (0)