Skip to content

Commit b5b2929

Browse files
authored
🔧 Reuse database url from config in alembic setup (#1229)
1 parent b15d482 commit b5b2929

2 files changed

Lines changed: 3 additions & 7 deletions

File tree

backend/app/alembic/env.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
# target_metadata = None
2020

2121
from app.models import SQLModel # noqa
22+
from app.core.config import settings # noqa
2223

2324
target_metadata = SQLModel.metadata
2425

@@ -29,12 +30,7 @@
2930

3031

3132
def get_url():
32-
user = os.getenv("POSTGRES_USER", "postgres")
33-
password = os.getenv("POSTGRES_PASSWORD", "")
34-
server = os.getenv("POSTGRES_SERVER", "db")
35-
port = os.getenv("POSTGRES_PORT", "5432")
36-
db = os.getenv("POSTGRES_DB", "app")
37-
return f"postgresql+psycopg://{user}:{password}@{server}:{port}/{db}"
33+
return str(settings.SQLALCHEMY_DATABASE_URI)
3834

3935

4036
def run_migrations_offline():

backend/app/core/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def server_host(self) -> str:
5151
POSTGRES_SERVER: str
5252
POSTGRES_PORT: int = 5432
5353
POSTGRES_USER: str
54-
POSTGRES_PASSWORD: str
54+
POSTGRES_PASSWORD: str = ""
5555
POSTGRES_DB: str = ""
5656

5757
@computed_field # type: ignore[misc]

0 commit comments

Comments
 (0)