elmeg-demo/backend/migrations/add_rating_venue_tour.py
fullsizemalt ee311c0bc4 feat: Complete venues overhaul
- Fix ratings API to support venue_id and tour_id
- Add migration for new rating columns
- Venues list: search, state filter, sort by name/shows
- Venues detail: show list with dates, venue stats, error handling
- Remove broken EntityRating/SocialWrapper from venue pages
2025-12-21 17:51:05 -08:00

43 lines
1.2 KiB
Python

"""Add venue_id and tour_id columns to rating table"""
import os
import sys
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from database import DATABASE_URL
import psycopg2
def run():
conn = psycopg2.connect(DATABASE_URL)
cur = conn.cursor()
# Add venue_id column
try:
cur.execute("ALTER TABLE rating ADD COLUMN venue_id INTEGER REFERENCES venue(id)")
print("✅ Added venue_id to rating")
except Exception as e:
if "already exists" in str(e):
print("⚠️ venue_id column already exists")
else:
print(f"❌ Error adding venue_id: {e}")
conn.rollback()
else:
conn.commit()
# Add tour_id column
try:
cur.execute("ALTER TABLE rating ADD COLUMN tour_id INTEGER REFERENCES tour(id)")
print("✅ Added tour_id to rating")
except Exception as e:
if "already exists" in str(e):
print("⚠️ tour_id column already exists")
else:
print(f"❌ Error adding tour_id: {e}")
conn.rollback()
else:
conn.commit()
cur.close()
conn.close()
if __name__ == "__main__":
run()