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.

42 lines
1.2 KiB

  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. "code.gitea.io/gitea/models"
  7. "code.gitea.io/gitea/modules/log"
  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. // Ignoring this error in case we run this migration second time (after migration reordering)
  30. log.Warn("Error changing user prohibit_login column definition (skipping): %v", err)
  31. }
  32. return nil
  33. }