Compare commits
2 commits
5ced96f4e6
...
19c5e97e7f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
19c5e97e7f | ||
|
|
704a8d9a0b |
3 changed files with 166 additions and 3 deletions
|
|
@ -54,6 +54,23 @@ class EntityTag(SQLModel, table=True):
|
|||
|
||||
# --- Core Entities ---
|
||||
|
||||
class VerticalScene(SQLModel, table=True):
|
||||
"""Join table linking verticals to scenes (many-to-many)"""
|
||||
vertical_id: int = Field(foreign_key="vertical.id", primary_key=True)
|
||||
scene_id: int = Field(foreign_key="scene.id", primary_key=True)
|
||||
|
||||
|
||||
class Scene(SQLModel, table=True):
|
||||
"""Genre/scene categorization for bands (e.g., 'Jam', 'Bluegrass', 'Dead Family')"""
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
name: str = Field(unique=True, index=True)
|
||||
slug: str = Field(unique=True, index=True)
|
||||
description: Optional[str] = Field(default=None)
|
||||
|
||||
# Relationships
|
||||
verticals: List["Vertical"] = Relationship(back_populates="scenes", link_model=VerticalScene)
|
||||
|
||||
|
||||
class Vertical(SQLModel, table=True):
|
||||
"""Represents a Fandom Vertical (e.g., 'Phish', 'Goose', 'Star Wars')"""
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
|
|
@ -64,8 +81,17 @@ class Vertical(SQLModel, table=True):
|
|||
# Link to primary artist/band for this vertical
|
||||
primary_artist_id: Optional[int] = Field(default=None, foreign_key="artist.id")
|
||||
|
||||
# Setlist.fm integration for universal import
|
||||
setlistfm_mbid: Optional[str] = Field(default=None, description="MusicBrainz ID for Setlist.fm")
|
||||
|
||||
# Admin/status fields
|
||||
is_active: bool = Field(default=True, description="Show in band selector")
|
||||
is_featured: bool = Field(default=False, description="Highlight in discovery")
|
||||
|
||||
# Relationships
|
||||
shows: List["Show"] = Relationship(back_populates="vertical")
|
||||
songs: List["Song"] = Relationship(back_populates="vertical")
|
||||
scenes: List["Scene"] = Relationship(back_populates="verticals", link_model=VerticalScene)
|
||||
|
||||
class Venue(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
|
|
|
|||
|
|
@ -47,12 +47,51 @@ class BulkVerticalPreferencesCreate(BaseModel):
|
|||
# --- Public endpoints ---
|
||||
|
||||
@router.get("/", response_model=List[VerticalRead])
|
||||
def list_verticals(session: Session = Depends(get_session)):
|
||||
"""List all available verticals (bands)"""
|
||||
verticals = session.exec(select(Vertical)).all()
|
||||
def list_verticals(
|
||||
scene: str | None = None,
|
||||
session: Session = Depends(get_session)
|
||||
):
|
||||
"""List all available verticals (bands), optionally filtered by scene"""
|
||||
from models import Scene, VerticalScene
|
||||
|
||||
if scene:
|
||||
# Filter by scene
|
||||
scene_obj = session.exec(select(Scene).where(Scene.slug == scene)).first()
|
||||
if not scene_obj:
|
||||
raise HTTPException(status_code=404, detail="Scene not found")
|
||||
|
||||
vertical_ids = session.exec(
|
||||
select(VerticalScene.vertical_id).where(VerticalScene.scene_id == scene_obj.id)
|
||||
).all()
|
||||
|
||||
verticals = session.exec(
|
||||
select(Vertical)
|
||||
.where(Vertical.id.in_(vertical_ids))
|
||||
.where(Vertical.is_active == True)
|
||||
).all()
|
||||
else:
|
||||
verticals = session.exec(
|
||||
select(Vertical).where(Vertical.is_active == True)
|
||||
).all()
|
||||
|
||||
return verticals
|
||||
|
||||
|
||||
class SceneRead(BaseModel):
|
||||
id: int
|
||||
name: str
|
||||
slug: str
|
||||
description: str | None = None
|
||||
|
||||
|
||||
@router.get("/scenes", response_model=List[SceneRead])
|
||||
def list_scenes(session: Session = Depends(get_session)):
|
||||
"""List all scenes (genres)"""
|
||||
from models import Scene
|
||||
scenes = session.exec(select(Scene)).all()
|
||||
return scenes
|
||||
|
||||
|
||||
@router.get("/{slug}", response_model=VerticalRead)
|
||||
def get_vertical(slug: str, session: Session = Depends(get_session)):
|
||||
"""Get a specific vertical by slug"""
|
||||
|
|
|
|||
98
backend/seed_scenes.py
Normal file
98
backend/seed_scenes.py
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
"""Seed script to create initial scenes and assign bands to them"""
|
||||
|
||||
from sqlmodel import Session, select
|
||||
from database import engine
|
||||
from models import Scene, Vertical, VerticalScene
|
||||
|
||||
|
||||
# Scene definitions
|
||||
SCENES = [
|
||||
{"name": "Jam", "slug": "jam", "description": "Improvisational rock bands with extended jams"},
|
||||
{"name": "Bluegrass", "slug": "bluegrass", "description": "Progressive and traditional bluegrass"},
|
||||
{"name": "Dead Family", "slug": "dead-family", "description": "Grateful Dead and related projects"},
|
||||
{"name": "Funk", "slug": "funk", "description": "Funk, soul, and groove-oriented bands"},
|
||||
]
|
||||
|
||||
# Band -> Scene assignments
|
||||
BAND_SCENES = {
|
||||
"goose": ["jam"],
|
||||
"phish": ["jam"],
|
||||
"grateful-dead": ["jam", "dead-family"],
|
||||
"dead-and-company": ["jam", "dead-family"],
|
||||
"billy-strings": ["bluegrass", "jam"],
|
||||
# Expansion Wave 1
|
||||
"pigeons-playing-ping-pong": ["jam", "funk"],
|
||||
"eggy": ["jam"],
|
||||
"dogs-in-a-pile": ["jam"],
|
||||
"greensky-bluegrass": ["bluegrass", "jam"],
|
||||
"daniel-donato": ["jam"],
|
||||
# Expansion Wave 2
|
||||
"umphreys-mcgee": ["jam"],
|
||||
"moe": ["jam"],
|
||||
"widespread-panic": ["jam"],
|
||||
"sturgill-simpson": ["bluegrass"],
|
||||
"slightly-stoopid": ["jam", "funk"],
|
||||
}
|
||||
|
||||
|
||||
def seed_scenes():
|
||||
"""Create scenes if they don't exist"""
|
||||
print("Seeding scenes...")
|
||||
|
||||
with Session(engine) as session:
|
||||
for scene_data in SCENES:
|
||||
existing = session.exec(
|
||||
select(Scene).where(Scene.slug == scene_data["slug"])
|
||||
).first()
|
||||
|
||||
if not existing:
|
||||
scene = Scene(**scene_data)
|
||||
session.add(scene)
|
||||
print(f" Created scene: {scene_data['name']}")
|
||||
else:
|
||||
print(f" Scene exists: {scene_data['name']}")
|
||||
|
||||
session.commit()
|
||||
print("Scenes seeded.")
|
||||
|
||||
|
||||
def assign_bands_to_scenes():
|
||||
"""Assign existing bands to their scenes"""
|
||||
print("\nAssigning bands to scenes...")
|
||||
|
||||
with Session(engine) as session:
|
||||
for band_slug, scene_slugs in BAND_SCENES.items():
|
||||
vertical = session.exec(
|
||||
select(Vertical).where(Vertical.slug == band_slug)
|
||||
).first()
|
||||
|
||||
if not vertical:
|
||||
continue
|
||||
|
||||
for scene_slug in scene_slugs:
|
||||
scene = session.exec(
|
||||
select(Scene).where(Scene.slug == scene_slug)
|
||||
).first()
|
||||
|
||||
if not scene:
|
||||
continue
|
||||
|
||||
# Check if assignment exists
|
||||
existing = session.exec(
|
||||
select(VerticalScene)
|
||||
.where(VerticalScene.vertical_id == vertical.id)
|
||||
.where(VerticalScene.scene_id == scene.id)
|
||||
).first()
|
||||
|
||||
if not existing:
|
||||
vs = VerticalScene(vertical_id=vertical.id, scene_id=scene.id)
|
||||
session.add(vs)
|
||||
print(f" Assigned {band_slug} -> {scene_slug}")
|
||||
|
||||
session.commit()
|
||||
print("Band scene assignments complete.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
seed_scenes()
|
||||
assign_bands_to_scenes()
|
||||
Loading…
Add table
Reference in a new issue