Spaces:
Sleeping
Sleeping
Update rag_routerv2.py
Browse files- rag_routerv2.py +34 -0
rag_routerv2.py
CHANGED
@@ -193,6 +193,40 @@ async def get_tables(user_id: str):
|
|
193 |
|
194 |
return result
|
195 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
196 |
@router.get("/health")
|
197 |
async def health_check():
|
198 |
return {"status": "healthy"}
|
|
|
193 |
|
194 |
return result
|
195 |
|
196 |
+
|
197 |
+
@router.delete("/delete_table/{table_id}")
|
198 |
+
async def delete_table(table_id: str, user_id: str):
|
199 |
+
try:
|
200 |
+
db = get_db()
|
201 |
+
|
202 |
+
# Verify user owns the table
|
203 |
+
table = db.execute(
|
204 |
+
'SELECT * FROM tables WHERE table_id = ? AND user_id = ?',
|
205 |
+
(table_id, user_id)
|
206 |
+
).fetchone()
|
207 |
+
|
208 |
+
if not table:
|
209 |
+
raise HTTPException(status_code=404, detail="Table not found or unauthorized")
|
210 |
+
|
211 |
+
# Delete files from filesystem
|
212 |
+
table_path = f"./data/{table_id}"
|
213 |
+
index_path = f"./lancedb/index/{table_id}"
|
214 |
+
if os.path.exists(table_path):
|
215 |
+
shutil.rmtree(table_path)
|
216 |
+
if os.path.exists(index_path):
|
217 |
+
shutil.rmtree(index_path)
|
218 |
+
|
219 |
+
# Delete from database
|
220 |
+
db.execute('DELETE FROM table_files WHERE table_id = ?', (table_id,))
|
221 |
+
db.execute('DELETE FROM tables WHERE table_id = ?', (table_id,))
|
222 |
+
db.commit()
|
223 |
+
|
224 |
+
return {"message": "Table deleted successfully"}
|
225 |
+
|
226 |
+
except Exception as e:
|
227 |
+
raise HTTPException(status_code=500, detail=str(e))
|
228 |
+
|
229 |
+
|
230 |
@router.get("/health")
|
231 |
async def health_check():
|
232 |
return {"status": "healthy"}
|