"""Immutable zkEvm with it's sepolia blockchains

Revision ID: 211646463e9f
Revises: 090c247f8618
Create Date: 2024-07-25 14:14:41.548326

"""
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 = '211646463e9f'
down_revision: Union[str, None] = '090c247f8618'
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('imx_zkevm_labels',
    sa.Column('id', sa.UUID(), nullable=False),
    sa.Column('label', sa.VARCHAR(length=256), nullable=False),
    sa.Column('transaction_hash', sa.VARCHAR(length=128), nullable=False),
    sa.Column('log_index', sa.Integer(), nullable=True),
    sa.Column('block_number', sa.BigInteger(), nullable=False),
    sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False),
    sa.Column('block_timestamp', sa.BigInteger(), nullable=False),
    sa.Column('caller_address', sa.LargeBinary(), nullable=True),
    sa.Column('origin_address', sa.LargeBinary(), nullable=True),
    sa.Column('address', sa.LargeBinary(), nullable=False),
    sa.Column('label_name', sa.Text(), nullable=True),
    sa.Column('label_type', sa.VARCHAR(length=64), nullable=True),
    sa.Column('label_data', postgresql.JSONB(astext_type=sa.Text()), nullable=True),
    sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False),
    sa.PrimaryKeyConstraint('id', name=op.f('pk_imx_zkevm_labels')),
    sa.UniqueConstraint('id', name=op.f('uq_imx_zkevm_labels_id'))
    )
    op.create_index('ix_imx_zkevm_labels_addr_block_num', 'imx_zkevm_labels', ['address', 'block_number'], unique=False)
    op.create_index('ix_imx_zkevm_labels_addr_block_ts', 'imx_zkevm_labels', ['address', 'block_timestamp'], unique=False)
    op.create_index(op.f('ix_imx_zkevm_labels_address'), 'imx_zkevm_labels', ['address'], unique=False)
    op.create_index(op.f('ix_imx_zkevm_labels_block_number'), 'imx_zkevm_labels', ['block_number'], unique=False)
    op.create_index(op.f('ix_imx_zkevm_labels_caller_address'), 'imx_zkevm_labels', ['caller_address'], unique=False)
    op.create_index(op.f('ix_imx_zkevm_labels_label'), 'imx_zkevm_labels', ['label'], unique=False)
    op.create_index(op.f('ix_imx_zkevm_labels_label_name'), 'imx_zkevm_labels', ['label_name'], unique=False)
    op.create_index(op.f('ix_imx_zkevm_labels_label_type'), 'imx_zkevm_labels', ['label_type'], unique=False)
    op.create_index(op.f('ix_imx_zkevm_labels_origin_address'), 'imx_zkevm_labels', ['origin_address'], unique=False)
    op.create_index(op.f('ix_imx_zkevm_labels_transaction_hash'), 'imx_zkevm_labels', ['transaction_hash'], unique=False)
    op.create_index('uk_imx_zkevm_labels_tx_hash_log_idx_evt', 'imx_zkevm_labels', ['transaction_hash', 'log_index'], unique=True, postgresql_where=sa.text("label='seer' and label_type='event'"))
    op.create_index('uk_imx_zkevm_labels_tx_hash_log_idx_evt_raw', 'imx_zkevm_labels', ['transaction_hash', 'log_index'], unique=True, postgresql_where=sa.text("label='seer-raw' and label_type='event'"))
    op.create_index('uk_imx_zkevm_labels_tx_hash_tx_call', 'imx_zkevm_labels', ['transaction_hash'], unique=True, postgresql_where=sa.text("label='seer' and label_type='tx_call'"))
    op.create_index('uk_imx_zkevm_labels_tx_hash_tx_call_raw', 'imx_zkevm_labels', ['transaction_hash'], unique=True, postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'"))
    op.create_table('imx_zkevm_sepolia_labels',
    sa.Column('id', sa.UUID(), nullable=False),
    sa.Column('label', sa.VARCHAR(length=256), nullable=False),
    sa.Column('transaction_hash', sa.VARCHAR(length=128), nullable=False),
    sa.Column('log_index', sa.Integer(), nullable=True),
    sa.Column('block_number', sa.BigInteger(), nullable=False),
    sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False),
    sa.Column('block_timestamp', sa.BigInteger(), nullable=False),
    sa.Column('caller_address', sa.LargeBinary(), nullable=True),
    sa.Column('origin_address', sa.LargeBinary(), nullable=True),
    sa.Column('address', sa.LargeBinary(), nullable=False),
    sa.Column('label_name', sa.Text(), nullable=True),
    sa.Column('label_type', sa.VARCHAR(length=64), nullable=True),
    sa.Column('label_data', postgresql.JSONB(astext_type=sa.Text()), nullable=True),
    sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False),
    sa.PrimaryKeyConstraint('id', name=op.f('pk_imx_zkevm_sepolia_labels')),
    sa.UniqueConstraint('id', name=op.f('uq_imx_zkevm_sepolia_labels_id'))
    )
    op.create_index('ix_imx_zkevm_sepolia_labels_addr_block_num', 'imx_zkevm_sepolia_labels', ['address', 'block_number'], unique=False)
    op.create_index('ix_imx_zkevm_sepolia_labels_addr_block_ts', 'imx_zkevm_sepolia_labels', ['address', 'block_timestamp'], unique=False)
    op.create_index(op.f('ix_imx_zkevm_sepolia_labels_address'), 'imx_zkevm_sepolia_labels', ['address'], unique=False)
    op.create_index(op.f('ix_imx_zkevm_sepolia_labels_block_number'), 'imx_zkevm_sepolia_labels', ['block_number'], unique=False)
    op.create_index(op.f('ix_imx_zkevm_sepolia_labels_caller_address'), 'imx_zkevm_sepolia_labels', ['caller_address'], unique=False)
    op.create_index(op.f('ix_imx_zkevm_sepolia_labels_label'), 'imx_zkevm_sepolia_labels', ['label'], unique=False)
    op.create_index(op.f('ix_imx_zkevm_sepolia_labels_label_name'), 'imx_zkevm_sepolia_labels', ['label_name'], unique=False)
    op.create_index(op.f('ix_imx_zkevm_sepolia_labels_label_type'), 'imx_zkevm_sepolia_labels', ['label_type'], unique=False)
    op.create_index(op.f('ix_imx_zkevm_sepolia_labels_origin_address'), 'imx_zkevm_sepolia_labels', ['origin_address'], unique=False)
    op.create_index(op.f('ix_imx_zkevm_sepolia_labels_transaction_hash'), 'imx_zkevm_sepolia_labels', ['transaction_hash'], unique=False)
    op.create_index('uk_imx_zkevm_sepolia_labels_tx_hash_log_idx_evt', 'imx_zkevm_sepolia_labels', ['transaction_hash', 'log_index'], unique=True, postgresql_where=sa.text("label='seer' and label_type='event'"))
    op.create_index('uk_imx_zkevm_sepolia_labels_tx_hash_log_idx_evt_raw', 'imx_zkevm_sepolia_labels', ['transaction_hash', 'log_index'], unique=True, postgresql_where=sa.text("label='seer-raw' and label_type='event'"))
    op.create_index('uk_imx_zkevm_sepolia_labels_tx_hash_tx_call', 'imx_zkevm_sepolia_labels', ['transaction_hash'], unique=True, postgresql_where=sa.text("label='seer' and label_type='tx_call'"))
    op.create_index('uk_imx_zkevm_sepolia_labels_tx_hash_tx_call_raw', 'imx_zkevm_sepolia_labels', ['transaction_hash'], unique=True, postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'"))
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index('uk_imx_zkevm_sepolia_labels_tx_hash_tx_call_raw', table_name='imx_zkevm_sepolia_labels', postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'"))
    op.drop_index('uk_imx_zkevm_sepolia_labels_tx_hash_tx_call', table_name='imx_zkevm_sepolia_labels', postgresql_where=sa.text("label='seer' and label_type='tx_call'"))
    op.drop_index('uk_imx_zkevm_sepolia_labels_tx_hash_log_idx_evt_raw', table_name='imx_zkevm_sepolia_labels', postgresql_where=sa.text("label='seer-raw' and label_type='event'"))
    op.drop_index('uk_imx_zkevm_sepolia_labels_tx_hash_log_idx_evt', table_name='imx_zkevm_sepolia_labels', postgresql_where=sa.text("label='seer' and label_type='event'"))
    op.drop_index(op.f('ix_imx_zkevm_sepolia_labels_transaction_hash'), table_name='imx_zkevm_sepolia_labels')
    op.drop_index(op.f('ix_imx_zkevm_sepolia_labels_origin_address'), table_name='imx_zkevm_sepolia_labels')
    op.drop_index(op.f('ix_imx_zkevm_sepolia_labels_label_type'), table_name='imx_zkevm_sepolia_labels')
    op.drop_index(op.f('ix_imx_zkevm_sepolia_labels_label_name'), table_name='imx_zkevm_sepolia_labels')
    op.drop_index(op.f('ix_imx_zkevm_sepolia_labels_label'), table_name='imx_zkevm_sepolia_labels')
    op.drop_index(op.f('ix_imx_zkevm_sepolia_labels_caller_address'), table_name='imx_zkevm_sepolia_labels')
    op.drop_index(op.f('ix_imx_zkevm_sepolia_labels_block_number'), table_name='imx_zkevm_sepolia_labels')
    op.drop_index(op.f('ix_imx_zkevm_sepolia_labels_address'), table_name='imx_zkevm_sepolia_labels')
    op.drop_index('ix_imx_zkevm_sepolia_labels_addr_block_ts', table_name='imx_zkevm_sepolia_labels')
    op.drop_index('ix_imx_zkevm_sepolia_labels_addr_block_num', table_name='imx_zkevm_sepolia_labels')
    op.drop_table('imx_zkevm_sepolia_labels')
    op.drop_index('uk_imx_zkevm_labels_tx_hash_tx_call_raw', table_name='imx_zkevm_labels', postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'"))
    op.drop_index('uk_imx_zkevm_labels_tx_hash_tx_call', table_name='imx_zkevm_labels', postgresql_where=sa.text("label='seer' and label_type='tx_call'"))
    op.drop_index('uk_imx_zkevm_labels_tx_hash_log_idx_evt_raw', table_name='imx_zkevm_labels', postgresql_where=sa.text("label='seer-raw' and label_type='event'"))
    op.drop_index('uk_imx_zkevm_labels_tx_hash_log_idx_evt', table_name='imx_zkevm_labels', postgresql_where=sa.text("label='seer' and label_type='event'"))
    op.drop_index(op.f('ix_imx_zkevm_labels_transaction_hash'), table_name='imx_zkevm_labels')
    op.drop_index(op.f('ix_imx_zkevm_labels_origin_address'), table_name='imx_zkevm_labels')
    op.drop_index(op.f('ix_imx_zkevm_labels_label_type'), table_name='imx_zkevm_labels')
    op.drop_index(op.f('ix_imx_zkevm_labels_label_name'), table_name='imx_zkevm_labels')
    op.drop_index(op.f('ix_imx_zkevm_labels_label'), table_name='imx_zkevm_labels')
    op.drop_index(op.f('ix_imx_zkevm_labels_caller_address'), table_name='imx_zkevm_labels')
    op.drop_index(op.f('ix_imx_zkevm_labels_block_number'), table_name='imx_zkevm_labels')
    op.drop_index(op.f('ix_imx_zkevm_labels_address'), table_name='imx_zkevm_labels')
    op.drop_index('ix_imx_zkevm_labels_addr_block_ts', table_name='imx_zkevm_labels')
    op.drop_index('ix_imx_zkevm_labels_addr_block_num', table_name='imx_zkevm_labels')
    op.drop_table('imx_zkevm_labels')
    # ### end Alembic commands ###
