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.

46 lines
900 B

  1. package database
  2. import (
  3. "log"
  4. "git.tovijaeschke.xyz/tovi/SuddenImpactRecords/models"
  5. "gorm.io/driver/postgres"
  6. "gorm.io/gorm"
  7. )
  8. const dbUrl = "postgres://postgres:@localhost:5432/sudden_impact_records"
  9. var (
  10. DB *gorm.DB
  11. )
  12. func Init() {
  13. var (
  14. err error
  15. )
  16. log.Println("Initializing database...")
  17. DB, err = gorm.Open(postgres.Open(dbUrl), &gorm.Config{})
  18. if err != nil {
  19. log.Fatalln(err)
  20. }
  21. log.Println("Running AutoMigrate on Post tables...")
  22. // Post tables
  23. DB.AutoMigrate(&models.PostImage{})
  24. DB.AutoMigrate(&models.PostVideo{})
  25. DB.AutoMigrate(&models.PostAudio{})
  26. DB.AutoMigrate(&models.PostLink{})
  27. DB.AutoMigrate(&models.Post{})
  28. log.Println("Running AutoMigrate on Subscription tables...")
  29. // Email subscription tables
  30. DB.AutoMigrate(&models.SubscriptionEmailAttachment{})
  31. DB.AutoMigrate(&models.SubscriptionEmail{})
  32. DB.AutoMigrate(&models.Subscription{})
  33. }