package Database
|
|
|
|
import (
|
|
"log"
|
|
|
|
"gorm.io/gorm"
|
|
|
|
"PersonalWebsite/Variables"
|
|
)
|
|
|
|
func updateDefaultSidebarLinks() {
|
|
var e error
|
|
for name, link := range Variables.DefaultSidebarLinks {
|
|
e = AddSidebarLink(name, link)
|
|
if e != nil {
|
|
log.Fatal(e)
|
|
}
|
|
}
|
|
}
|
|
|
|
func MigrateDB() error {
|
|
var (
|
|
migrator gorm.Migrator
|
|
)
|
|
migrator = DB.Migrator()
|
|
|
|
if !migrator.HasTable(Post{}) {
|
|
migrator.CreateTable(&Post{})
|
|
}
|
|
|
|
if !migrator.HasTable(SidebarLink{}) {
|
|
migrator.CreateTable(&SidebarLink{})
|
|
updateDefaultSidebarLinks()
|
|
}
|
|
|
|
return nil
|
|
}
|