"""add_user_dismissed_tags

Revision ID: f98b3d2bd7b5
Revises: 2b16c6562fff
Create Date: 2026-07-14 07:09:41.514249
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa


revision: str = 'f98b3d2bd7b5'
down_revision: Union[str, None] = '2b16c6562fff'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    op.create_table('user_dismissed_tags',
    sa.Column('id', sa.Uuid(), nullable=False),
    sa.Column('user_id', sa.Uuid(), nullable=False),
    sa.Column('tag_id', sa.Uuid(), nullable=False),
    sa.Column('dismiss_count', sa.Integer(), nullable=False),
    sa.Column('last_dismissed_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
    sa.ForeignKeyConstraint(['tag_id'], ['global_tags.id'], ondelete='CASCADE'),
    sa.ForeignKeyConstraint(['user_id'], ['users.id'], ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('user_id', 'tag_id', name='uq_udt_user_tag')
    )
    op.create_index('ix_udt_user_count', 'user_dismissed_tags', ['user_id', 'dismiss_count'], unique=False)


def downgrade() -> None:
    op.drop_index('ix_udt_user_count', table_name='user_dismissed_tags')
    op.drop_table('user_dismissed_tags')
