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.

convert.go 737B

123456789101112131415161718192021222324252627
  1. // Copyright 2019 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 models
  5. import "fmt"
  6. // ConvertUtf8ToUtf8mb4 converts database and tables from utf8 to utf8mb4 if it's mysql
  7. func ConvertUtf8ToUtf8mb4() error {
  8. _, err := x.Exec(fmt.Sprintf("ALTER DATABASE `%s` CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci", DbCfg.Name))
  9. if err != nil {
  10. return err
  11. }
  12. tables, err := x.DBMetas()
  13. if err != nil {
  14. return err
  15. }
  16. for _, table := range tables {
  17. if _, err := x.Exec(fmt.Sprintf("ALTER TABLE `%s` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;", table.Name)); err != nil {
  18. return err
  19. }
  20. }
  21. return nil
  22. }