Skip to content

Commit 67f43d9

Browse files
authored
Removes direct env access from env.py and keeps runtime DB selection logic intact. (#70)
Co-authored-by: RAMAMUTHUKUMARAN <130954718+RAMAMUTHUKUMARAN@users.noreply.github.com>
1 parent 82c60cd commit 67f43d9

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

migrations/env.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
from logging.config import fileConfig
2-
import os
3-
42
from sqlalchemy import engine_from_config, create_engine
53
from sqlalchemy import pool
6-
4+
from src.config import settings
75
from alembic import context
86

97
# this is the Alembic Config object, which provides
@@ -22,9 +20,9 @@
2220

2321
# map Alembic environment names to DB URLs
2422
DB_URLS = {
25-
"development": os.getenv("DEV_DATABASE_URL"),
26-
"production": os.getenv("PROD_DATABASE_URL"),
27-
"custom": os.getenv("CUSTOM_DATABASE_URL"),
23+
"development": settings.dev_database_url,
24+
"production": settings.prod_database_url,
25+
"custom": settings.custom_database_url,
2826
}
2927

3028
def get_url() -> str:
@@ -39,9 +37,8 @@ def get_url() -> str:
3937
# can be acquired:
4038
# my_important_option = config.get_main_option("my_important_option")
4139
# ... etc.
42-
from os import environ as env
4340
def env_url():
44-
return env.get("CTI_POSTGRES_URL")
41+
return settings.cti_postgres_url
4542

4643
def run_migrations_offline() -> None:
4744
"""Run migrations in 'offline' mode.

src/config.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ class Settings(BaseSettings):
2020
cti_mongo_url: Optional[str] = Field(validation_alias="CTI_MONGO_URL", default=None)
2121
cti_postgres_url: Optional[str] = Field(validation_alias="CTI_POSTGRES_URL", default=None)
2222

23+
# Alembic / Migration Database URLs
24+
dev_database_url: Optional[str] = Field(validation_alias="DEV_DATABASE_URL", default=None)
25+
prod_database_url: Optional[str] = Field(validation_alias="PROD_DATABASE_URL", default=None)
26+
custom_database_url: Optional[str] = Field(validation_alias="CUSTOM_DATABASE_URL", default=None)
27+
2328
# Canvas Variables, only required for Canvas specific-operations
2429
# NOTE: SIS ID's are needed for SIS operations, must be manually defined ahead of time
2530
# TODO: Rename CTI_ACCESS_TOKEN to CTI_CANVAS_TOKEN, improve clarity on token purpose and differentiate from server token

0 commit comments

Comments
 (0)