"""crons

Revision ID: 4366736872cc
Revises: b4e51a03cd8f
Create Date: 2026-01-30 15:57:27.293874

"""
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 = '4366736872cc'
down_revision: Union[str, None] = 'b4e51a03cd8f'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('cron_job_logs',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('module', sa.String(length=50), nullable=False),
    sa.Column('task_type', sa.String(length=100), nullable=False),
    sa.Column('batch_id', sa.String(length=255), nullable=True),
    sa.Column('status', sa.String(length=50), nullable=False),
    sa.Column('started_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
    sa.Column('completed_at', sa.DateTime(timezone=True), nullable=True),
    sa.Column('error_message', sa.Text(), nullable=True),
    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.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_cron_job_logs_batch_id'), 'cron_job_logs', ['batch_id'], unique=False)
    op.create_index(op.f('ix_cron_job_logs_id'), 'cron_job_logs', ['id'], unique=False)
    op.create_index(op.f('ix_cron_job_logs_module'), 'cron_job_logs', ['module'], unique=False)
    op.create_index(op.f('ix_cron_job_logs_task_type'), 'cron_job_logs', ['task_type'], unique=False)
    op.drop_index('ix_smart_inventory_cron_job_logs_id', table_name='smart_inventory_cron_job_logs')
    op.drop_index('ix_smart_inventory_cron_job_logs_task_id', table_name='smart_inventory_cron_job_logs')
    op.drop_index('ix_smart_inventory_cron_job_logs_task_type', table_name='smart_inventory_cron_job_logs')
    op.drop_table('smart_inventory_cron_job_logs')
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('smart_inventory_cron_job_logs',
    sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False),
    sa.Column('task_type', sa.VARCHAR(length=100), autoincrement=False, nullable=False),
    sa.Column('task_id', sa.VARCHAR(length=255), autoincrement=False, nullable=True),
    sa.Column('status', sa.VARCHAR(length=50), autoincrement=False, nullable=False),
    sa.Column('processed_count', sa.INTEGER(), autoincrement=False, nullable=True),
    sa.Column('inserted_count', sa.INTEGER(), autoincrement=False, nullable=True),
    sa.Column('updated_count', sa.INTEGER(), autoincrement=False, nullable=True),
    sa.Column('rows_inserted', sa.INTEGER(), autoincrement=False, nullable=True),
    sa.Column('target_date', sa.VARCHAR(length=50), autoincrement=False, nullable=True),
    sa.Column('started_at', postgresql.TIMESTAMP(timezone=True), server_default=sa.text('now()'), autoincrement=False, nullable=False),
    sa.Column('completed_at', postgresql.TIMESTAMP(timezone=True), autoincrement=False, nullable=True),
    sa.Column('duration_seconds', sa.INTEGER(), autoincrement=False, nullable=True),
    sa.Column('error_message', sa.TEXT(), autoincrement=False, nullable=True),
    sa.Column('task_result', postgresql.JSON(astext_type=sa.Text()), autoincrement=False, nullable=True),
    sa.Column('created_at', postgresql.TIMESTAMP(timezone=True), server_default=sa.text('now()'), autoincrement=False, nullable=False),
    sa.Column('updated_at', postgresql.TIMESTAMP(timezone=True), server_default=sa.text('now()'), autoincrement=False, nullable=False),
    sa.PrimaryKeyConstraint('id', name='smart_inventory_cron_job_logs_pkey')
    )
    op.create_index('ix_smart_inventory_cron_job_logs_task_type', 'smart_inventory_cron_job_logs', ['task_type'], unique=False)
    op.create_index('ix_smart_inventory_cron_job_logs_task_id', 'smart_inventory_cron_job_logs', ['task_id'], unique=False)
    op.create_index('ix_smart_inventory_cron_job_logs_id', 'smart_inventory_cron_job_logs', ['id'], unique=False)
    op.drop_index(op.f('ix_cron_job_logs_task_type'), table_name='cron_job_logs')
    op.drop_index(op.f('ix_cron_job_logs_module'), table_name='cron_job_logs')
    op.drop_index(op.f('ix_cron_job_logs_id'), table_name='cron_job_logs')
    op.drop_index(op.f('ix_cron_job_logs_batch_id'), table_name='cron_job_logs')
    op.drop_table('cron_job_logs')
    # ### end Alembic commands ###
