elmeg-demo/backend/seed_ratings.py

64 lines
2 KiB
Python

"""
Seed script to create demo ratings for shows and performances.
Run with: python seed_ratings.py
"""
from sqlmodel import Session, create_engine, select
from database import DATABASE_URL
from models import Rating, Show, Performance, User
import random
def seed_ratings():
engine = create_engine(DATABASE_URL)
with Session(engine) as session:
# Get first user (or admin) to attribute ratings to
user = session.exec(select(User).limit(1)).first()
if not user:
print("No users found. Please create a user first.")
return
# Get some shows
shows = session.exec(select(Show).limit(20)).all()
# Get some performances
performances = session.exec(select(Performance).limit(50)).all()
created_count = 0
# Seed show ratings (7-10 range for positive feel)
for show in shows:
# Check if rating already exists
existing = session.exec(
select(Rating).where(Rating.show_id == show.id, Rating.user_id == user.id)
).first()
if existing:
continue
rating = Rating(
user_id=user.id,
show_id=show.id,
score=random.randint(7, 10)
)
session.add(rating)
created_count += 1
# Seed performance ratings
for perf in performances:
existing = session.exec(
select(Rating).where(Rating.performance_id == perf.id, Rating.user_id == user.id)
).first()
if existing:
continue
rating = Rating(
user_id=user.id,
performance_id=perf.id,
score=random.randint(6, 10)
)
session.add(rating)
created_count += 1
session.commit()
print(f"Created {created_count} demo ratings!")
if __name__ == "__main__":
seed_ratings()