Skip to content

Commit 426584f

Browse files
committed
feat: change config
1 parent b045e55 commit 426584f

File tree

5 files changed

+9
-33
lines changed

5 files changed

+9
-33
lines changed

backend/qllm/alembic/env.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
# my_important_option = config.get_main_option("my_important_option")
2525
# ... etc.
2626
db_url = config.get_main_option("sqlalchemy.url")
27-
# if settings.SQLALCHEMY_DATABASE_URI is not None:
28-
# db_url = str(settings.SQLALCHEMY_DATABASE_URI)
27+
# if settings.DATABASE_URI is not None:
28+
# db_url = str(settings.DATABASE_URI)
2929
# print(f"Using DATABASE_URL {db_url} from environment for migrations")
3030
# config.set_main_option("sqlalchemy.url", db_url)
3131

backend/qllm/core/config.py

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@ class ApplicationSetting(BaseSettings):
4444
BeforeValidator(parse_cors),
4545
]
4646
] = None
47+
DATABASE_URL: str
4748
STORAGE_DIR: str = "storage"
4849

49-
FRONTEND_HOST: str = "http://localhost:3000"
50+
FRONTEND_HOST: str
5051
ENVIRONMENT: Literal["local", "staging", "production"] = "local"
5152
LOG_LEVEL: Literal["DEBUG", "INFO", "ERROR", "WARNING"] = "DEBUG"
5253
SENTRY_DSN: Optional[HttpUrl] = None
@@ -89,20 +90,6 @@ class Config:
8990
env_file = ".env"
9091
env_file_encoding = "utf-8"
9192

92-
@property
93-
def SQLALCHEMY_DATABASE_URI(self) -> PostgresDsn:
94-
"""
95-
Builds the SQLAlchemy-compatible database URI.
96-
"""
97-
return MultiHostUrl.build(
98-
scheme="postgresql+asyncpg",
99-
username=self.POSTGRES_USER,
100-
password=self.POSTGRES_PASSWORD,
101-
host=self.POSTGRES_SERVER,
102-
port=self.POSTGRES_PORT,
103-
path=self.POSTGRES_DB,
104-
)
105-
10693

10794
# Initialize settings
10895
settings = ApplicationSetting()

backend/qllm/core/database.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from qllm.core.config import settings
44

5-
DATABASE_URL = settings.SQLALCHEMY_DATABASE_URI
5+
DATABASE_URL = settings.DATABASE_URI
66

77
engine = create_async_engine(str(DATABASE_URL))
88
async_session_maker = async_sessionmaker(engine, expire_on_commit=False)

backend/qllm/main.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ async def lifespan(app: FastAPI):
5454
current_path = Path(__file__).parent
5555
cfg = Config(os.path.join(current_path, "alembic.ini"))
5656
# Change DB URL to use psycopg2 driver for this specific check
57-
db_url = str(settings.SQLALCHEMY_DATABASE_URI).replace(
57+
db_url = str(settings.DATABASE_URI).replace(
5858
"postgresql+asyncpg://", "postgresql+psycopg2://"
5959
)
6060
script_location = cfg.get_main_option("script_location", "alembic")
@@ -96,13 +96,7 @@ async def lifespan(app: FastAPI):
9696
logger.info("CORS enabled for %s", settings.BACKEND_CORS_ORIGINS)
9797
# origins = settings.BACKEND_CORS_ORIGINS.copy()
9898
origins = str(settings.BACKEND_CORS_ORIGINS)
99-
if (
100-
settings.CODESPACES
101-
and settings.CODESPACE_NAME
102-
and settings.ENVIRONMENT == AppEnvironment.LOCAL
103-
):
104-
# add codespace origin if running in Github codespace
105-
origins.append(f"https://{settings.CODESPACE_NAME}-3000.app.github.dev")
99+
origins.append(settings.FRONTEND_HOST)
106100
# allow all origins
107101
app.add_middleware(
108102
CORSMiddleware,
@@ -119,8 +113,8 @@ async def lifespan(app: FastAPI):
119113
"http://127.0.0.1",
120114
"http://127.0.0.1:8000",
121115
"http://0.0.0.0",
122-
"http://localhost:5173",
123116
]
117+
origins.append(settings.FRONTEND_HOST)
124118

125119
app.add_middleware(
126120
CORSMiddleware,
@@ -132,11 +126,6 @@ async def lifespan(app: FastAPI):
132126

133127
app.include_router(api_router, prefix=settings.API_PREFIX)
134128

135-
# Mount the data files to serve the file viewer
136-
# mount_static_files("data", "/api/files/data")
137-
# Mount the output files from tools
138-
# mount_static_files("output", "/api/files/output")
139-
140129

141130
def start():
142131
"""Launched with `poetry run start` at root level"""

backend/qllm/services/db/session.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from qllm.core.config import settings
44

55
# Database connection settings
6-
DATABASE_URL = settings.SQLALCHEMY_DATABASE_URI
6+
DATABASE_URL = settings.DATABASE_URI
77

88

99
# Create the SQLAlchemy engine

0 commit comments

Comments
 (0)