File size: 1,475 Bytes
c9f1a26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45

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())