Some checks failed
CI/CD - Build & Test / Backend Tests (push) Has been cancelled
CI/CD - Build & Test / Frontend Tests (push) Has been cancelled
CI/CD - Build & Test / Security Scans (push) Has been cancelled
CI/CD - Build & Test / Docker Build Test (push) Has been cancelled
CI/CD - Build & Test / Terraform Validate (push) Has been cancelled
Deploy to Production / Build & Test (push) Has been cancelled
Deploy to Production / Security Scan (push) Has been cancelled
Deploy to Production / Build Docker Images (push) Has been cancelled
Deploy to Production / Deploy to Staging (push) Has been cancelled
Deploy to Production / E2E Tests (push) Has been cancelled
Deploy to Production / Deploy to Production (push) Has been cancelled
E2E Tests / Run E2E Tests (push) Has been cancelled
E2E Tests / Visual Regression Tests (push) Has been cancelled
E2E Tests / Smoke Tests (push) Has been cancelled
Major fixes to database connectivity in Docker: 1. Fix alembic.ini - Changed localhost to postgres (line 90) - This was the root cause of localhost connection errors 2. Fix database.py default - Changed localhost to postgres - Ensures correct default when env var not set 3. Fix config.py default - Changed localhost to postgres - Consistent configuration across all files 4. Fix .env file - Changed DATABASE_URL from localhost to postgres - Prevents local dev config from overriding Docker config 5. Update Dockerfile.backend - Add debug logging to verify env vars 6. Fix docker-compose.yml frontend port - Changed 3000 to 8888 7. Fix Celery commands - Use 'uv run celery' instead of just 'celery' 8. Remove obsolete 'version' attribute from docker-compose.yml Verification: - DATABASE_URL env var: postgresql+asyncpg://postgres:postgres@postgres:5432/mockupaws ✅ - Backend now connects to postgres:5432 instead of localhost ✅ - Frontend accessible at http://localhost:8888 ✅ Note: There's a separate migration error with index creation (idx_logs_recent using NOW() - requires IMMUTABLE function). This is a database migration issue, not a connection issue.
45 lines
1.1 KiB
Python
45 lines
1.1 KiB
Python
"""Database configuration and session management."""
|
|
|
|
import os
|
|
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession, async_sessionmaker
|
|
from sqlalchemy.orm import declarative_base
|
|
|
|
# URL dal environment o default per Docker
|
|
DATABASE_URL = os.getenv(
|
|
"DATABASE_URL", "postgresql+asyncpg://postgres:postgres@postgres:5432/mockupaws"
|
|
)
|
|
|
|
# Debug: stampa la DATABASE_URL all'avvio
|
|
print(f"DEBUG - DATABASE_URL: {DATABASE_URL}", flush=True)
|
|
|
|
# Engine async
|
|
engine = create_async_engine(
|
|
DATABASE_URL,
|
|
echo=False, # Set to True for debug SQL
|
|
future=True,
|
|
pool_size=20,
|
|
max_overflow=0,
|
|
)
|
|
|
|
# Session factory
|
|
AsyncSessionLocal = async_sessionmaker(
|
|
engine,
|
|
class_=AsyncSession,
|
|
expire_on_commit=False,
|
|
autocommit=False,
|
|
autoflush=False,
|
|
)
|
|
|
|
# Base per i modelli
|
|
Base = declarative_base()
|
|
|
|
|
|
# Dependency per FastAPI
|
|
async def get_db() -> AsyncSession:
|
|
"""Dependency that provides a database session."""
|
|
async with AsyncSessionLocal() as session:
|
|
try:
|
|
yield session
|
|
finally:
|
|
await session.close()
|