Skip to content

Commit

Permalink
feat: change config
Browse files Browse the repository at this point in the history
  • Loading branch information
LongBaoCoder2 committed Feb 19, 2025
1 parent b045e55 commit 426584f
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 33 deletions.
4 changes: 2 additions & 2 deletions backend/qllm/alembic/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
# my_important_option = config.get_main_option("my_important_option")
# ... etc.
db_url = config.get_main_option("sqlalchemy.url")
# if settings.SQLALCHEMY_DATABASE_URI is not None:
# db_url = str(settings.SQLALCHEMY_DATABASE_URI)
# if settings.DATABASE_URI is not None:
# db_url = str(settings.DATABASE_URI)
# print(f"Using DATABASE_URL {db_url} from environment for migrations")
# config.set_main_option("sqlalchemy.url", db_url)

Expand Down
17 changes: 2 additions & 15 deletions backend/qllm/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ class ApplicationSetting(BaseSettings):
BeforeValidator(parse_cors),
]
] = None
DATABASE_URL: str
STORAGE_DIR: str = "storage"

FRONTEND_HOST: str = "http://localhost:3000"
FRONTEND_HOST: str
ENVIRONMENT: Literal["local", "staging", "production"] = "local"
LOG_LEVEL: Literal["DEBUG", "INFO", "ERROR", "WARNING"] = "DEBUG"
SENTRY_DSN: Optional[HttpUrl] = None
Expand Down Expand Up @@ -89,20 +90,6 @@ class Config:
env_file = ".env"
env_file_encoding = "utf-8"

@property
def SQLALCHEMY_DATABASE_URI(self) -> PostgresDsn:
"""
Builds the SQLAlchemy-compatible database URI.
"""
return MultiHostUrl.build(
scheme="postgresql+asyncpg",
username=self.POSTGRES_USER,
password=self.POSTGRES_PASSWORD,
host=self.POSTGRES_SERVER,
port=self.POSTGRES_PORT,
path=self.POSTGRES_DB,
)


# Initialize settings
settings = ApplicationSetting()
2 changes: 1 addition & 1 deletion backend/qllm/core/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from qllm.core.config import settings

DATABASE_URL = settings.SQLALCHEMY_DATABASE_URI
DATABASE_URL = settings.DATABASE_URI

engine = create_async_engine(str(DATABASE_URL))
async_session_maker = async_sessionmaker(engine, expire_on_commit=False)
17 changes: 3 additions & 14 deletions backend/qllm/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async def lifespan(app: FastAPI):
current_path = Path(__file__).parent
cfg = Config(os.path.join(current_path, "alembic.ini"))
# Change DB URL to use psycopg2 driver for this specific check
db_url = str(settings.SQLALCHEMY_DATABASE_URI).replace(
db_url = str(settings.DATABASE_URI).replace(
"postgresql+asyncpg://", "postgresql+psycopg2://"
)
script_location = cfg.get_main_option("script_location", "alembic")
Expand Down Expand Up @@ -96,13 +96,7 @@ async def lifespan(app: FastAPI):
logger.info("CORS enabled for %s", settings.BACKEND_CORS_ORIGINS)
# origins = settings.BACKEND_CORS_ORIGINS.copy()
origins = str(settings.BACKEND_CORS_ORIGINS)
if (
settings.CODESPACES
and settings.CODESPACE_NAME
and settings.ENVIRONMENT == AppEnvironment.LOCAL
):
# add codespace origin if running in Github codespace
origins.append(f"https://{settings.CODESPACE_NAME}-3000.app.github.dev")
origins.append(settings.FRONTEND_HOST)
# allow all origins
app.add_middleware(
CORSMiddleware,
Expand All @@ -119,8 +113,8 @@ async def lifespan(app: FastAPI):
"http://127.0.0.1",
"http://127.0.0.1:8000",
"http://0.0.0.0",
"http://localhost:5173",
]
origins.append(settings.FRONTEND_HOST)

app.add_middleware(
CORSMiddleware,
Expand All @@ -132,11 +126,6 @@ async def lifespan(app: FastAPI):

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

# Mount the data files to serve the file viewer
# mount_static_files("data", "/api/files/data")
# Mount the output files from tools
# mount_static_files("output", "/api/files/output")


def start():
"""Launched with `poetry run start` at root level"""
Expand Down
2 changes: 1 addition & 1 deletion backend/qllm/services/db/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from qllm.core.config import settings

# Database connection settings
DATABASE_URL = settings.SQLALCHEMY_DATABASE_URI
DATABASE_URL = settings.DATABASE_URI


# Create the SQLAlchemy engine
Expand Down

0 comments on commit 426584f

Please sign in to comment.