diff --git a/internal/storage/storage_service.go b/internal/storage/storage_service.go index 19b9f44..5fb73ce 100644 --- a/internal/storage/storage_service.go +++ b/internal/storage/storage_service.go @@ -36,7 +36,23 @@ type MenuStorageService struct { userDataStore db.Db } -func NewMenuStorageService(conn ConnData, resourceDir string) *MenuStorageService { +func BuildConnStr() string { + host := initializers.GetEnv("DB_HOST", "localhost") + user := initializers.GetEnv("DB_USER", "postgres") + password := initializers.GetEnv("DB_PASSWORD", "") + dbName := initializers.GetEnv("DB_NAME", "") + port := initializers.GetEnv("DB_PORT", "5432") + + connString := fmt.Sprintf( + "postgres://%s:%s@%s:%s/%s", + user, password, host, port, dbName, + ) + logg.Debugf("pg conn string", "conn", connString) + + return connString +} + +func NewMenuStorageService(dbDir string, resourceDir string) *MenuStorageService { return &MenuStorageService{ conn: conn, resourceDir: resourceDir, @@ -58,7 +74,7 @@ func (ms *MenuStorageService) getOrCreateDb(ctx context.Context, existingDb db.D if database == "postgres" { - connStr := buildConnStr() + connStr := BuildConnStr() // Ensure the schema exists err = ensureSchemaExists(ctx, connStr, schema)