You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
547 B

  1. package Database
  2. import (
  3. "log"
  4. "gorm.io/gorm"
  5. "PersonalWebsite/Variables"
  6. )
  7. func updateDefaultSidebarLinks() {
  8. var e error
  9. for name, link := range Variables.DefaultSidebarLinks {
  10. e = AddSidebarLink(name, link)
  11. if e != nil {
  12. log.Fatal(e)
  13. }
  14. }
  15. }
  16. func MigrateDB() error {
  17. var (
  18. migrator gorm.Migrator
  19. )
  20. migrator = DB.Migrator()
  21. if !migrator.HasTable(Post{}) {
  22. migrator.CreateTable(&Post{})
  23. }
  24. if !migrator.HasTable(SidebarLink{}) {
  25. migrator.CreateTable(&SidebarLink{})
  26. updateDefaultSidebarLinks()
  27. }
  28. return nil
  29. }