mirror of
https://github.com/GlueOps/autoglue.git
synced 2026-02-13 21:00:06 +01:00
initial rebuild
This commit is contained in:
42
internal/db/database.go
Normal file
42
internal/db/database.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/glueops/autoglue/internal/db/models"
|
||||
"github.com/spf13/viper"
|
||||
"gorm.io/driver/postgres"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
var DB *gorm.DB
|
||||
|
||||
func Connect() {
|
||||
dsn := viper.GetString("database.dsn")
|
||||
|
||||
if dsn == "" {
|
||||
log.Fatal("DRAGON_DATABASE_DSN is not set")
|
||||
}
|
||||
|
||||
var err error
|
||||
DB, err = gorm.Open(postgres.Open(dsn), &gorm.Config{})
|
||||
if err != nil {
|
||||
log.Fatalf("failed to connect to DB: %v", err)
|
||||
}
|
||||
|
||||
err = DB.AutoMigrate(
|
||||
&models.EmailVerification{},
|
||||
&models.Invitation{},
|
||||
&models.Member{},
|
||||
&models.Organization{},
|
||||
&models.PasswordReset{},
|
||||
&models.RefreshToken{},
|
||||
&models.User{},
|
||||
)
|
||||
if err != nil {
|
||||
log.Fatalf("auto migration failed: %v", err)
|
||||
}
|
||||
|
||||
fmt.Println("database connected and migrated")
|
||||
}
|
||||
Reference in New Issue
Block a user