feat(logging): added in db and logging with websocket

This commit is contained in:
2025-07-22 19:59:06 -05:00
parent 623e19f028
commit 52ef39fd5c
9 changed files with 555 additions and 96 deletions

32
backend/utils/db/db.go Normal file
View File

@@ -0,0 +1,32 @@
package db
import (
"fmt"
"os"
"gorm.io/driver/postgres"
"gorm.io/gorm"
)
var DB *gorm.DB
func InitDB() error {
dsn := fmt.Sprintf("host=%s port=%s user=%s password=%s dbname=%s",
os.Getenv("DB_HOST"),
os.Getenv("DB_PORT"),
os.Getenv("DB_USER"),
os.Getenv("DB_PASSWORD"),
os.Getenv("DB_NAME"))
var err error
DB, err = gorm.Open(postgres.Open(dsn), &gorm.Config{})
if err != nil {
return fmt.Errorf("failed to connect to database: %v", err)
}
// Auto-migrate all models
DB.AutoMigrate(&Log{}) // Add other models here
return nil
}