diff --git a/backend/app/config.py b/backend/app/config.py index 7eab778f75..d0c06fbd75 100644 --- a/backend/app/config.py +++ b/backend/app/config.py @@ -9,7 +9,7 @@ class Settings(BaseSettings): # Core settings - database_url: str = "postgresql://postgres:postgres@db:5432/propertyflow" + database_url: str = "postgresql+asyncpg://postgres:postgres@db:5432/propertyflow" redis_url: str = "redis://redis:6379/0" secret_key: str = "debug_challenge_secret" diff --git a/backend/app/core/database_pool.py b/backend/app/core/database_pool.py index d638dfcfe3..5d5ccf4ee3 100644 --- a/backend/app/core/database_pool.py +++ b/backend/app/core/database_pool.py @@ -15,11 +15,11 @@ async def initialize(self): """Initialize database connection pool""" try: # Create async engine with connection pooling - database_url = f"postgresql+asyncpg://{settings.supabase_db_user}:{settings.supabase_db_password}@{settings.supabase_db_host}:{settings.supabase_db_port}/{settings.supabase_db_name}" - + database_url = settings.database_url + self.engine = create_async_engine( database_url, - poolclass=QueuePool, + # poolclass=QueuePool, pool_size=20, # Number of connections to maintain max_overflow=30, # Additional connections when needed pool_pre_ping=True, # Validate connections @@ -56,5 +56,5 @@ async def get_session(self) -> AsyncSession: async def get_db_session() -> AsyncSession: """Dependency to get database session""" - async with db_pool.get_session() as session: + async with (await db_pool.get_session()) as session: yield session diff --git a/backend/app/main.py b/backend/app/main.py index 00734b2fa3..18879c5259 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -92,12 +92,12 @@ async def lifespan(app: FastAPI): # Initialize Supabase connection pool try: - from .core.supabase_connection_pool import supabase_pool + from .core.database_pool import db_pool - await supabase_pool.initialize() - logger.info("✅ Supabase connection pool initialized") + await db_pool.initialize() + logger.info("✅ Database connection pool initialized") except Exception as e: - logger.error(f"❌ Supabase connection pool initialization failed: {e}") + logger.error(f"❌ Database connection pool initialization failed: {e}") # Continue startup - fallback to direct connections # Initialize Redis connection with timeout diff --git a/backend/app/services/cache.py b/backend/app/services/cache.py index b81474957f..8c03feff79 100644 --- a/backend/app/services/cache.py +++ b/backend/app/services/cache.py @@ -10,7 +10,7 @@ async def get_revenue_summary(property_id: str, tenant_id: str) -> Dict[str, Any """ Fetches revenue summary, utilizing caching to improve performance. """ - cache_key = f"revenue:{property_id}" + cache_key = f"revenue:{property_id}:{tenant_id}" # Try to get from cache cached = await redis_client.get(cache_key) diff --git a/backend/app/services/reservations.py b/backend/app/services/reservations.py index 384bd00abe..85745c5d63 100644 --- a/backend/app/services/reservations.py +++ b/backend/app/services/reservations.py @@ -44,7 +44,7 @@ async def calculate_total_revenue(property_id: str, tenant_id: str) -> Dict[str, await db_pool.initialize() if db_pool.session_factory: - async with db_pool.get_session() as session: + async with (await db_pool.get_session()) as session: # Use SQLAlchemy text for raw SQL from sqlalchemy import text diff --git a/backend/requirements.txt b/backend/requirements.txt index 6b777d2aaa..f16fe9e1af 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -9,6 +9,7 @@ lz4 orjson Pillow==10.4.0 psycopg2-binary +psycopg pydantic-settings pydantic[email] pyhumps==3.8.0 @@ -18,7 +19,7 @@ pytz redis>=5.0.0 requests sendgrid -sqlalchemy>=2.0.0 +sqlalchemy[asyncio]>=2.0.0 supabase tenacity>=8.0.0 uvicorn[standard]