feat(db): add RehearsalSession table, songs.session_id, songs.tags
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>
This commit is contained in:
@@ -84,6 +84,9 @@ class Band(Base):
|
||||
songs: Mapped[list[Song]] = relationship(
|
||||
"Song", back_populates="band", cascade="all, delete-orphan"
|
||||
)
|
||||
sessions: Mapped[list[RehearsalSession]] = relationship(
|
||||
"RehearsalSession", back_populates="band", cascade="all, delete-orphan"
|
||||
)
|
||||
|
||||
|
||||
class BandMember(Base):
|
||||
@@ -128,6 +131,29 @@ class BandInvite(Base):
|
||||
creator: Mapped[Member] = relationship("Member", foreign_keys=[created_by])
|
||||
|
||||
|
||||
# ── Rehearsal Sessions ────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
class RehearsalSession(Base):
|
||||
__tablename__ = "rehearsal_sessions"
|
||||
__table_args__ = (UniqueConstraint("band_id", "date", name="uq_session_band_date"),)
|
||||
|
||||
id: Mapped[uuid.UUID] = mapped_column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
band_id: Mapped[uuid.UUID] = mapped_column(
|
||||
UUID(as_uuid=True), ForeignKey("bands.id", ondelete="CASCADE"), nullable=False, index=True
|
||||
)
|
||||
date: Mapped[datetime] = mapped_column(DateTime(timezone=False), nullable=False)
|
||||
nc_folder_path: Mapped[Optional[str]] = mapped_column(Text)
|
||||
label: Mapped[Optional[str]] = mapped_column(String(255))
|
||||
notes: Mapped[Optional[str]] = mapped_column(Text)
|
||||
created_at: Mapped[datetime] = mapped_column(
|
||||
DateTime(timezone=True), server_default=func.now(), nullable=False
|
||||
)
|
||||
|
||||
band: Mapped[Band] = relationship("Band", back_populates="sessions")
|
||||
songs: Mapped[list[Song]] = relationship("Song", back_populates="session")
|
||||
|
||||
|
||||
# ── Songs ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
@@ -138,9 +164,13 @@ class Song(Base):
|
||||
band_id: Mapped[uuid.UUID] = mapped_column(
|
||||
UUID(as_uuid=True), ForeignKey("bands.id", ondelete="CASCADE"), nullable=False, index=True
|
||||
)
|
||||
session_id: Mapped[Optional[uuid.UUID]] = mapped_column(
|
||||
UUID(as_uuid=True), ForeignKey("rehearsal_sessions.id", ondelete="SET NULL"), index=True
|
||||
)
|
||||
title: Mapped[str] = mapped_column(String(500), nullable=False)
|
||||
nc_folder_path: Mapped[Optional[str]] = mapped_column(Text)
|
||||
status: Mapped[str] = mapped_column(String(20), nullable=False, default="jam")
|
||||
tags: Mapped[list[str]] = mapped_column(ARRAY(Text), default=list, nullable=False)
|
||||
global_key: Mapped[Optional[str]] = mapped_column(String(30))
|
||||
global_bpm: Mapped[Optional[float]] = mapped_column(Numeric(6, 2))
|
||||
notes: Mapped[Optional[str]] = mapped_column(Text)
|
||||
@@ -155,6 +185,7 @@ class Song(Base):
|
||||
)
|
||||
|
||||
band: Mapped[Band] = relationship("Band", back_populates="songs")
|
||||
session: Mapped[Optional[RehearsalSession]] = relationship("RehearsalSession", back_populates="songs")
|
||||
creator: Mapped[Optional[Member]] = relationship("Member", back_populates="authored_songs")
|
||||
versions: Mapped[list[AudioVersion]] = relationship(
|
||||
"AudioVersion", back_populates="song", cascade="all, delete-orphan"
|
||||
|
||||
Reference in New Issue
Block a user