Spaces:
Sleeping
Sleeping
Download backend/scripts/reset_db.py from orakzai-io/Rednote: direct link, hf CLI and curl.
- Browser
- Download file 857 Bytes
-
https://huggingface.co/spaces/orakzai-io/Rednote/resolve/main/backend/scripts/reset_db.py
- Command line
-
hf download hf://spaces/orakzai-io/Rednote/backend/scripts/reset_db.py
-
curl -L -o reset_db.py https://huggingface.co/spaces/orakzai-io/Rednote/resolve/main/backend/scripts/reset_db.py
857 Bytes
| import asyncio | |
| import logging | |
| import sys | |
| # Add backend to path if needed | |
| import os | |
| sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | |
| from db.session import engine | |
| from db.init import init_database | |
| from models.db import Base | |
| logging.basicConfig(level=logging.INFO) | |
| logger = logging.getLogger(__name__) | |
| async def reset_database() -> None: | |
| logger.info("Dropping all existing database tables...") | |
| async with engine.begin() as conn: | |
| # Disable foreign key checks or cascade drops if needed, drop_all handles order/cascade automatically | |
| await conn.run_sync(Base.metadata.drop_all) | |
| logger.info("Tables dropped successfully. Re-initializing database...") | |
| await init_database() | |
| logger.info("Database reset and schema creation complete!") | |
| if __name__ == "__main__": | |
| asyncio.run(reset_database()) | |