Skip to content

Commit

Permalink
feat: add local db for debug
Browse files Browse the repository at this point in the history
  • Loading branch information
haxgun authored Nov 28, 2024
1 parent c4a4dd6 commit 1832938
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ DEBUG=True
PROJECT_NAME="My app"
VERSION="1.0.0"

DATABASE_URL="postgresql+asyncpg://postgres:postgres@localhost:5432/valory"
DATABASE_URL="postgresql+asyncpg://postgres:postgres@localhost:5432/valory"
DEGUB_DATABASE_URL="sqlite+aiosqlite:///sqlite.db"
5 changes: 4 additions & 1 deletion backend/app/db/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
from sqlmodel import SQLModel
from app import settings

engine = create_async_engine(settings.DATABASE_URL, echo=True, future=True)
if settings.DEBUG:
engine = create_async_engine(settings.DEGUB_DATABASE_URL, echo=True, future=True)
else:
engine = create_async_engine(settings.DATABASE_URL, echo=True, future=True)

AsyncSessionLocal = sessionmaker(
bind=engine,
Expand Down
3 changes: 2 additions & 1 deletion backend/app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ def str_to_bool(value: str) -> bool:
PROJECT_NAME = environ.get('PROJECT_NAME')
VERSION = environ.get('VERSION')

DATABASE_URL = environ.get('DATABASE_URL')
DATABASE_URL = environ.get('DATABASE_URL')
DEGUB_DATABASE_URL = environ.get('DEGUB_DATABASE_URL')
7 changes: 3 additions & 4 deletions backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ async def lifespan(app: FastAPI):
allow_headers=["*"],
)

app.include_router(api_router, prefix="/api/v1")
app.include_router(api_router, prefix="/api/")

@app.get("/")
async def read_root():
return {"message": "Welcome to the API!"}
if __name__ == "__main__":
uvicorn.run(app="main:app", reload=True)

0 comments on commit 1832938

Please sign in to comment.