57 lines
1.9 KiB
Python
57 lines
1.9 KiB
Python
|
|
"""Add named taste profiles and speaker mappings
|
||
|
|
|
||
|
|
Revision ID: 003
|
||
|
|
Revises: 002
|
||
|
|
Create Date: 2026-02-22
|
||
|
|
|
||
|
|
"""
|
||
|
|
from typing import Sequence, Union
|
||
|
|
|
||
|
|
import sqlalchemy as sa
|
||
|
|
from alembic import op
|
||
|
|
|
||
|
|
revision: str = "003"
|
||
|
|
down_revision: Union[str, None] = "002"
|
||
|
|
branch_labels: Union[str, Sequence[str], None] = None
|
||
|
|
depends_on: Union[str, Sequence[str], None] = None
|
||
|
|
|
||
|
|
|
||
|
|
def upgrade() -> None:
|
||
|
|
# 1. Create profiles table
|
||
|
|
op.create_table(
|
||
|
|
"profiles",
|
||
|
|
sa.Column("id", sa.BigInteger, primary_key=True),
|
||
|
|
sa.Column("name", sa.Text, unique=True, nullable=False),
|
||
|
|
sa.Column("display_name", sa.Text),
|
||
|
|
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.func.now()),
|
||
|
|
)
|
||
|
|
|
||
|
|
# 2. Seed "default" profile
|
||
|
|
op.execute("INSERT INTO profiles (id, name, display_name) VALUES (1, 'default', 'Default')")
|
||
|
|
|
||
|
|
# 3. Create speaker_profile_mappings table
|
||
|
|
op.create_table(
|
||
|
|
"speaker_profile_mappings",
|
||
|
|
sa.Column("id", sa.BigInteger, primary_key=True),
|
||
|
|
sa.Column("speaker_name", sa.Text, unique=True, nullable=False),
|
||
|
|
sa.Column("profile_id", sa.BigInteger, sa.ForeignKey("profiles.id"), nullable=False),
|
||
|
|
)
|
||
|
|
|
||
|
|
# 4. Add profile_id to listen_events (nullable — NULL means "default")
|
||
|
|
op.add_column("listen_events", sa.Column("profile_id", sa.BigInteger, sa.ForeignKey("profiles.id")))
|
||
|
|
|
||
|
|
# 5. Add profile_id to taste_profiles (nullable, unique)
|
||
|
|
op.add_column("taste_profiles", sa.Column("profile_id", sa.BigInteger, sa.ForeignKey("profiles.id"), unique=True))
|
||
|
|
|
||
|
|
# 6. Link existing "default" taste profile row to the default profile
|
||
|
|
op.execute(
|
||
|
|
"UPDATE taste_profiles SET profile_id = 1 WHERE name = 'default'"
|
||
|
|
)
|
||
|
|
|
||
|
|
|
||
|
|
def downgrade() -> None:
|
||
|
|
op.drop_column("taste_profiles", "profile_id")
|
||
|
|
op.drop_column("listen_events", "profile_id")
|
||
|
|
op.drop_table("speaker_profile_mappings")
|
||
|
|
op.drop_table("profiles")
|