Skip to content

Commit

Permalink
fix: set CHARSET to utf8mb4 if use mysql
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Sep 15, 2022
1 parent f22232d commit 86a625c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 3 additions & 0 deletions internal/bootstrap/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ func InitDB() {
dsn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8mb4&parseTime=True&loc=Local&tls=%s",
database.User, database.Password, database.Host, database.Port, database.Name, database.SSLMode)
dB, err = gorm.Open(mysql.Open(dsn), gormConfig)
if err == nil {
dB = dB.Set("gorm:table_options", "ENGINE=InnoDB CHARSET=utf8mb4")
}
}
case "postgres":
{
Expand Down
4 changes: 2 additions & 2 deletions internal/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (
"gorm.io/gorm"
)

var db gorm.DB
var db *gorm.DB

func Init(d *gorm.DB) {
db = *d
db = d
err := db.AutoMigrate(new(model.Storage), new(model.User), new(model.Meta), new(model.SettingItem))
if err != nil {
log.Fatalf("failed migrate database: %s", err.Error())
Expand Down

0 comments on commit 86a625c

Please sign in to comment.