mirror of
https://github.com/Dvorinka/Trackeep.git
synced 2026-06-03 20:12:58 +00:00
feat: migrate to DragonflyDB and clean up environment configuration
- Replace Redis with DragonflyDB for better performance and memory efficiency - Remove redundant environment variables (POSTGRES_*, ENCRYPTION_KEY, OAUTH_SERVICE_URL) - Consolidate database configuration to use single DB_* variables - Use JWT_SECRET for both JWT tokens and encryption - Remove PORT variable redundancy, use BACKEND_PORT consistently - Clean up docker-compose configurations for dev/prod consistency - Add DragonflyDB configuration with optimized memory usage - Remove redis.conf as it's no longer needed - Update health checks to use Redis-compatible CLI for DragonflyDB - Add missing VITE_API_URL to production frontend - Fix GitHub Actions to use correct go.sum path - Clean up development directories and unused files
This commit is contained in:
+27
-10
@@ -2,12 +2,12 @@ package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/trackeep/backend/migrations"
|
||||
"go.uber.org/zap"
|
||||
"gorm.io/driver/postgres"
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/logger"
|
||||
)
|
||||
|
||||
var DB *gorm.DB
|
||||
@@ -26,12 +26,20 @@ func getJWTSecret() string {
|
||||
|
||||
// InitDatabase initializes the database connection
|
||||
func InitDatabase() {
|
||||
// Initialize logger first
|
||||
InitLogger()
|
||||
logger := GetLogger()
|
||||
|
||||
// Check if demo mode is enabled
|
||||
if os.Getenv("VITE_DEMO_MODE") == "true" {
|
||||
logger.Info("Demo mode enabled - skipping database initialization")
|
||||
return
|
||||
}
|
||||
|
||||
var err error
|
||||
|
||||
// Configure GORM logger
|
||||
gormConfig := &gorm.Config{
|
||||
Logger: logger.Default.LogMode(logger.Info),
|
||||
}
|
||||
// Configure GORM
|
||||
gormConfig := &gorm.Config{}
|
||||
|
||||
dbType := os.Getenv("DB_TYPE")
|
||||
if dbType == "" {
|
||||
@@ -49,19 +57,28 @@ func InitDatabase() {
|
||||
os.Getenv("DB_SSL_MODE"),
|
||||
)
|
||||
DB, err = gorm.Open(postgres.Open(dsn), gormConfig)
|
||||
log.Println("Using PostgreSQL database")
|
||||
logger.Info("Using PostgreSQL database")
|
||||
default:
|
||||
log.Fatal("Unsupported database type: " + dbType)
|
||||
logger.Fatal("Unsupported database type", zap.String("type", dbType))
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
log.Fatal("Failed to connect to database:", err)
|
||||
logger.Fatal("Failed to connect to database", zap.Error(err))
|
||||
}
|
||||
|
||||
log.Println("Database connected successfully")
|
||||
logger.Info("Database connected successfully")
|
||||
|
||||
// Run database migrations
|
||||
if err := migrations.RunMigrations(); err != nil {
|
||||
logger.Fatal("Failed to run database migrations", zap.Error(err))
|
||||
}
|
||||
}
|
||||
|
||||
// GetDB returns the database instance
|
||||
func GetDB() *gorm.DB {
|
||||
// In demo mode, return nil since no database is available
|
||||
if os.Getenv("VITE_DEMO_MODE") == "true" {
|
||||
return nil
|
||||
}
|
||||
return DB
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user