"""added user preferences table

Revision ID: c6c36663acd5
Revises: dc57fb290621
Create Date: 2025-11-25 18:47:59.146263

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision: str = 'c6c36663acd5'
down_revision: Union[str, Sequence[str], None] = 'dc57fb290621'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    """Upgrade schema."""
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('user_preferences',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('contact_id', sa.Integer(), nullable=False),
    sa.Column('likes', postgresql.JSONB(astext_type=sa.Text()), server_default='[]', nullable=False),
    sa.Column('dislikes', postgresql.JSONB(astext_type=sa.Text()), server_default='[]', nullable=False),
    sa.Column('facts', postgresql.JSONB(astext_type=sa.Text()), server_default='[]', nullable=False),
    sa.Column('plans', postgresql.JSONB(astext_type=sa.Text()), server_default='[]', nullable=False),
    sa.Column('total_extractions', sa.Integer(), server_default='0', nullable=False),
    sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
    sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
    sa.Column('deleted_at', sa.DateTime(timezone=True), nullable=True),
    sa.ForeignKeyConstraint(['contact_id'], ['contact.id'], name=op.f('user_preferences_contact_id_fkey'), ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('id', name=op.f('user_preferences_pkey')),
    sa.UniqueConstraint('contact_id', name=op.f('user_preferences_contact_id_key'))
    )
    op.create_index('ix_userpreferences_contact', 'user_preferences', ['contact_id'], unique=False)
    op.create_index('ix_userpreferences_updated', 'user_preferences', ['updated_at'], unique=False)
    # ### end Alembic commands ###


def downgrade() -> None:
    """Downgrade schema."""
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index('ix_userpreferences_updated', table_name='user_preferences')
    op.drop_index('ix_userpreferences_contact', table_name='user_preferences')
    op.drop_table('user_preferences')
    # ### end Alembic commands ###
