"""add-b3

Revision ID: 25b339f55f8f
Revises: 48d2562504d1
Create Date: 2024-09-11 13:58:54.884367

"""

from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = "25b339f55f8f"
down_revision: Union[str, None] = "48d2562504d1"
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(
        "b3_blocks",
        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("parent_hash", sa.VARCHAR(length=256), nullable=False),
        sa.Column("row_id", sa.BigInteger(), nullable=False),
        sa.Column("path", sa.Text(), nullable=False),
        sa.Column("transactions_indexed_at", sa.DateTime(timezone=True), nullable=True),
        sa.Column("logs_indexed_at", sa.DateTime(timezone=True), nullable=True),
        sa.Column(
            "indexed_at",
            sa.DateTime(timezone=True),
            server_default=sa.text("TIMEZONE('utc', statement_timestamp())"),
            nullable=False,
        ),
        sa.PrimaryKeyConstraint("block_number", name=op.f("pk_b3_blocks")),
    )
    op.create_index(
        op.f("ix_b3_blocks_block_number"), "b3_blocks", ["block_number"], unique=False
    )
    op.create_index(
        op.f("ix_b3_blocks_block_timestamp"),
        "b3_blocks",
        ["block_timestamp"],
        unique=False,
    )
    op.create_table(
        "b3_reorgs",
        sa.Column("id", sa.UUID(), nullable=False),
        sa.Column("block_number", sa.BigInteger(), nullable=False),
        sa.Column("block_hash", sa.VARCHAR(length=256), nullable=False),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_b3_reorgs")),
    )
    op.create_index(
        op.f("ix_b3_reorgs_block_hash"), "b3_reorgs", ["block_hash"], unique=False
    )
    op.create_index(
        op.f("ix_b3_reorgs_block_number"), "b3_reorgs", ["block_number"], unique=False
    )
    op.create_table(
        "b3_sepolia_blocks",
        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("parent_hash", sa.VARCHAR(length=256), nullable=False),
        sa.Column("row_id", sa.BigInteger(), nullable=False),
        sa.Column("path", sa.Text(), nullable=False),
        sa.Column("transactions_indexed_at", sa.DateTime(timezone=True), nullable=True),
        sa.Column("logs_indexed_at", sa.DateTime(timezone=True), nullable=True),
        sa.Column(
            "indexed_at",
            sa.DateTime(timezone=True),
            server_default=sa.text("TIMEZONE('utc', statement_timestamp())"),
            nullable=False,
        ),
        sa.PrimaryKeyConstraint("block_number", name=op.f("pk_b3_sepolia_blocks")),
    )
    op.create_index(
        op.f("ix_b3_sepolia_blocks_block_number"),
        "b3_sepolia_blocks",
        ["block_number"],
        unique=False,
    )
    op.create_index(
        op.f("ix_b3_sepolia_blocks_block_timestamp"),
        "b3_sepolia_blocks",
        ["block_timestamp"],
        unique=False,
    )
    op.create_table(
        "b3_sepolia_reorgs",
        sa.Column("id", sa.UUID(), nullable=False),
        sa.Column("block_number", sa.BigInteger(), nullable=False),
        sa.Column("block_hash", sa.VARCHAR(length=256), nullable=False),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_b3_sepolia_reorgs")),
    )
    op.create_index(
        op.f("ix_b3_sepolia_reorgs_block_hash"),
        "b3_sepolia_reorgs",
        ["block_hash"],
        unique=False,
    )
    op.create_index(
        op.f("ix_b3_sepolia_reorgs_block_number"),
        "b3_sepolia_reorgs",
        ["block_number"],
        unique=False,
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###

    op.drop_index(
        op.f("ix_b3_sepolia_reorgs_block_number"), table_name="b3_sepolia_reorgs"
    )
    op.drop_index(
        op.f("ix_b3_sepolia_reorgs_block_hash"), table_name="b3_sepolia_reorgs"
    )
    op.drop_table("b3_sepolia_reorgs")
    op.drop_index(
        op.f("ix_b3_sepolia_blocks_block_timestamp"), table_name="b3_sepolia_blocks"
    )
    op.drop_index(
        op.f("ix_b3_sepolia_blocks_block_number"), table_name="b3_sepolia_blocks"
    )
    op.drop_table("b3_sepolia_blocks")
    op.drop_index(op.f("ix_b3_reorgs_block_number"), table_name="b3_reorgs")
    op.drop_index(op.f("ix_b3_reorgs_block_hash"), table_name="b3_reorgs")
    op.drop_table("b3_reorgs")
    op.drop_index(op.f("ix_b3_blocks_block_timestamp"), table_name="b3_blocks")
    op.drop_index(op.f("ix_b3_blocks_block_number"), table_name="b3_blocks")
    op.drop_table("b3_blocks")
    # ### end Alembic commands ###
