-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverify_db.py
More file actions
24 lines (20 loc) · 762 Bytes
/
verify_db.py
File metadata and controls
24 lines (20 loc) · 762 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from backend.models import Base, Product, Order
from backend.database import SQLALCHEMY_DATABASE_URL
print(f"Connecting to {SQLALCHEMY_DATABASE_URL}")
try:
engine = create_engine(SQLALCHEMY_DATABASE_URL, connect_args={"check_same_thread": False})
Base.metadata.create_all(bind=engine)
print("Tables created/verified.")
SessionLocal = sessionmaker(bind=engine)
db = SessionLocal()
print("Querying products...")
products = db.query(Product).all()
print(f"Products count: {len(products)}")
db.close()
print("DB Check Success")
except Exception as e:
print(f"DB Check Failed: {e}")
import traceback
traceback.print_exc()