Fork to maintain patches against the official gitea for https://code.ceondo.com https://github.com/go-gitea/gitea

v41.go 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright 2017 The Gitea 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. "code.gitea.io/gitea/models"
  8. "github.com/go-xorm/xorm"
  9. )
  10. func addDefaultValueToUserProhibitLogin(x *xorm.Engine) (err error) {
  11. user := &models.User{
  12. ProhibitLogin: false,
  13. }
  14. if _, err := x.Where("`prohibit_login` IS NULL").Cols("prohibit_login").Update(user); err != nil {
  15. return err
  16. }
  17. dialect := x.Dialect().DriverName()
  18. switch dialect {
  19. case "mysql":
  20. _, err = x.Exec("ALTER TABLE user MODIFY `prohibit_login` tinyint(1) NOT NULL DEFAULT 0")
  21. case "postgres":
  22. _, err = x.Exec("ALTER TABLE \"user\" ALTER COLUMN `prohibit_login` SET NOT NULL, ALTER COLUMN `prohibit_login` SET DEFAULT false")
  23. case "mssql":
  24. // xorm already set DEFAULT 0 for data type BIT in mssql
  25. _, err = x.Exec(`ALTER TABLE [user] ALTER COLUMN "prohibit_login" BIT NOT NULL`)
  26. case "sqlite3":
  27. }
  28. if err != nil {
  29. return fmt.Errorf("Error changing user prohibit_login column definition: %v", err)
  30. }
  31. return err
  32. }