Skip to content

Commit

Permalink
馃敡 Reuse database url from config in alembic setup
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick91 committed Jun 14, 2024
1 parent df66c1d commit 8fccc07
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
8 changes: 2 additions & 6 deletions backend/app/alembic/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
# target_metadata = None

from app.models import SQLModel # noqa
from app.core.config import settings # noqa

target_metadata = SQLModel.metadata

Expand All @@ -29,12 +30,7 @@


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


def run_migrations_offline():
Expand Down
2 changes: 1 addition & 1 deletion backend/app/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def server_host(self) -> str:
POSTGRES_SERVER: str
POSTGRES_PORT: int = 5432
POSTGRES_USER: str
POSTGRES_PASSWORD: str
POSTGRES_PASSWORD: str = ""
POSTGRES_DB: str = ""

@computed_field # type: ignore[misc]
Expand Down

0 comments on commit 8fccc07

Please sign in to comment.