Introduces the rehearsal session concept: each YYMMDD folder in Nextcloud maps to one RehearsalSession row (band_id + date unique). Songs gain a nullable session_id FK and a tags TEXT[] column for manual labeling (searchable by name, tag, BPM, key). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
50 lines
1.7 KiB
Python
50 lines
1.7 KiB
Python
"""Add rehearsal_sessions table, songs.session_id, songs.tags.
|
|
|
|
Revision ID: 0004
|
|
Revises: 0003
|
|
Create Date: 2026-03-29
|
|
"""
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
from sqlalchemy.dialects.postgresql import ARRAY, UUID
|
|
|
|
revision = "0004"
|
|
down_revision = "0003"
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
op.create_table(
|
|
"rehearsal_sessions",
|
|
sa.Column("id", UUID(as_uuid=True), primary_key=True),
|
|
sa.Column("band_id", UUID(as_uuid=True), sa.ForeignKey("bands.id", ondelete="CASCADE"), nullable=False),
|
|
sa.Column("date", sa.DateTime(timezone=False), nullable=False),
|
|
sa.Column("nc_folder_path", sa.Text()),
|
|
sa.Column("label", sa.String(255)),
|
|
sa.Column("notes", sa.Text()),
|
|
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
|
|
sa.UniqueConstraint("band_id", "date", name="uq_session_band_date"),
|
|
)
|
|
op.create_index("ix_rehearsal_sessions_band_id", "rehearsal_sessions", ["band_id"])
|
|
|
|
op.add_column("songs", sa.Column(
|
|
"session_id", UUID(as_uuid=True),
|
|
sa.ForeignKey("rehearsal_sessions.id", ondelete="SET NULL"),
|
|
nullable=True,
|
|
))
|
|
op.create_index("ix_songs_session_id", "songs", ["session_id"])
|
|
|
|
op.add_column("songs", sa.Column(
|
|
"tags", ARRAY(sa.Text()), nullable=False, server_default="{}",
|
|
))
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.drop_column("songs", "tags")
|
|
op.drop_index("ix_songs_session_id", table_name="songs")
|
|
op.drop_column("songs", "session_id")
|
|
op.drop_index("ix_rehearsal_sessions_band_id", table_name="rehearsal_sessions")
|
|
op.drop_table("rehearsal_sessions")
|