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"
|
|
|
|
|
2022-09-16 14:21:43 +00:00
|
|
|
"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"
|
|
|
|
)
|
|
|
|
|
2022-09-15 09:14:03 +00:00
|
|
|
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) {
|
2022-09-15 09:14:03 +00:00
|
|
|
db = d
|
2022-09-16 14:21:43 +00:00
|
|
|
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
|
|
|
}
|