Skip to content

Upgrade xorm to v1.3.9 and improve some migrations Sync #29899

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ require (
mvdan.cc/xurls/v2 v2.5.0
strk.kbt.io/projects/go/libravatar v0.0.0-20191008002943-06d1c002b251
xorm.io/builder v0.3.13
xorm.io/xorm v1.3.8
xorm.io/xorm v1.3.9
)

require (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1064,5 +1064,5 @@ strk.kbt.io/projects/go/libravatar v0.0.0-20191008002943-06d1c002b251 h1:mUcz5b3
strk.kbt.io/projects/go/libravatar v0.0.0-20191008002943-06d1c002b251/go.mod h1:FJGmPh3vz9jSos1L/F91iAgnC/aejc0wIIrF2ZwJxdY=
xorm.io/builder v0.3.13 h1:a3jmiVVL19psGeXx8GIurTp7p0IIgqeDmwhcR6BAOAo=
xorm.io/builder v0.3.13/go.mod h1:aUW0S9eb9VCaPohFCH3j7czOx1PMW3i1HrSzbLYGBSE=
xorm.io/xorm v1.3.8 h1:CJmplmWqfSRpLWSPMmqz+so8toBp3m7ehuRehIWedZo=
xorm.io/xorm v1.3.8/go.mod h1:LsCCffeeYp63ssk0pKumP6l96WZcHix7ChpurcLNuMw=
xorm.io/xorm v1.3.9 h1:TUovzS0ko+IQ1XnNLfs5dqK1cJl1H5uHpWbWqAQ04nU=
xorm.io/xorm v1.3.9/go.mod h1:LsCCffeeYp63ssk0pKumP6l96WZcHix7ChpurcLNuMw=
6 changes: 5 additions & 1 deletion models/migrations/v1_21/v279.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,9 @@ func AddIndexToActionUserID(x *xorm.Engine) error {
UserID int64 `xorm:"INDEX"`
}

return x.Sync(new(Action))
_, err := x.SyncWithOptions(xorm.SyncOptions{
IgnoreDropIndices: true,
IgnoreConstrains: true,
}, new(Action))
return err
}
6 changes: 5 additions & 1 deletion models/migrations/v1_22/v284.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,9 @@ func AddIgnoreStaleApprovalsColumnToProtectedBranchTable(x *xorm.Engine) error {
type ProtectedBranch struct {
IgnoreStaleApprovals bool `xorm:"NOT NULL DEFAULT false"`
}
return x.Sync(new(ProtectedBranch))
_, err := x.SyncWithOptions(xorm.SyncOptions{
IgnoreIndices: true,
IgnoreConstrains: true,
}, new(ProtectedBranch))
return err
}
6 changes: 5 additions & 1 deletion models/migrations/v1_22/v285.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,9 @@ func AddPreviousDurationToActionRun(x *xorm.Engine) error {
PreviousDuration time.Duration
}

return x.Sync(&ActionRun{})
_, err := x.SyncWithOptions(xorm.SyncOptions{
IgnoreIndices: true,
IgnoreConstrains: true,
}, &ActionRun{})
return err
}
5 changes: 4 additions & 1 deletion models/migrations/v1_22/v286.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ func addObjectFormatNameToRepository(x *xorm.Engine) error {
ObjectFormatName string `xorm:"VARCHAR(6) NOT NULL DEFAULT 'sha1'"`
}

if err := x.Sync(new(Repository)); err != nil {
if _, err := x.SyncWithOptions(xorm.SyncOptions{
IgnoreIndices: true,
IgnoreConstrains: true,
}, new(Repository)); err != nil {
return err
}

Expand Down
5 changes: 4 additions & 1 deletion models/migrations/v1_22/v289.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ func AddDefaultWikiBranch(x *xorm.Engine) error {
ID int64
DefaultWikiBranch string
}
if err := x.Sync(&Repository{}); err != nil {
if _, err := x.SyncWithOptions(xorm.SyncOptions{
IgnoreIndices: true,
IgnoreConstrains: true,
}, &Repository{}); err != nil {
return err
}
_, err := x.Exec("UPDATE `repository` SET default_wiki_branch = 'master' WHERE (default_wiki_branch IS NULL) OR (default_wiki_branch = '')")
Expand Down
9 changes: 8 additions & 1 deletion models/migrations/v1_22/v290.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,12 @@ type HookTask struct {

func AddPayloadVersionToHookTaskTable(x *xorm.Engine) error {
// create missing column
return x.Sync(new(HookTask))
if _, err := x.SyncWithOptions(xorm.SyncOptions{
IgnoreIndices: true,
IgnoreConstrains: true,
}, new(HookTask)); err != nil {
return err
}
_, err := x.Exec("UPDATE hook_task SET payload_version = 1 WHERE payload_version IS NULL")
Comment on lines +16 to +22
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to switch these statements around.
Otherwise, it seems inconsistent.
Why is it even necessary, even though it wasn't previously?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This maybe an unrelated change to this PR. I just found v290 missed the update operations. Because creating a new column with default value will not update the old record automatically. It should be a bug of previous PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe split this change out into separate PR?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think fixing it here is fine ... just add a doctor command to address this things ?

return err
}
6 changes: 5 additions & 1 deletion models/migrations/v1_22/v291.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,9 @@ func AddCommentIDIndexofAttachment(x *xorm.Engine) error {
CommentID int64 `xorm:"INDEX"`
}

return x.Sync(&Attachment{})
_, err := x.SyncWithOptions(xorm.SyncOptions{
IgnoreDropIndices: true,
IgnoreConstrains: true,
}, &Attachment{})
return err
}