diff --git a/Dockerfile.backend b/Dockerfile.backend index 823fbdc..f04d8b7 100644 --- a/Dockerfile.backend +++ b/Dockerfile.backend @@ -26,4 +26,4 @@ COPY alembic/ ./alembic/ COPY alembic.ini ./ # Run migrations and start application -CMD ["sh", "-c", "uv run alembic upgrade head && uv run uvicorn src.main:app --host 0.0.0.0 --port 8000"] +CMD ["sh", "-c", "echo 'DATABASE_URL from env: '$DATABASE_URL && uv run alembic upgrade head && uv run uvicorn src.main:app --host 0.0.0.0 --port 8000"] diff --git a/alembic.ini b/alembic.ini index 573f79f..a158b62 100644 --- a/alembic.ini +++ b/alembic.ini @@ -87,7 +87,7 @@ path_separator = os # other means of configuring database URLs may be customized within the env.py # file. # Format: postgresql+asyncpg://user:password@host:port/dbname -sqlalchemy.url = postgresql+asyncpg://postgres:postgres@localhost:5432/mockupaws +sqlalchemy.url = postgresql+asyncpg://postgres:postgres@postgres:5432/mockupaws [post_write_hooks] diff --git a/src/core/config.py b/src/core/config.py index 8dfaf2f..02fe9c6 100644 --- a/src/core/config.py +++ b/src/core/config.py @@ -15,8 +15,8 @@ class Settings(BaseSettings): log_level: str = "INFO" json_logging: bool = True - # Database - database_url: str = "postgresql+asyncpg://app:changeme@localhost:5432/mockupaws" + # Database - default uses 'postgres' hostname for Docker, fallback to localhost for local dev + database_url: str = "postgresql+asyncpg://postgres:postgres@postgres:5432/mockupaws" # Redis redis_url: str = "redis://localhost:6379/0" diff --git a/src/core/database.py b/src/core/database.py index 371c5ec..96d4601 100644 --- a/src/core/database.py +++ b/src/core/database.py @@ -4,11 +4,14 @@ 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 dev +# URL dal environment o default per Docker DATABASE_URL = os.getenv( - "DATABASE_URL", "postgresql+asyncpg://postgres:postgres@localhost:5432/mockupaws" + "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,