Commit 1df8a1ab authored by Aryan Noshirvnai's avatar Aryan Noshirvnai

Add three-tier Soundmarks: major landmarks, business playlists, community voting

Adds a tier column (major/business/community) with tier-specific
governance: major locations get a single super-admin-set anthem,
businesses get an owner-managed playlist, community spots stay fully
vote-driven. Adds a suggestion/review-queue system (SoundmarkSuggestion)
for major and business tiers, scoped so business admins only see
suggestions for soundmarks they own while super admins see everything.

Migration backfills tier from the existing business_owner_id (owned ->
business, unowned -> major) and seeds each business's playlist from its
old single song_id so existing anthems aren't silently dropped.
Co-Authored-By: 's avatarClaude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019i3NAUkLkHNbsPg5vKfzF9
parent 9531f3a9
Pipeline #1061 passed with stage
in 3 minutes and 41 seconds
"""add soundmark tiers, playlists, and suggestions
Revision ID: e612e2750fa2
Revises: 63839d131d50
Create Date: 2026-08-12 05:51:26.141644
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision: str = 'e612e2750fa2'
down_revision: Union[str, Sequence[str], None] = '63839d131d50'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
"""Upgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('soundmark_playlist_tracks',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('soundmark_id', sa.Integer(), nullable=True),
sa.Column('song_id', sa.Integer(), nullable=True),
sa.Column('position', sa.Integer(), nullable=True),
sa.Column('added_at', sa.DateTime(), nullable=True),
sa.ForeignKeyConstraint(['song_id'], ['library_songs.id'], ),
sa.ForeignKeyConstraint(['soundmark_id'], ['soundmarks.id'], ),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('soundmark_id', 'song_id', name='uq_soundmark_playlist_song')
)
op.create_index(op.f('ix_soundmark_playlist_tracks_id'), 'soundmark_playlist_tracks', ['id'], unique=False)
op.create_index(op.f('ix_soundmark_playlist_tracks_soundmark_id'), 'soundmark_playlist_tracks', ['soundmark_id'], unique=False)
op.create_table('soundmark_suggestions',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('soundmark_id', sa.Integer(), nullable=True),
sa.Column('song_id', sa.Integer(), nullable=True),
sa.Column('suggested_by_user_id', sa.Integer(), nullable=True),
sa.Column('status', sa.String(), nullable=True),
sa.Column('reviewed_by_user_id', sa.Integer(), nullable=True),
sa.Column('reviewed_at', sa.DateTime(), nullable=True),
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.ForeignKeyConstraint(['reviewed_by_user_id'], ['users.id'], ),
sa.ForeignKeyConstraint(['song_id'], ['library_songs.id'], ),
sa.ForeignKeyConstraint(['soundmark_id'], ['soundmarks.id'], ),
sa.ForeignKeyConstraint(['suggested_by_user_id'], ['users.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_soundmark_suggestions_id'), 'soundmark_suggestions', ['id'], unique=False)
op.create_index(op.f('ix_soundmark_suggestions_soundmark_id'), 'soundmark_suggestions', ['soundmark_id'], unique=False)
op.create_index(op.f('ix_soundmark_suggestions_status'), 'soundmark_suggestions', ['status'], unique=False)
# server_default backfills existing rows with the model's own default ('community') -
# without it, adding a NOT NULL column to a table that already has rows fails.
op.add_column('soundmarks', sa.Column('tier', sa.String(), nullable=False, server_default='community'))
# ### end Alembic commands ###
# Data migration: existing soundmarks predate tiers, but they were all created by an
# admin through the super admin panel - not submitted by the public - so the closest
# honest classification is by whether they have an owner, not a blanket "community".
op.execute("UPDATE soundmarks SET tier = 'business' WHERE business_owner_id IS NOT NULL")
op.execute("UPDATE soundmarks SET tier = 'major' WHERE business_owner_id IS NULL")
# Business tier no longer plays sm.song_id directly (it plays the first playlist track) -
# without this, every pre-existing business soundmark that had a song set the old way would
# silently go anthem-less until someone manually re-added the same song to its playlist.
op.execute(
"INSERT INTO soundmark_playlist_tracks (soundmark_id, song_id, position) "
"SELECT id, song_id, 0 FROM soundmarks WHERE business_owner_id IS NOT NULL AND song_id IS NOT NULL"
)
def downgrade() -> None:
"""Downgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('soundmarks', 'tier')
op.drop_index(op.f('ix_soundmark_suggestions_status'), table_name='soundmark_suggestions')
op.drop_index(op.f('ix_soundmark_suggestions_soundmark_id'), table_name='soundmark_suggestions')
op.drop_index(op.f('ix_soundmark_suggestions_id'), table_name='soundmark_suggestions')
op.drop_table('soundmark_suggestions')
op.drop_index(op.f('ix_soundmark_playlist_tracks_soundmark_id'), table_name='soundmark_playlist_tracks')
op.drop_index(op.f('ix_soundmark_playlist_tracks_id'), table_name='soundmark_playlist_tracks')
op.drop_table('soundmark_playlist_tracks')
# ### end Alembic commands ###
This diff is collapsed.
...@@ -128,15 +128,24 @@ class GeoDrop(Base): ...@@ -128,15 +128,24 @@ class GeoDrop(Base):
class Soundmark(Base): class Soundmark(Base):
"""A curated 'anthem' tied to a real-world place - distinct from GeoDrop (any user """A curated 'anthem' tied to a real-world place - distinct from GeoDrop (any user
dropping a song for others to stumble on). A Soundmark with business_owner_id NULL is a dropping a song for others to stumble on). Three tiers, distinguished by `tier`:
super-admin-curated landmark (e.g. locally significant to the area); one with an owner is
that business's location, and its anthem can only be changed by that owner or a super - "major": a super-admin-curated landmark. One official song (song_id), set directly by a
admin. song_id is nullable so a soundmark can exist (name/location set by a super admin) super admin (auto-applied). Anyone else's pick goes through SoundmarkSuggestion instead.
before anyone has picked its anthem yet.""" - "business": owned by a business_owner_id. Has a *playlist* (SoundmarkPlaylistTrack), not
a single song - the owner adds/removes tracks directly (auto-applied); everyone else's
picks go through SoundmarkSuggestion.
- "community": no owner, fully automated. Anyone can propose a song (SoundmarkProposal) and
vote; the most-voted one just plays, no review step at all - see
soundmarks.py's _resolve_active_song_id.
song_id is only meaningful for "major" (and as a legacy fallback for pre-tier "community"
rows that predate SoundmarkProposal - see _resolve_active_song_id)."""
__tablename__ = "soundmarks" __tablename__ = "soundmarks"
id = Column(Integer, primary_key=True, index=True) id = Column(Integer, primary_key=True, index=True)
name = Column(String, index=True) name = Column(String, index=True)
description = Column(String, nullable=True) description = Column(String, nullable=True)
tier = Column(String, default="community", nullable=False) # "major" | "business" | "community"
latitude = Column(Float) latitude = Column(Float)
longitude = Column(Float) longitude = Column(Float)
# How close (in meters) someone needs to be for this soundmark to be considered "active" - # How close (in meters) someone needs to be for this soundmark to be considered "active" -
...@@ -147,11 +156,39 @@ class Soundmark(Base): ...@@ -147,11 +156,39 @@ class Soundmark(Base):
created_at = Column(DateTime, default=lambda: datetime.now(timezone.utc)) created_at = Column(DateTime, default=lambda: datetime.now(timezone.utc))
updated_at = Column(DateTime, default=lambda: datetime.now(timezone.utc), onupdate=lambda: datetime.now(timezone.utc)) updated_at = Column(DateTime, default=lambda: datetime.now(timezone.utc), onupdate=lambda: datetime.now(timezone.utc))
class SoundmarkPlaylistTrack(Base):
"""One song in a "business"-tier soundmark's playlist. Added directly by the business
owner or a super admin (auto-applied, no review) - see SoundmarkSuggestion for how a
non-owner's pick gets added instead (only after being approved)."""
__tablename__ = "soundmark_playlist_tracks"
__table_args__ = (UniqueConstraint("soundmark_id", "song_id", name="uq_soundmark_playlist_song"),)
id = Column(Integer, primary_key=True, index=True)
soundmark_id = Column(Integer, ForeignKey("soundmarks.id"), index=True)
song_id = Column(Integer, ForeignKey("library_songs.id"))
position = Column(Integer, default=0)
added_at = Column(DateTime, default=lambda: datetime.now(timezone.utc))
class SoundmarkSuggestion(Base):
"""A song someone other than the owner suggested for a "major" or "business" soundmark -
sits in a review queue until the owner (business admin for their own business, super admin
for major locations - super admin can review either) approves or rejects it. Approving
applies the effect (sets Soundmark.song_id for "major", adds a SoundmarkPlaylistTrack for
"business"). "community" soundmarks don't use this at all - they use
SoundmarkProposal/SoundmarkProposalVote instead, with no review step."""
__tablename__ = "soundmark_suggestions"
id = Column(Integer, primary_key=True, index=True)
soundmark_id = Column(Integer, ForeignKey("soundmarks.id"), index=True)
song_id = Column(Integer, ForeignKey("library_songs.id"))
suggested_by_user_id = Column(Integer, ForeignKey("users.id"))
status = Column(String, default="pending", index=True) # "pending" | "approved" | "rejected"
reviewed_by_user_id = Column(Integer, ForeignKey("users.id"), nullable=True)
reviewed_at = Column(DateTime, nullable=True)
created_at = Column(DateTime, default=lambda: datetime.now(timezone.utc))
class SoundmarkProposal(Base): class SoundmarkProposal(Base):
"""A candidate anthem someone's suggested for a soundmark. The proposal with the most """A candidate anthem someone's suggested for a "community"-tier soundmark - see
votes is what actually plays there (see soundmarks.py's _resolve_active_song) - the Soundmark's docstring. The proposal with the most votes is what actually plays there (see
business/super-admin-set Soundmark.song_id is only the fallback used while a soundmark has soundmarks.py's _resolve_active_song_id); there's no review step for this tier."""
no proposals yet, not a permanent override."""
__tablename__ = "soundmark_proposals" __tablename__ = "soundmark_proposals"
__table_args__ = (UniqueConstraint("soundmark_id", "song_id", name="uq_soundmark_proposal_song"),) __table_args__ = (UniqueConstraint("soundmark_id", "song_id", name="uq_soundmark_proposal_song"),)
id = Column(Integer, primary_key=True, index=True) id = Column(Integer, primary_key=True, index=True)
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment