Skip to content

Commit de080bb

Browse files
committed
refactor: remove db.py and reorganize database initialization
- Deleted db.py to streamline database management and reduce redundancy. - Updated main.py to directly import init_db from the database module, simplifying the database initialization process. - Introduced auth_router.py to handle authentication routes, enhancing modularity and organization of the codebase. - Ensured dotenv loading is handled in the database module for consistent environment variable access.
1 parent 63447ed commit de080bb

File tree

4 files changed

+7
-214
lines changed

4 files changed

+7
-214
lines changed

src/backend/database/database.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313

1414
from .models import Base, SCHEMA_NAME
1515

16+
from dotenv import load_dotenv
17+
18+
load_dotenv()
19+
1620
# PostgreSQL connection configuration
1721
DB_USER = os.getenv('POSTGRES_USER', 'postgres')
1822
DB_PASSWORD = os.getenv('POSTGRES_PASSWORD', 'postgres')

src/backend/db.py

Lines changed: 0 additions & 208 deletions
This file was deleted.

src/backend/main.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@
1010
from fastapi.staticfiles import StaticFiles
1111
from dotenv import load_dotenv
1212

13-
from db import init_db
14-
from database import init_db as init_database
13+
from database import init_db
1514
from config import STATIC_DIR, ASSETS_DIR
1615
from dependencies import UserSession, optional_auth
17-
from routers.auth import auth_router
16+
from routers.auth_router import auth_router
1817
from routers.user_router import user_router
1918
from routers.workspace_router import workspace_router
2019
from routers.pad_router import pad_router
@@ -83,7 +82,6 @@ async def load_templates():
8382
@asynccontextmanager
8483
async def lifespan(_: FastAPI):
8584
await init_db()
86-
await init_database()
8785
print("Database connection established successfully")
8886

8987
# Load all templates from the templates directory

src/backend/routers/auth.py renamed to src/backend/routers/auth_router.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import secrets
22
import jwt
33
import httpx
4-
from fastapi import APIRouter, Request, HTTPException, Depends
4+
from fastapi import APIRouter, Request, HTTPException
55
from fastapi.responses import RedirectResponse, FileResponse, JSONResponse
66
import os
77

88
from config import get_auth_url, get_token_url, OIDC_CONFIG, set_session, delete_session, STATIC_DIR, get_session
9-
from dependencies import UserSession, require_auth
109
from coder import CoderAPI
1110

1211
auth_router = APIRouter()

0 commit comments

Comments
 (0)