"""Add Crawl property Table

Revision ID: 425ed29584d5
Revises: f652e94c3a0f
Create Date: 2025-07-18 19:19:02.554621

"""
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 = '425ed29584d5'
down_revision: Union[str, None] = 'f652e94c3a0f'
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('job_logs',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('literal', sa.String(), nullable=True),
    sa.Column('code', sa.String(), nullable=True),
    sa.Column('name', sa.String(), nullable=True),
    sa.Column('url', sa.Text(), nullable=True),
    sa.Column('status', sa.String(), nullable=True),
    sa.Column('total_records', sa.Integer(), nullable=True),
    sa.Column('total_prices', sa.DECIMAL(), nullable=True),
    sa.Column('date_start', sa.DateTime(), nullable=True),
    sa.Column('date_end', sa.DateTime(), nullable=True),
    sa.Column('message', sa.Text(), nullable=True),
    sa.Column('total_validation', sa.Integer(), nullable=True),
    sa.Column('validation_passed', sa.Integer(), nullable=True),
    sa.Column('validation_warn', sa.Integer(), nullable=True),
    sa.Column('validation_failed', sa.Integer(), nullable=True),
    sa.Column('validation_status', sa.String(), nullable=True),
    sa.Column('validation_message', sa.Text(), nullable=True),
    sa.Column('date_created', sa.DateTime(), nullable=True),
    sa.Column('last_updated', sa.DateTime(), nullable=True),
    sa.Column('job_date', sa.DateTime(), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_job_logs_code'), 'job_logs', ['code'], unique=False)
    op.create_index(op.f('ix_job_logs_id'), 'job_logs', ['id'], unique=False)
    op.create_index(op.f('ix_job_logs_status'), 'job_logs', ['status'], unique=False)
    op.create_index(op.f('ix_job_logs_validation_status'), 'job_logs', ['validation_status'], unique=False)
    op.create_table('matched_logs',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('literal', sa.String(), nullable=True),
    sa.Column('code', sa.String(), nullable=True),
    sa.Column('process_keyword', sa.Boolean(), nullable=True),
    sa.Column('total_records', sa.Integer(), nullable=True),
    sa.Column('history_matched', sa.Integer(), nullable=True),
    sa.Column('keyword_matched', sa.Integer(), nullable=True),
    sa.Column('ambiguous_matched', sa.Integer(), nullable=True),
    sa.Column('unknown_wines', sa.Integer(), nullable=True),
    sa.Column('status', sa.String(), nullable=True),
    sa.Column('crawl_date', sa.DateTime(), nullable=True),
    sa.Column('date_start', sa.DateTime(), nullable=True),
    sa.Column('date_end', sa.DateTime(), nullable=True),
    sa.Column('message', sa.Text(), nullable=True),
    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_matched_logs_code'), 'matched_logs', ['code'], unique=False)
    op.create_index(op.f('ix_matched_logs_id'), 'matched_logs', ['id'], unique=False)
    op.create_table('wine_matches',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('uuid', sa.UUID(), nullable=False),
    sa.Column('name', sa.String(length=255), nullable=False),
    sa.Column('description', sa.Text(), nullable=True),
    sa.Column('is_deleted', sa.Boolean(), nullable=False),
    sa.Column('deleted_at', sa.DateTime(), nullable=True),
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('updated_at', sa.DateTime(), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_wine_matches_uuid'), 'wine_matches', ['uuid'], unique=True)
    op.create_table('crawl_properties',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('web_crawler_id', sa.Integer(), nullable=False),
    sa.Column('wine_property', sa.String(), nullable=False),
    sa.Column('custom_label', sa.String(), nullable=True),
    sa.Column('property_index', sa.Integer(), nullable=False),
    sa.Column('data_output', sa.Boolean(), nullable=True),
    sa.Column('selectors', sa.String(), nullable=True),
    sa.ForeignKeyConstraint(['web_crawler_id'], ['web_crawlers.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.alter_column('producer_keywords', 'producer_id',
               existing_type=sa.INTEGER(),
               nullable=False)
    op.alter_column('wine_db', 'status',
               existing_type=postgresql.ENUM('ACTIVE', 'DELETED', name='winedbstatus'),
               type_=sa.String(),
               existing_nullable=True)
    op.alter_column('wine_keywords', 'wine_db_id',
               existing_type=sa.INTEGER(),
               nullable=False)
    # ### end Alembic commands ###


def downgrade() -> None:
    """Downgrade schema."""
    # ### commands auto generated by Alembic - please adjust! ###
    op.alter_column('wine_keywords', 'wine_db_id',
               existing_type=sa.INTEGER(),
               nullable=True)
    op.alter_column('wine_db', 'status',
               existing_type=sa.String(),
               type_=postgresql.ENUM('ACTIVE', 'DELETED', name='winedbstatus'),
               existing_nullable=True)
    op.alter_column('producer_keywords', 'producer_id',
               existing_type=sa.INTEGER(),
               nullable=True)
    op.drop_table('crawl_properties')
    op.drop_index(op.f('ix_wine_matches_uuid'), table_name='wine_matches')
    op.drop_table('wine_matches')
    op.drop_index(op.f('ix_matched_logs_id'), table_name='matched_logs')
    op.drop_index(op.f('ix_matched_logs_code'), table_name='matched_logs')
    op.drop_table('matched_logs')
    op.drop_index(op.f('ix_job_logs_validation_status'), table_name='job_logs')
    op.drop_index(op.f('ix_job_logs_status'), table_name='job_logs')
    op.drop_index(op.f('ix_job_logs_id'), table_name='job_logs')
    op.drop_index(op.f('ix_job_logs_code'), table_name='job_logs')
    op.drop_table('job_logs')
    # ### end Alembic commands ###
