Skip to content

Commit

Permalink
Rename Sync2 -> Sync
Browse files Browse the repository at this point in the history
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
```
  • Loading branch information
delvh committed Aug 13, 2023
1 parent 50fc22e commit af6d55f
Show file tree
Hide file tree
Showing 122 changed files with 184 additions and 184 deletions.
2 changes: 1 addition & 1 deletion docs/content/administration/command-line.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ Sometimes when there are migrations the old columns and default values may be le
unchanged in the database schema. This may lead to warning such as:

```
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
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
```

You can cause Gitea to recreate these tables and copy the old data into the new table
Expand Down
2 changes: 1 addition & 1 deletion docs/content/administration/command-line.zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ AuthorizedKeysCommand /path/to/gitea keys -e git -u %u -t %t -k %k
有时,在迁移时,旧的列和默认值可能会在数据库模式中保持不变。这可能会导致警告,如下所示:

```
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
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
```

您可以通过以下方式让 Gitea 重新创建这些表,并将旧数据复制到新表中,并适当设置默认值:
Expand Down
2 changes: 1 addition & 1 deletion docs/content/help/faq.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ Sometimes when there are migrations the old columns and default values may be le
unchanged in the database schema. This may lead to warning such as:

```
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
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
```

These can safely be ignored, but you are able to stop these warnings by getting Gitea to recreate these tables using:
Expand Down
2 changes: 1 addition & 1 deletion docs/content/help/faq.zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ SystemD 上的标准输出默认会写入日志记录中。您可以尝试使用
这可能会导致警告,例如:

```
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
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
```

可以安全地忽略这些警告,但您可以通过让 Gitea 重新创建这些表来停止这些警告,使用以下命令:
Expand Down
4 changes: 2 additions & 2 deletions models/db/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ type Engine interface {
Limit(limit int, start ...int) *xorm.Session
NoAutoTime() *xorm.Session
SumInt(bean any, columnName string) (res int64, err error)
Sync2(...any) error
Sync(...any) error
Select(string) *xorm.Session
NotIn(string, ...any) *xorm.Session
OrderBy(any, ...any) *xorm.Session
Expand Down Expand Up @@ -172,7 +172,7 @@ func UnsetDefaultEngine() {
}

// InitEngineWithMigration initializes a new xorm.Engine and sets it as the db.DefaultContext
// This function must never call .Sync2() if the provided migration function fails.
// This function must never call .Sync() if the provided migration function fails.
// When called from the "doctor" command, the migration function is a version check
// that prevents the doctor from fixing anything in the database if the migration level
// is different from the expected value.
Expand Down
2 changes: 1 addition & 1 deletion models/db/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestDumpDatabase(t *testing.T) {
ID int64 `xorm:"pk autoincr"`
Version int64
}
assert.NoError(t, db.GetEngine(db.DefaultContext).Sync2(new(Version)))
assert.NoError(t, db.GetEngine(db.DefaultContext).Sync(new(Version)))

for _, dbType := range setting.SupportedDatabaseTypes {
assert.NoError(t, db.DumpDatabase(filepath.Join(dir, dbType+".sql"), dbType))
Expand Down
2 changes: 1 addition & 1 deletion models/issues/content_history_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestContentHistory(t *testing.T) {
Name string
FullName string
}
_ = db.GetEngine(dbCtx).Sync2(&User{})
_ = db.GetEngine(dbCtx).Sync(&User{})

list1, _ := issues_model.FetchIssueContentHistoryList(dbCtx, 10, 0)
assert.Len(t, list1, 3)
Expand Down
4 changes: 2 additions & 2 deletions models/migrations/base/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func Test_DropTableColumns(t *testing.T) {

for i := range columns {
x.SetMapper(names.GonicMapper{})
if err := x.Sync2(new(DropTest)); err != nil {
if err := x.Sync(new(DropTest)); err != nil {
t.Errorf("unable to create DropTest table: %v", err)
return
}
Expand All @@ -65,7 +65,7 @@ func Test_DropTableColumns(t *testing.T) {
}
for j := range columns[i+1:] {
x.SetMapper(names.GonicMapper{})
if err := x.Sync2(new(DropTest)); err != nil {
if err := x.Sync(new(DropTest)); err != nil {
t.Errorf("unable to create DropTest table: %v", err)
return
}
Expand Down
2 changes: 1 addition & 1 deletion models/migrations/base/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func PrepareTestEnv(t *testing.T, skip int, syncModels ...any) (*xorm.Engine, fu
}

if len(syncModels) > 0 {
if err := x.Sync2(syncModels...); err != nil {
if err := x.Sync(syncModels...); err != nil {
t.Errorf("error during sync: %v", err)
return x, deferFn
}
Expand Down
4 changes: 2 additions & 2 deletions models/migrations/v1_10/v100.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func UpdateMigrationServiceTypes(x *xorm.Engine) error {
OriginalURL string `xorm:"VARCHAR(2048)"`
}

if err := x.Sync2(new(Repository)); err != nil {
if err := x.Sync(new(Repository)); err != nil {
return err
}

Expand Down Expand Up @@ -78,5 +78,5 @@ func UpdateMigrationServiceTypes(x *xorm.Engine) error {
ExpiresAt time.Time
}

return x.Sync2(new(ExternalLoginUser))
return x.Sync(new(ExternalLoginUser))
}
2 changes: 1 addition & 1 deletion models/migrations/v1_10/v101.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ func ChangeSomeColumnsLengthOfExternalLoginUser(x *xorm.Engine) error {
RefreshToken string `xorm:"TEXT"`
}

return x.Sync2(new(ExternalLoginUser))
return x.Sync(new(ExternalLoginUser))
}
2 changes: 1 addition & 1 deletion models/migrations/v1_10/v88.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func AddCommitStatusContext(x *xorm.Engine) error {
Context string `xorm:"TEXT"`
}

if err := x.Sync2(new(CommitStatus)); err != nil {
if err := x.Sync(new(CommitStatus)); err != nil {
return err
}

Expand Down
6 changes: 3 additions & 3 deletions models/migrations/v1_10/v89.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func AddOriginalMigrationInfo(x *xorm.Engine) error {
OriginalAuthorID int64
}

if err := x.Sync2(new(Issue)); err != nil {
if err := x.Sync(new(Issue)); err != nil {
return err
}

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

if err := x.Sync2(new(Comment)); err != nil {
if err := x.Sync(new(Comment)); err != nil {
return err
}

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

return x.Sync2(new(Repository))
return x.Sync(new(Repository))
}
2 changes: 1 addition & 1 deletion models/migrations/v1_10/v90.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ func ChangeSomeColumnsLengthOfRepo(x *xorm.Engine) error {
OriginalURL string `xorm:"VARCHAR(2048)"`
}

return x.Sync2(new(Repository))
return x.Sync(new(Repository))
}
4 changes: 2 additions & 2 deletions models/migrations/v1_10/v91.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func AddIndexOnRepositoryAndComment(x *xorm.Engine) error {
OwnerID int64 `xorm:"index"`
}

if err := x.Sync2(new(Repository)); err != nil {
if err := x.Sync(new(Repository)); err != nil {
return err
}

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

return x.Sync2(new(Comment))
return x.Sync(new(Comment))
}
2 changes: 1 addition & 1 deletion models/migrations/v1_10/v93.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ func AddEmailNotificationEnabledToUser(x *xorm.Engine) error {
EmailNotificationsPreference string `xorm:"VARCHAR(20) NOT NULL DEFAULT 'enabled'"`
}

return x.Sync2(new(User))
return x.Sync(new(User))
}
2 changes: 1 addition & 1 deletion models/migrations/v1_10/v94.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func AddStatusCheckColumnsForProtectedBranches(x *xorm.Engine) error {
StatusCheckContexts []string `xorm:"JSON TEXT"`
}

if err := x.Sync2(new(ProtectedBranch)); err != nil {
if err := x.Sync(new(ProtectedBranch)); err != nil {
return err
}

Expand Down
2 changes: 1 addition & 1 deletion models/migrations/v1_10/v95.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ func AddCrossReferenceColumns(x *xorm.Engine) error {
RefIsPull bool
}

return x.Sync2(new(Comment))
return x.Sync(new(Comment))
}
2 changes: 1 addition & 1 deletion models/migrations/v1_10/v97.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ func AddRepoAdminChangeTeamAccessColumnForUser(x *xorm.Engine) error {
RepoAdminChangeTeamAccess bool `xorm:"NOT NULL DEFAULT false"`
}

return x.Sync2(new(User))
return x.Sync(new(User))
}
2 changes: 1 addition & 1 deletion models/migrations/v1_10/v98.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ func AddOriginalAuthorOnMigratedReleases(x *xorm.Engine) error {
OriginalAuthorID int64 `xorm:"index"`
}

return x.Sync2(new(Release))
return x.Sync(new(Release))
}
2 changes: 1 addition & 1 deletion models/migrations/v1_10/v99.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ func AddTaskTable(x *xorm.Engine) error {
Status int `xorm:"NOT NULL DEFAULT 0"`
}

return x.Sync2(new(Task), new(Repository))
return x.Sync(new(Task), new(Repository))
}
2 changes: 1 addition & 1 deletion models/migrations/v1_11/v103.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ func AddWhitelistDeployKeysToBranches(x *xorm.Engine) error {
WhitelistDeployKeys bool `xorm:"NOT NULL DEFAULT false"`
}

return x.Sync2(new(ProtectedBranch))
return x.Sync(new(ProtectedBranch))
}
2 changes: 1 addition & 1 deletion models/migrations/v1_11/v104.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func RemoveLabelUneededCols(x *xorm.Engine) error {
QueryString string
IsSelected bool
}
if err := x.Sync2(new(Label)); err != nil {
if err := x.Sync(new(Label)); err != nil {
return err
}

Expand Down
2 changes: 1 addition & 1 deletion models/migrations/v1_11/v105.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func AddTeamIncludesAllRepositories(x *xorm.Engine) error {
IncludesAllRepositories bool `xorm:"NOT NULL DEFAULT false"`
}

if err := x.Sync2(new(Team)); err != nil {
if err := x.Sync(new(Team)); err != nil {
return err
}

Expand Down
2 changes: 1 addition & 1 deletion models/migrations/v1_11/v106.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type Watch struct {
}

func AddModeColumnToWatch(x *xorm.Engine) error {
if err := x.Sync2(new(Watch)); err != nil {
if err := x.Sync(new(Watch)); err != nil {
return err
}
_, err := x.Exec("UPDATE `watch` SET `mode` = 1")
Expand Down
2 changes: 1 addition & 1 deletion models/migrations/v1_11/v107.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ func AddTemplateToRepo(x *xorm.Engine) error {
TemplateID int64 `xorm:"INDEX"`
}

return x.Sync2(new(Repository))
return x.Sync(new(Repository))
}
2 changes: 1 addition & 1 deletion models/migrations/v1_11/v108.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ func AddCommentIDOnNotification(x *xorm.Engine) error {
CommentID int64
}

return x.Sync2(new(Notification))
return x.Sync(new(Notification))
}
2 changes: 1 addition & 1 deletion models/migrations/v1_11/v109.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ func AddCanCreateOrgRepoColumnForTeam(x *xorm.Engine) error {
CanCreateOrgRepo bool `xorm:"NOT NULL DEFAULT false"`
}

return x.Sync2(new(Team))
return x.Sync(new(Team))
}
4 changes: 2 additions & 2 deletions models/migrations/v1_11/v111.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ func AddBranchProtectionCanPushAndEnableWhitelist(x *xorm.Engine) error {
IssueID int64 `xorm:"index"`
}

if err := x.Sync2(new(ProtectedBranch)); err != nil {
if err := x.Sync(new(ProtectedBranch)); err != nil {
return err
}

if err := x.Sync2(new(Review)); err != nil {
if err := x.Sync(new(Review)); err != nil {
return err
}

Expand Down
4 changes: 2 additions & 2 deletions models/migrations/v1_11/v113.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ func FeatureChangeTargetBranch(x *xorm.Engine) error {
NewRef string
}

if err := x.Sync2(new(Comment)); err != nil {
return fmt.Errorf("Sync2: %w", err)
if err := x.Sync(new(Comment)); err != nil {
return fmt.Errorf("Sync: %w", err)
}
return nil
}
2 changes: 1 addition & 1 deletion models/migrations/v1_11/v116.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func ExtendTrackedTimes(x *xorm.Engine) error {
return err
}

if err := sess.Sync2(new(TrackedTime)); err != nil {
if err := sess.Sync(new(TrackedTime)); err != nil {
return err
}

Expand Down
2 changes: 1 addition & 1 deletion models/migrations/v1_12/v117.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ func AddBlockOnRejectedReviews(x *xorm.Engine) error {
BlockOnRejectedReviews bool `xorm:"NOT NULL DEFAULT false"`
}

return x.Sync2(new(ProtectedBranch))
return x.Sync(new(ProtectedBranch))
}
4 changes: 2 additions & 2 deletions models/migrations/v1_12/v118.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ func AddReviewCommitAndStale(x *xorm.Engine) error {
}

// Old reviews will have commit ID set to "" and not stale
if err := x.Sync2(new(Review)); err != nil {
if err := x.Sync(new(Review)); err != nil {
return err
}
return x.Sync2(new(ProtectedBranch))
return x.Sync(new(ProtectedBranch))
}
2 changes: 1 addition & 1 deletion models/migrations/v1_12/v120.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func AddOwnerNameOnRepository(x *xorm.Engine) error {
type Repository struct {
OwnerName string
}
if err := x.Sync2(new(Repository)); err != nil {
if err := x.Sync(new(Repository)); err != nil {
return err
}
_, err := x.Exec("UPDATE repository SET owner_name = (SELECT name FROM `user` WHERE `user`.id = repository.owner_id)")
Expand Down
2 changes: 1 addition & 1 deletion models/migrations/v1_12/v121.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ func AddIsRestricted(x *xorm.Engine) error {
IsRestricted bool `xorm:"NOT NULL DEFAULT false"`
}

return x.Sync2(new(User))
return x.Sync(new(User))
}
2 changes: 1 addition & 1 deletion models/migrations/v1_12/v122.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ func AddRequireSignedCommits(x *xorm.Engine) error {
RequireSignedCommits bool `xorm:"NOT NULL DEFAULT false"`
}

return x.Sync2(new(ProtectedBranch))
return x.Sync(new(ProtectedBranch))
}
2 changes: 1 addition & 1 deletion models/migrations/v1_12/v123.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ func AddReactionOriginals(x *xorm.Engine) error {
OriginalAuthor string
}

return x.Sync2(new(Reaction))
return x.Sync(new(Reaction))
}
2 changes: 1 addition & 1 deletion models/migrations/v1_12/v124.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ func AddUserRepoMissingColumns(x *xorm.Engine) error {
Topics []string `xorm:"TEXT JSON"`
}

return x.Sync2(new(User), new(Repository))
return x.Sync(new(User), new(Repository))
}
4 changes: 2 additions & 2 deletions models/migrations/v1_12/v125.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ func AddReviewMigrateInfo(x *xorm.Engine) error {
OriginalAuthorID int64
}

if err := x.Sync2(new(Review)); err != nil {
return fmt.Errorf("Sync2: %w", err)
if err := x.Sync(new(Review)); err != nil {
return fmt.Errorf("Sync: %w", err)
}
return nil
}
8 changes: 4 additions & 4 deletions models/migrations/v1_12/v127.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ func AddLanguageStats(x *xorm.Engine) error {
IndexerType RepoIndexerType `xorm:"INDEX(s) NOT NULL DEFAULT 0"`
}

if err := x.Sync2(new(LanguageStat)); err != nil {
return fmt.Errorf("Sync2: %w", err)
if err := x.Sync(new(LanguageStat)); err != nil {
return fmt.Errorf("Sync: %w", err)
}
if err := x.Sync2(new(RepoIndexerStatus)); err != nil {
return fmt.Errorf("Sync2: %w", err)
if err := x.Sync(new(RepoIndexerStatus)); err != nil {
return fmt.Errorf("Sync: %w", err)
}
return nil
}
Loading

0 comments on commit af6d55f

Please sign in to comment.