Spaces:
Runtime error
Runtime error
| import asyncio | |
| import aiosqlite | |
| from config import DATABASE_PATH | |
| import sys | |
| # Windows console encoding fix | |
| sys.stdout.reconfigure(encoding='utf-8') | |
| async def verify(): | |
| if not DATABASE_PATH: | |
| print("Error: DATABASE_PATH not set") | |
| return | |
| try: | |
| async with aiosqlite.connect(DATABASE_PATH) as db: | |
| print(f"Connected to {DATABASE_PATH}") | |
| tables = ["categories", "products", "cart_items", "orders", "order_items"] | |
| all_exist = True | |
| for table in tables: | |
| cursor = await db.execute(f"SELECT name FROM sqlite_master WHERE type='table' AND name='{table}';") | |
| result = await cursor.fetchone() | |
| if result: | |
| print(f"[OK] Table '{table}' exists.") | |
| else: | |
| print(f"[MISSING] Table '{table}' NOT FOUND!") | |
| all_exist = False | |
| # Check if default categories were inserted | |
| cursor = await db.execute("SELECT COUNT(*) FROM categories") | |
| count = await cursor.fetchone() | |
| print(f"[INFO] Categories count: {count[0]}") | |
| if all_exist and count[0] > 0: | |
| print("SUCCESS: Database verification passed.") | |
| else: | |
| print("FAILURE: Database verification failed.") | |
| except Exception as e: | |
| print(f"ERROR: {e}") | |
| if __name__ == "__main__": | |
| asyncio.run(verify()) | |