Skip to content
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

Fix the v78 migration script #5776

Merged
Merged
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
12 changes: 12 additions & 0 deletions models/migrations/v78.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func renameRepoIsBareToIsEmpty(x *xorm.Engine) error {
IsEmpty bool `xorm:"INDEX"`
}

// First remove the index
sess := x.NewSession()
defer sess.Close()
if err := sess.Begin(); err != nil {
Expand All @@ -37,6 +38,17 @@ func renameRepoIsBareToIsEmpty(x *xorm.Engine) error {
return fmt.Errorf("Drop index failed: %v", err)
}

if err = sess.Commit(); err != nil {
return err
}

// Then reset the values
sess = x.NewSession()
defer sess.Close()
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 this two lines is unnecessary but xorm should work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hiya @lunny, dropping the index and sync2 have to be in different transactions on sqlite as the schema becomes locked by sync2 which conflicts with the index drop. Therefore the original single transaction fails on sqlite and is rolled back.

Copy link
Member

Choose a reason for hiding this comment

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

@zeripath I know. I mean

sess := x.NewSession()
defer sess.Close()

sess.Begin()
sess.Commit()

sess.Begin()
sess.Commit()

The second NewSession is uncessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, so xorm would just create a new transaction in the same session after the first one is committed.

Fair enough. Clean it up if you like and/or think it will cause problems in future.

if err := sess.Begin(); err != nil {
return err
}

if err := sess.Sync2(new(Repository)); err != nil {
return err
}
Expand Down