"""add_asset_path_to_meetings

Revision ID: e9f0a1b2c3d4
Revises: d8e5f6a7b2c3
Create Date: 2025-12-19 08:00:00.000000

"""

from collections.abc import Sequence

import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision: str = "e9f0a1b2c3d4"
down_revision: str | Sequence[str] | None = "d8e5f6a7b2c3"
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None


def upgrade() -> None:
    """Add asset_path column to meetings table.

    Stores the relative path for audio files. This allows the meetings_dir
    to change without orphaning existing recordings.
    """
    op.add_column(
        "meetings",
        sa.Column("asset_path", sa.Text(), nullable=True),
        schema="noteflow",
    )

    # Backfill existing rows: asset_path = id (as string)
    op.execute(
        """
        UPDATE noteflow.meetings
        SET asset_path = id::text
        WHERE asset_path IS NULL
        """
    )


def downgrade() -> None:
    """Remove asset_path column from meetings table."""
    op.drop_column("meetings", "asset_path", schema="noteflow")
