Skip to content

Fix v85.go #6851

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 1 commit into from
May 5, 2019
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
24 changes: 21 additions & 3 deletions models/migrations/v85.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func hashAppToken(x *xorm.Engine) error {
Name string
Sha1 string
Token string `xorm:"-"`
TokenHash string `xorm:"UNIQUE"` // sha256 of token
TokenHash string // sha256 of token - we will ensure UNIQUE later
TokenSalt string
TokenLastEight string `xorm:"token_last_eight"`

Expand Down Expand Up @@ -74,7 +74,7 @@ func hashAppToken(x *xorm.Engine) error {
return err
}

if err := x.Sync2(new(AccessToken)); err != nil {
if err := sess.Sync2(new(AccessToken)); err != nil {
return fmt.Errorf("Sync2: %v", err)
}

Expand Down Expand Up @@ -130,6 +130,24 @@ func hashAppToken(x *xorm.Engine) error {
if err := dropTableColumns(sess, "access_token", "sha1"); err != nil {
return err
}
return sess.Commit()
if err := sess.Commit(); err != nil {
return err
}
return resyncHashAppTokenWithUniqueHash(x)
}

func resyncHashAppTokenWithUniqueHash(x *xorm.Engine) error {
// AccessToken see models/token.go
type AccessToken struct {
TokenHash string `xorm:"UNIQUE"` // sha256 of token - we will ensure UNIQUE later
}
sess := x.NewSession()
defer sess.Close()
if err := sess.Begin(); err != nil {
return err
}
if err := sess.Sync2(new(AccessToken)); err != nil {
return fmt.Errorf("Sync2: %v", err)
}
return sess.Commit()
}