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.

36 lines
573 B

  1. package database
  2. import (
  3. "log"
  4. "git.tovijaeschke.xyz/tovi/personal_website/variables"
  5. "gorm.io/gorm"
  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. }