"""Drop team_id from target_lists.

account_id (NOT NULL) is now the tenant isolation key; team_id is redundant.
All reads/writes use account_id via RLS + application filter.

Revision ID: 172ad76d7d20
Revises: 04f013768235
Create Date: 2026-04-11 00:00:00.000000
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa

revision: str = '172ad76d7d20'
down_revision: Union[str, None] = '04f013768235'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    op.drop_index('ix_target_lists_team_id', table_name='target_lists', if_exists=True)
    op.drop_constraint('target_lists_team_id_fkey', 'target_lists', type_='foreignkey')
    op.drop_column('target_lists', 'team_id')


def downgrade() -> None:
    op.add_column('target_lists', sa.Column('team_id', sa.UUID(), nullable=True))
    op.create_foreign_key(
        'target_lists_team_id_fkey', 'target_lists', 'teams',
        ['team_id'], ['id'], ondelete='CASCADE',
    )
    op.create_index('ix_target_lists_team_id', 'target_lists', ['team_id'])
