first commit
This commit is contained in:
commit
34ea15a54d
246 changed files with 18660 additions and 0 deletions
20
backend/scripts/migrate.py
Normal file
20
backend/scripts/migrate.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
"""Run Alembic migrations (upgrade head)."""
|
||||
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
def main():
|
||||
result = subprocess.run(
|
||||
[sys.executable, "-m", "alembic", "upgrade", "head"],
|
||||
cwd=ROOT,
|
||||
check=False,
|
||||
)
|
||||
raise SystemExit(result.returncode)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
55
backend/scripts/seed.py
Normal file
55
backend/scripts/seed.py
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
"""Initialize admin user and default Bengaluru platform links."""
|
||||
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
|
||||
|
||||
from app.auth import hash_password
|
||||
from app.config import settings
|
||||
from app.database import SessionLocal, engine
|
||||
from app.models import AdminUser, Base, PlatformKind, PlatformLink
|
||||
|
||||
DEFAULT_LINKS = [
|
||||
(PlatformKind.bookmyshow, "BookMyShow", "https://in.bookmyshow.com/explore/home/bengaluru", 0),
|
||||
(PlatformKind.district, "District", "https://www.district.in/events/bengaluru", 1),
|
||||
(PlatformKind.instagram, "Instagram", "https://www.instagram.com/", 2),
|
||||
(PlatformKind.highape, "HighApe", "https://highape.com/bangalore", 3),
|
||||
]
|
||||
|
||||
REMOVED_KINDS = (PlatformKind.youtube, PlatformKind.whatsapp)
|
||||
|
||||
|
||||
def main():
|
||||
Base.metadata.create_all(bind=engine)
|
||||
db = SessionLocal()
|
||||
try:
|
||||
if not db.query(AdminUser).filter(AdminUser.email == settings.admin_email).first():
|
||||
db.add(
|
||||
AdminUser(
|
||||
email=settings.admin_email,
|
||||
hashed_password=hash_password(settings.admin_password),
|
||||
)
|
||||
)
|
||||
print(f"Created admin: {settings.admin_email}")
|
||||
|
||||
if db.query(PlatformLink).count() == 0:
|
||||
for kind, label, url, order in DEFAULT_LINKS:
|
||||
db.add(PlatformLink(kind=kind, label=label, url=url, sort_order=order, is_active=True))
|
||||
print("Seeded default platform links (update URLs in admin)")
|
||||
else:
|
||||
for kind in REMOVED_KINDS:
|
||||
db.query(PlatformLink).filter(PlatformLink.kind == kind).delete()
|
||||
for kind, label, url, order in DEFAULT_LINKS:
|
||||
row = db.query(PlatformLink).filter(PlatformLink.kind == kind).first()
|
||||
if not row:
|
||||
db.add(PlatformLink(kind=kind, label=label, url=url, sort_order=order, is_active=True))
|
||||
print("Synced platform links (removed YouTube/WhatsApp, ensured BMS/District/Insta/HighApe)")
|
||||
|
||||
db.commit()
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
40
backend/scripts/seed_admin.py
Normal file
40
backend/scripts/seed_admin.py
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
"""Ensure default admin user exists (catalog admin dashboard)."""
|
||||
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
|
||||
|
||||
from sqlalchemy import select
|
||||
|
||||
from app.core.config import get_settings
|
||||
from app.core.security import hash_password
|
||||
from app.db.session import SessionLocal
|
||||
from app.models.entities import AdminUser
|
||||
from app.models.enums import AdminRole
|
||||
|
||||
|
||||
def main() -> None:
|
||||
settings = get_settings()
|
||||
db = SessionLocal()
|
||||
try:
|
||||
email = settings.admin_email.strip().lower()
|
||||
existing = db.scalar(select(AdminUser).where(AdminUser.email == email))
|
||||
if not existing:
|
||||
db.add(
|
||||
AdminUser(
|
||||
email=email,
|
||||
hashed_password=hash_password(settings.admin_password),
|
||||
role=AdminRole.super_admin,
|
||||
)
|
||||
)
|
||||
db.commit()
|
||||
print(f"Created admin user: {email}")
|
||||
else:
|
||||
print(f"Admin user already exists: {email}")
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
187
backend/scripts/seed_catalog.py
Normal file
187
backend/scripts/seed_catalog.py
Normal file
|
|
@ -0,0 +1,187 @@
|
|||
"""Seed venues, events, media, and ticket types for Holi, Garba, Dandiya."""
|
||||
|
||||
import sys
|
||||
from datetime import datetime, timezone
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
|
||||
|
||||
from sqlalchemy import select
|
||||
|
||||
from app.db.session import SessionLocal
|
||||
from app.models.catalog import Event, EventMedia, TicketType, Venue
|
||||
from app.models.enums import EventStatus, EventType, TicketTypeStatus
|
||||
|
||||
IMG = lambda photo_id, w=1600: f"https://images.unsplash.com/{photo_id}?auto=format&fit=crop&w={w}&q=80"
|
||||
|
||||
GARBA_IMAGE = IMG("photo-1516450360457-62c5678aefa8")
|
||||
GARBA_IMAGE_ALT = IMG("photo-1578662996442-48f60103fc96")
|
||||
HOLI_IMAGE = IMG("photo-1524492412937-b28074a5d7da")
|
||||
DANDIYA_IMAGE = IMG("photo-1533174072545-7a4b6ad7a6c3")
|
||||
|
||||
VENUES = [
|
||||
{
|
||||
"slug": "palace-grounds",
|
||||
"name": "Palace Grounds",
|
||||
"area": "Vasanth Nagar",
|
||||
"address": "Palace Grounds, Jayamahal, Bengaluru, Karnataka 560006",
|
||||
"map_url": "https://maps.google.com/?q=Palace+Grounds+Bengaluru",
|
||||
"description": "Large open-air lawns suited to daylight Holi editions.",
|
||||
},
|
||||
{
|
||||
"slug": "ktpo-whitefield",
|
||||
"name": "KTPO Convention Centre",
|
||||
"area": "Whitefield",
|
||||
"address": "KTPO, Whitefield Main Rd, Bengaluru, Karnataka 560066",
|
||||
"map_url": "https://maps.google.com/?q=KTPO+Whitefield",
|
||||
"description": "Convention-scale halls and floors for Garba and Dandiya nights.",
|
||||
},
|
||||
{
|
||||
"slug": "hsr-layout-grounds",
|
||||
"name": "HSR Layout Club Grounds",
|
||||
"area": "HSR Layout",
|
||||
"address": "27th Main Rd, HSR Layout, Bengaluru, Karnataka 560102",
|
||||
"map_url": "https://maps.google.com/?q=HSR+Layout+Bengaluru",
|
||||
"description": "Neighbourhood grounds for intimate cultural socials.",
|
||||
},
|
||||
]
|
||||
|
||||
EVENTS = [
|
||||
{
|
||||
"slug": "rang-barse-palace-grounds-2026",
|
||||
"title": "Rang Barse — Palace Grounds",
|
||||
"category": EventType.holi,
|
||||
"venue_slug": "palace-grounds",
|
||||
"starts_at": datetime(2026, 3, 9, 10, 0, tzinfo=timezone.utc),
|
||||
"ends_at": datetime(2026, 3, 9, 18, 0, tzinfo=timezone.utc),
|
||||
"is_featured": True,
|
||||
"cover": HOLI_IMAGE,
|
||||
"cover_alt": "Crowd celebrating Holi with colour in the air",
|
||||
"description": "Daylight Holi with live dhol, curated gulal zones, and family-friendly lawns.",
|
||||
"media": [(HOLI_IMAGE, "Holi colour cloud above dancers", 0)],
|
||||
"tickets": [
|
||||
("General admission", "Full-day access with colour kit", 149900, 5000),
|
||||
("Shade deck", "Reserved seating and meal credit", 299900, 400),
|
||||
],
|
||||
},
|
||||
{
|
||||
"slug": "navratri-nights-ktpo",
|
||||
"title": "Navratri Nights",
|
||||
"category": EventType.garba,
|
||||
"venue_slug": "ktpo-whitefield",
|
||||
"starts_at": datetime(2026, 10, 3, 19, 0, tzinfo=timezone.utc),
|
||||
"ends_at": datetime(2026, 10, 4, 1, 0, tzinfo=timezone.utc),
|
||||
"is_featured": True,
|
||||
"cover": GARBA_IMAGE,
|
||||
"cover_alt": "Women in traditional attire performing garba under evening lights",
|
||||
"description": "Whitefield Garba with live folk vocals, circular floor, and midnight raas.",
|
||||
"media": [
|
||||
(GARBA_IMAGE, "Garba dancers in traditional dress", 0),
|
||||
(GARBA_IMAGE_ALT, "Garba dancers in coordinated circle", 1),
|
||||
],
|
||||
"tickets": [
|
||||
("Dance floor", "Standing access to main circle", 99900, 3000),
|
||||
("Balcony lounge", "Elevated seating", 189900, 250),
|
||||
],
|
||||
},
|
||||
{
|
||||
"slug": "hsr-dandiya-social-2026",
|
||||
"title": "HSR Dandiya Social",
|
||||
"category": EventType.dandiya,
|
||||
"venue_slug": "hsr-layout-grounds",
|
||||
"starts_at": datetime(2026, 10, 11, 20, 0, tzinfo=timezone.utc),
|
||||
"ends_at": datetime(2026, 10, 12, 1, 0, tzinfo=timezone.utc),
|
||||
"is_featured": False,
|
||||
"cover": DANDIYA_IMAGE,
|
||||
"cover_alt": "Evening lanterns at a cultural celebration",
|
||||
"description": "South Bengaluru Dandiya social with resident callers and midnight chai.",
|
||||
"media": [(DANDIYA_IMAGE, "Festival lights over the dance floor", 0)],
|
||||
"tickets": [("Early bird", "Full night access", 79900, 800)],
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
def upsert_venue(db, data: dict) -> Venue:
|
||||
venue = db.scalar(select(Venue).where(Venue.slug == data["slug"]))
|
||||
if venue:
|
||||
for key, value in data.items():
|
||||
setattr(venue, key, value)
|
||||
return venue
|
||||
venue = Venue(**data)
|
||||
db.add(venue)
|
||||
db.flush()
|
||||
return venue
|
||||
|
||||
|
||||
def seed() -> None:
|
||||
db = SessionLocal()
|
||||
try:
|
||||
venues_by_slug = {}
|
||||
for row in VENUES:
|
||||
venues_by_slug[row["slug"]] = upsert_venue(db, row)
|
||||
|
||||
for row in EVENTS:
|
||||
venue = venues_by_slug[row["venue_slug"]]
|
||||
event = db.scalar(select(Event).where(Event.slug == row["slug"]))
|
||||
if not event:
|
||||
event = Event(
|
||||
slug=row["slug"],
|
||||
title=row["title"],
|
||||
category=row["category"],
|
||||
status=EventStatus.published,
|
||||
venue_id=venue.id,
|
||||
description=row["description"],
|
||||
starts_at=row["starts_at"],
|
||||
ends_at=row["ends_at"],
|
||||
is_featured=row["is_featured"],
|
||||
cover_image_url=row["cover"],
|
||||
cover_image_alt=row["cover_alt"],
|
||||
meta_description=row["description"][:300],
|
||||
)
|
||||
db.add(event)
|
||||
db.flush()
|
||||
else:
|
||||
event.title = row["title"]
|
||||
event.category = row["category"]
|
||||
event.status = EventStatus.published
|
||||
event.venue_id = venue.id
|
||||
event.description = row["description"]
|
||||
event.starts_at = row["starts_at"]
|
||||
event.ends_at = row["ends_at"]
|
||||
event.is_featured = row["is_featured"]
|
||||
event.cover_image_url = row["cover"]
|
||||
event.cover_image_alt = row["cover_alt"]
|
||||
|
||||
if not event.media:
|
||||
for url, alt, order in row["media"]:
|
||||
db.add(
|
||||
EventMedia(
|
||||
event_id=event.id,
|
||||
image_url=url,
|
||||
alt_text=alt,
|
||||
sort_order=order,
|
||||
)
|
||||
)
|
||||
|
||||
if not event.ticket_types:
|
||||
for idx, (name, desc, price_paise, qty) in enumerate(row["tickets"]):
|
||||
db.add(
|
||||
TicketType(
|
||||
event_id=event.id,
|
||||
name=name,
|
||||
description=desc,
|
||||
price_paise=price_paise,
|
||||
quantity_total=qty,
|
||||
status=TicketTypeStatus.active,
|
||||
sort_order=idx,
|
||||
)
|
||||
)
|
||||
|
||||
db.commit()
|
||||
print("Seeded catalog: venues, Holi, Garba, Dandiya events.")
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
seed()
|
||||
Loading…
Add table
Add a link
Reference in a new issue