bin/models/models.go

28 lines
556 B
Go
Raw Permalink Normal View History

2023-09-11 23:26:50 +02:00
package models
import (
"reflect"
"github.com/sirupsen/logrus"
"gorm.io/gorm"
)
func DatabaseMigrations(db *gorm.DB) {
tables := []interface{}{
File{},
User{},
}
logrus.Infoln("Running database migrations.")
for _, table := range tables {
name := reflect.TypeOf(table).Name()
err := db.AutoMigrate(&table)
if err != nil {
logrus.WithError(err).WithField("table", name).Fatalln("Migration failed.")
} else {
logrus.WithField("table", name).Infoln("Migration successful.")
}
}
logrus.Infoln("Migrations ran successfully.")
}