Spaces:
Runtime error
Runtime error
Aryan Jain commited on
Commit ·
387690c
1
Parent(s): 94835dc
add api to delete the data from database
Browse files- src/app.py +7 -0
src/app.py
CHANGED
|
@@ -11,6 +11,7 @@ from fastapi.middleware.cors import CORSMiddleware
|
|
| 11 |
from src.config import DatabaseConfig, logger
|
| 12 |
from src.controllers import api_router
|
| 13 |
|
|
|
|
| 14 |
|
| 15 |
|
| 16 |
def run_upgrade(connection, alembic_config: Config):
|
|
@@ -62,5 +63,11 @@ app.add_middleware(
|
|
| 62 |
async def check_health():
|
| 63 |
return {"response": "Service is healthy!"}
|
| 64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
app.include_router(api_router, prefix="/api/v1")
|
|
|
|
| 11 |
from src.config import DatabaseConfig, logger
|
| 12 |
from src.controllers import api_router
|
| 13 |
|
| 14 |
+
from src.models import Base
|
| 15 |
|
| 16 |
|
| 17 |
def run_upgrade(connection, alembic_config: Config):
|
|
|
|
| 63 |
async def check_health():
|
| 64 |
return {"response": "Service is healthy!"}
|
| 65 |
|
| 66 |
+
@app.delete("/api/v1/databse")
|
| 67 |
+
async def delete_all_data():
|
| 68 |
+
async with DatabaseConfig.get_engine().begin() as session:
|
| 69 |
+
await session.run_sync(Base.metadata.drop_all)
|
| 70 |
+
await session.run_sync(Base.metadata.create_all)
|
| 71 |
+
return {"response": "All data deleted successfully!"}
|
| 72 |
|
| 73 |
app.include_router(api_router, prefix="/api/v1")
|