alist/internal/db/db.go

25 lines
601 B
Go
Raw Normal View History

2022-06-25 13:36:35 +00:00
package db
2022-06-09 09:11:46 +00:00
import (
2022-08-03 06:26:59 +00:00
"log"
"github.com/alist-org/alist/v3/internal/conf"
2022-06-14 11:44:25 +00:00
"github.com/alist-org/alist/v3/internal/model"
2022-06-09 09:11:46 +00:00
"gorm.io/gorm"
)
var db *gorm.DB
2022-06-14 11:44:25 +00:00
2022-06-16 08:06:10 +00:00
func Init(d *gorm.DB) {
db = d
var err error
if conf.Conf.Database.Type == "mysql" {
err = db.Set("gorm:table_options", "ENGINE=InnoDB CHARSET=utf8mb4").AutoMigrate(new(model.Storage), new(model.User), new(model.Meta), new(model.SettingItem))
} else {
err = db.AutoMigrate(new(model.Storage), new(model.User), new(model.Meta), new(model.SettingItem))
}
2022-06-16 08:06:10 +00:00
if err != nil {
log.Fatalf("failed migrate database: %s", err.Error())
}
2022-06-14 11:44:25 +00:00
}