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.

35 lines
500 B

3 years ago
  1. package database
  2. import (
  3. "log"
  4. "git.tovijaeschke.xyz/tovi/JumboPetstore/models"
  5. "gorm.io/driver/postgres"
  6. "gorm.io/gorm"
  7. )
  8. const (
  9. dbUrl = "postgres://postgres:@localhost:5432/petstore"
  10. )
  11. var (
  12. DB *gorm.DB
  13. )
  14. func Init() {
  15. var (
  16. err error
  17. )
  18. DB, err = gorm.Open(postgres.Open(dbUrl), &gorm.Config{})
  19. if err != nil {
  20. log.Fatalln(err)
  21. }
  22. DB.AutoMigrate(&models.PetCategory{})
  23. DB.AutoMigrate(&models.PetTag{})
  24. DB.AutoMigrate(&models.PetPhoto{})
  25. DB.AutoMigrate(&models.Pet{})
  26. }