"""add validation

Revision ID: 71046ff74214
Revises: 8ba055a43d6d
Create Date: 2025-09-01 16:47:49.275007

"""
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 = '71046ff74214'
down_revision: Union[str, None] = '8ba055a43d6d'
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('work_groups',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(), nullable=False),
    sa.Column('date_created', sa.DateTime(), nullable=True),
    sa.Column('last_updated', sa.DateTime(), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_work_groups_id'), 'work_groups', ['id'], unique=False)
    op.create_table('work_group_web_crawlers',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('work_group_id', sa.Integer(), nullable=False),
    sa.Column('web_crawler_id', sa.Integer(), nullable=False),
    sa.Column('date_created', sa.DateTime(), nullable=True),
    sa.Column('last_updated', sa.DateTime(), nullable=True),
    sa.ForeignKeyConstraint(['web_crawler_id'], ['web_crawlers.id'], ),
    sa.ForeignKeyConstraint(['work_group_id'], ['work_groups.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_work_group_web_crawlers_id'), 'work_group_web_crawlers', ['id'], unique=False)
    op.alter_column('wine_db', 'source',
               existing_type=postgresql.ENUM('IMPORT', 'MANUAL', name='sourceenum'),
               type_=sa.String(),
               existing_nullable=True)
    op.add_column('wine_matches', sa.Column('wine_alert_id', sa.String(length=255), nullable=True))
    op.add_column('wine_matches', sa.Column('web_crawler_id', sa.Integer(), nullable=True))
    op.add_column('wine_matches', sa.Column('validation_type', sa.String(length=255), nullable=True))
    op.add_column('wine_matches', sa.Column('keyword', sa.String(length=255), nullable=True))
    op.add_column('wine_matches', sa.Column('status', sa.String(length=50), nullable=True))
    op.create_foreign_key('ix_wine_matches_web_crawler_id', 'wine_matches', 'web_crawlers', ['web_crawler_id'], ['id'])
    op.alter_column('wine_noises', 'wine_db_id',
               existing_type=sa.INTEGER(),
               nullable=True)
    # ### end Alembic commands ###


def downgrade() -> None:
    """Downgrade schema."""
    # ### commands auto generated by Alembic - please adjust! ###
    op.alter_column('wine_noises', 'wine_db_id',
               existing_type=sa.INTEGER(),
               nullable=False)
    op.drop_constraint('ix_wine_matches_web_crawler_id', 'wine_matches', type_='foreignkey')
    op.drop_column('wine_matches', 'status')
    op.drop_column('wine_matches', 'keyword')
    op.drop_column('wine_matches', 'validation_type')
    op.drop_column('wine_matches', 'web_crawler_id')
    op.drop_column('wine_matches', 'wine_alert_id')
    op.alter_column('wine_db', 'source',
               existing_type=sa.String(),
               type_=postgresql.ENUM('IMPORT', 'MANUAL', name='sourceenum'),
               existing_nullable=True)
    op.drop_index(op.f('ix_work_group_web_crawlers_id'), table_name='work_group_web_crawlers')
    op.drop_table('work_group_web_crawlers')
    op.drop_index(op.f('ix_work_groups_id'), table_name='work_groups')
    op.drop_table('work_groups')
    # ### end Alembic commands ###
