refactor(ws): ws logging and channel manager added no auth currently
This commit is contained in:
@@ -12,7 +12,12 @@ var DB *gorm.DB
|
||||
|
||||
type JSONB map[string]interface{}
|
||||
|
||||
func InitDB() error {
|
||||
type DBConfig struct {
|
||||
DB *gorm.DB
|
||||
DSN string
|
||||
}
|
||||
|
||||
func InitDB() (*DBConfig, error) {
|
||||
dsn := fmt.Sprintf("host=%s port=%s user=%s password=%s dbname=%s",
|
||||
os.Getenv("DB_HOST"),
|
||||
os.Getenv("DB_PORT"),
|
||||
@@ -24,7 +29,7 @@ func InitDB() error {
|
||||
|
||||
DB, err = gorm.Open(postgres.Open(dsn), &gorm.Config{})
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to connect to database: %v", err)
|
||||
return nil, fmt.Errorf("failed to connect to database: %v", err)
|
||||
}
|
||||
|
||||
fmt.Println("✅ Connected to database")
|
||||
@@ -32,12 +37,15 @@ func InitDB() error {
|
||||
// ensures we have the uuid stuff setup properly
|
||||
DB.Exec(`CREATE EXTENSION IF NOT EXISTS "uuid-ossp"`)
|
||||
|
||||
err = DB.AutoMigrate(&Log{}, &Config{}, &ClientRecord{})
|
||||
err = DB.AutoMigrate(&Log{}, &Settings{}, &ClientRecord{})
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to auto-migrate models: %v", err)
|
||||
return nil, fmt.Errorf("failed to auto-migrate models: %v", err)
|
||||
}
|
||||
|
||||
fmt.Println("✅ Database migration completed successfully")
|
||||
|
||||
return nil
|
||||
return &DBConfig{
|
||||
DB: DB,
|
||||
DSN: dsn,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -4,12 +4,12 @@ import (
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
gorm.Model
|
||||
ID uint `gorm:"primaryKey;autoIncrement"`
|
||||
type Settings struct {
|
||||
ConfigID uuid.UUID `gorm:"type:uuid;default:uuid_generate_v4();primaryKey" json:"id"`
|
||||
Name string `gorm:"uniqueIndex;not null"`
|
||||
Description string `gorm:"type:text"`
|
||||
Value string `gorm:"not null"`
|
||||
@@ -20,7 +20,7 @@ type Config struct {
|
||||
DeletedAt gorm.DeletedAt `gorm:"index"`
|
||||
}
|
||||
|
||||
var seedConfigData = []Config{
|
||||
var seedConfigData = []Settings{
|
||||
{Name: "serverPort", Description: "The port the server will listen on if not running in docker", Value: "4000", Enabled: true},
|
||||
{Name: "server", Description: "The server we will use when connecting to the alplaprod sql", Value: "usmcd1vms006", Enabled: true},
|
||||
}
|
||||
@@ -28,7 +28,7 @@ var seedConfigData = []Config{
|
||||
func SeedConfigs(db *gorm.DB) error {
|
||||
|
||||
for _, cfg := range seedConfigData {
|
||||
var existing Config
|
||||
var existing Settings
|
||||
// Try to find config by unique name
|
||||
result := db.Where("name =?", cfg.Name).First(&existing)
|
||||
|
||||
@@ -57,11 +57,11 @@ func SeedConfigs(db *gorm.DB) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetAllConfigs(db *gorm.DB) ([]Config, error) {
|
||||
var configs []Config
|
||||
func GetAllConfigs(db *gorm.DB) ([]Settings, error) {
|
||||
var settings []Settings
|
||||
|
||||
result := db.Find(&configs)
|
||||
result := db.Find(&settings)
|
||||
|
||||
return configs, result.Error
|
||||
return settings, result.Error
|
||||
|
||||
}
|
||||
@@ -17,8 +17,9 @@ type CustomLogger struct {
|
||||
}
|
||||
|
||||
type Message struct {
|
||||
Channel string `json:"channel"`
|
||||
Data interface{} `json:"data"`
|
||||
Channel string `json:"channel"`
|
||||
Data map[string]interface{} `json:"data"`
|
||||
Meta map[string]interface{} `json:"meta,omitempty"`
|
||||
}
|
||||
|
||||
// New creates a configured CustomLogger.
|
||||
|
||||
Reference in New Issue
Block a user