diff options
author | zeripath <art27@cantab.net> | 2019-05-05 14:47:42 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-05 14:47:42 +0100 |
commit | 07bcccf9ce805ff29453d295533c96550a03c627 (patch) | |
tree | 8209283c6811aaad23919580d36faf3d1df88cf9 /models/migrations | |
parent | d27bf72530864c0b81b135d3200d65722e82a6f3 (diff) | |
download | gitea-07bcccf9ce805ff29453d295533c96550a03c627.tar.gz gitea-07bcccf9ce805ff29453d295533c96550a03c627.zip |
Fix v85.go: Set UNIQUE constraint later (#6851)
Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'models/migrations')
-rw-r--r-- | models/migrations/v85.go | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/models/migrations/v85.go b/models/migrations/v85.go index 28f6ac146d..1fe85ac408 100644 --- a/models/migrations/v85.go +++ b/models/migrations/v85.go @@ -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"` @@ -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) } @@ -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() } |