You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

v30.go 942B

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Copyright 2017 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package migrations
  5. import (
  6. "fmt"
  7. "xorm.io/xorm"
  8. )
  9. func addExternalLoginUserPK(x *xorm.Engine) error {
  10. // ExternalLoginUser see models/external_login_user.go
  11. type ExternalLoginUser struct {
  12. ExternalID string `xorm:"pk NOT NULL"`
  13. UserID int64 `xorm:"INDEX NOT NULL"`
  14. LoginSourceID int64 `xorm:"pk NOT NULL"`
  15. }
  16. extlogins := make([]*ExternalLoginUser, 0, 6)
  17. if err := x.Find(&extlogins); err != nil {
  18. return fmt.Errorf("Find: %v", err)
  19. }
  20. if err := x.DropTables(new(ExternalLoginUser)); err != nil {
  21. return fmt.Errorf("DropTables: %v", err)
  22. }
  23. if err := x.Sync2(new(ExternalLoginUser)); err != nil {
  24. return fmt.Errorf("Sync2: %v", err)
  25. }
  26. if _, err := x.Insert(extlogins); err != nil {
  27. return fmt.Errorf("Insert: %v", err)
  28. }
  29. return nil
  30. }