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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user