28 lines
556 B
Go
28 lines
556 B
Go
|
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.")
|
||
|
}
|