[V0.2] WORKING Working calendar and AI with full frontend.
This commit is contained in:
@@ -14,18 +14,24 @@ def read_admin():
|
||||
return {"message": "Admin route"}
|
||||
|
||||
@router.get("/cleardb")
|
||||
def clear_db(db: Annotated[Session, Depends(get_db)]):
|
||||
def clear_db(db: Annotated[Session, Depends(get_db)], hard: bool):
|
||||
"""
|
||||
Clear the database.
|
||||
'hard' parameter determines if the database should be completely reset.
|
||||
"""
|
||||
tables = Base.metadata.tables.keys()
|
||||
for table in tables:
|
||||
# delete all tables that isn't the users table
|
||||
if table != "users":
|
||||
table = Base.metadata.tables[table]
|
||||
db.execute(table.delete())
|
||||
|
||||
if hard:
|
||||
Base.metadata.drop_all(bind=db.get_bind())
|
||||
Base.metadata.create_all(bind=db.get_bind())
|
||||
return {"message": "Database reset (HARD)"}
|
||||
else:
|
||||
tables = Base.metadata.tables.keys()
|
||||
for table_name in tables:
|
||||
# delete all tables that isn't the users table
|
||||
if table_name != "users":
|
||||
table = Base.metadata.tables[table_name]
|
||||
db.execute(table.delete())
|
||||
|
||||
# delete all non-admin accounts
|
||||
db.query(User).filter(User.role != UserRole.ADMIN).delete()
|
||||
db.commit()
|
||||
return {"message": "Database cleared"}
|
||||
db.query(User).filter(User.role != UserRole.ADMIN).delete()
|
||||
db.commit()
|
||||
return {"message": "Database cleared"}
|
||||
Reference in New Issue
Block a user