Immutable zkEvm with it's sepolia migration for indexes

pull/1112/head
kompotkot 2024-07-25 11:35:45 +00:00
rodzic 6deae0e967
commit 484722bd96
3 zmienionych plików z 312 dodań i 1 usunięć

Wyświetl plik

@ -0,0 +1,198 @@
"""Immutable zkEvm with it's sepolia blockchains
Revision ID: f19652e59bc5
Revises: a1ead76c0470
Create Date: 2024-07-25 11:34:09.513131
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision: str = 'f19652e59bc5'
down_revision: Union[str, None] = 'a1ead76c0470'
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_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('indexed_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False),
sa.PrimaryKeyConstraint('block_number', name=op.f('pk_imx_zkevm_blocks'))
)
op.create_index(op.f('ix_imx_zkevm_blocks_block_number'), 'imx_zkevm_blocks', ['block_number'], unique=False)
op.create_index(op.f('ix_imx_zkevm_blocks_block_timestamp'), 'imx_zkevm_blocks', ['block_timestamp'], unique=False)
op.create_table('imx_zkevm_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_imx_zkevm_reorgs'))
)
op.create_index(op.f('ix_imx_zkevm_reorgs_block_hash'), 'imx_zkevm_reorgs', ['block_hash'], unique=False)
op.create_index(op.f('ix_imx_zkevm_reorgs_block_number'), 'imx_zkevm_reorgs', ['block_number'], unique=False)
op.create_table('imx_zkevm_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('indexed_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False),
sa.PrimaryKeyConstraint('block_number', name=op.f('pk_imx_zkevm_sepolia_blocks'))
)
op.create_index(op.f('ix_imx_zkevm_sepolia_blocks_block_number'), 'imx_zkevm_sepolia_blocks', ['block_number'], unique=False)
op.create_index(op.f('ix_imx_zkevm_sepolia_blocks_block_timestamp'), 'imx_zkevm_sepolia_blocks', ['block_timestamp'], unique=False)
op.create_table('imx_zkevm_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_imx_zkevm_sepolia_reorgs'))
)
op.create_index(op.f('ix_imx_zkevm_sepolia_reorgs_block_hash'), 'imx_zkevm_sepolia_reorgs', ['block_hash'], unique=False)
op.create_index(op.f('ix_imx_zkevm_sepolia_reorgs_block_number'), 'imx_zkevm_sepolia_reorgs', ['block_number'], unique=False)
op.create_table('imx_zkevm_sepolia_transactions',
sa.Column('block_number', sa.BigInteger(), nullable=False),
sa.Column('hash', sa.VARCHAR(length=256), nullable=False),
sa.Column('from_address', sa.LargeBinary(length=20), nullable=False),
sa.Column('to_address', sa.LargeBinary(length=20), nullable=False),
sa.Column('selector', sa.VARCHAR(length=256), nullable=True),
sa.Column('type', sa.Integer(), nullable=True),
sa.Column('row_id', sa.BigInteger(), nullable=False),
sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False),
sa.Column('index', sa.BigInteger(), nullable=False),
sa.Column('path', sa.Text(), nullable=False),
sa.Column('indexed_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False),
sa.ForeignKeyConstraint(['block_number'], ['imx_zkevm_sepolia_blocks.block_number'], name=op.f('fk_imx_zkevm_sepolia_transactions_block_number_imx_zkevm_sepolia_blocks'), ondelete='CASCADE'),
sa.PrimaryKeyConstraint('hash', name=op.f('pk_imx_zkevm_sepolia_transactions'))
)
op.create_index(op.f('ix_imx_zkevm_sepolia_transactions_block_hash'), 'imx_zkevm_sepolia_transactions', ['block_hash'], unique=False)
op.create_index(op.f('ix_imx_zkevm_sepolia_transactions_block_number'), 'imx_zkevm_sepolia_transactions', ['block_number'], unique=False)
op.create_index(op.f('ix_imx_zkevm_sepolia_transactions_from_address'), 'imx_zkevm_sepolia_transactions', ['from_address'], unique=False)
op.create_index(op.f('ix_imx_zkevm_sepolia_transactions_hash'), 'imx_zkevm_sepolia_transactions', ['hash'], unique=True)
op.create_index(op.f('ix_imx_zkevm_sepolia_transactions_index'), 'imx_zkevm_sepolia_transactions', ['index'], unique=False)
op.create_index(op.f('ix_imx_zkevm_sepolia_transactions_selector'), 'imx_zkevm_sepolia_transactions', ['selector'], unique=False)
op.create_index(op.f('ix_imx_zkevm_sepolia_transactions_to_address'), 'imx_zkevm_sepolia_transactions', ['to_address'], unique=False)
op.create_index(op.f('ix_imx_zkevm_sepolia_transactions_type'), 'imx_zkevm_sepolia_transactions', ['type'], unique=False)
op.create_table('imx_zkevm_transactions',
sa.Column('block_number', sa.BigInteger(), nullable=False),
sa.Column('hash', sa.VARCHAR(length=256), nullable=False),
sa.Column('from_address', sa.LargeBinary(length=20), nullable=False),
sa.Column('to_address', sa.LargeBinary(length=20), nullable=False),
sa.Column('selector', sa.VARCHAR(length=256), nullable=True),
sa.Column('type', sa.Integer(), nullable=True),
sa.Column('row_id', sa.BigInteger(), nullable=False),
sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False),
sa.Column('index', sa.BigInteger(), nullable=False),
sa.Column('path', sa.Text(), nullable=False),
sa.Column('indexed_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False),
sa.ForeignKeyConstraint(['block_number'], ['imx_zkevm_blocks.block_number'], name=op.f('fk_imx_zkevm_transactions_block_number_imx_zkevm_blocks'), ondelete='CASCADE'),
sa.PrimaryKeyConstraint('hash', name=op.f('pk_imx_zkevm_transactions'))
)
op.create_index(op.f('ix_imx_zkevm_transactions_block_hash'), 'imx_zkevm_transactions', ['block_hash'], unique=False)
op.create_index(op.f('ix_imx_zkevm_transactions_block_number'), 'imx_zkevm_transactions', ['block_number'], unique=False)
op.create_index(op.f('ix_imx_zkevm_transactions_from_address'), 'imx_zkevm_transactions', ['from_address'], unique=False)
op.create_index(op.f('ix_imx_zkevm_transactions_hash'), 'imx_zkevm_transactions', ['hash'], unique=True)
op.create_index(op.f('ix_imx_zkevm_transactions_index'), 'imx_zkevm_transactions', ['index'], unique=False)
op.create_index(op.f('ix_imx_zkevm_transactions_selector'), 'imx_zkevm_transactions', ['selector'], unique=False)
op.create_index(op.f('ix_imx_zkevm_transactions_to_address'), 'imx_zkevm_transactions', ['to_address'], unique=False)
op.create_index(op.f('ix_imx_zkevm_transactions_type'), 'imx_zkevm_transactions', ['type'], unique=False)
op.create_table('imx_zkevm_logs',
sa.Column('transaction_hash', sa.VARCHAR(length=256), nullable=False),
sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False),
sa.Column('address', sa.LargeBinary(length=20), nullable=False),
sa.Column('row_id', sa.BigInteger(), nullable=False),
sa.Column('selector', sa.VARCHAR(length=256), nullable=True),
sa.Column('topic1', sa.VARCHAR(length=256), nullable=True),
sa.Column('topic2', sa.VARCHAR(length=256), nullable=True),
sa.Column('topic3', sa.VARCHAR(length=256), nullable=True),
sa.Column('log_index', sa.BigInteger(), nullable=False),
sa.Column('path', sa.Text(), nullable=False),
sa.Column('indexed_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False),
sa.ForeignKeyConstraint(['transaction_hash'], ['imx_zkevm_transactions.hash'], name=op.f('fk_imx_zkevm_logs_transaction_hash_imx_zkevm_transactions'), ondelete='CASCADE'),
sa.PrimaryKeyConstraint('transaction_hash', 'log_index', name='pk_imx_zkevm_log_index'),
sa.UniqueConstraint('transaction_hash', 'log_index', name='uq_imx_zkevm_log_index_transaction_hash_log_index')
)
op.create_index('idx_imx_zkevm_logs_address_selector', 'imx_zkevm_logs', ['address', 'selector'], unique=False)
op.create_index('idx_imx_zkevm_logs_block_hash_log_index', 'imx_zkevm_logs', ['block_hash', 'log_index'], unique=True)
op.create_index(op.f('ix_imx_zkevm_logs_address'), 'imx_zkevm_logs', ['address'], unique=False)
op.create_index(op.f('ix_imx_zkevm_logs_block_hash'), 'imx_zkevm_logs', ['block_hash'], unique=False)
op.create_index(op.f('ix_imx_zkevm_logs_transaction_hash'), 'imx_zkevm_logs', ['transaction_hash'], unique=False)
op.create_table('imx_zkevm_sepolia_logs',
sa.Column('transaction_hash', sa.VARCHAR(length=256), nullable=False),
sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False),
sa.Column('address', sa.LargeBinary(length=20), nullable=False),
sa.Column('row_id', sa.BigInteger(), nullable=False),
sa.Column('selector', sa.VARCHAR(length=256), nullable=True),
sa.Column('topic1', sa.VARCHAR(length=256), nullable=True),
sa.Column('topic2', sa.VARCHAR(length=256), nullable=True),
sa.Column('topic3', sa.VARCHAR(length=256), nullable=True),
sa.Column('log_index', sa.BigInteger(), nullable=False),
sa.Column('path', sa.Text(), nullable=False),
sa.Column('indexed_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False),
sa.ForeignKeyConstraint(['transaction_hash'], ['imx_zkevm_sepolia_transactions.hash'], name=op.f('fk_imx_zkevm_sepolia_logs_transaction_hash_imx_zkevm_sepolia_transactions'), ondelete='CASCADE'),
sa.PrimaryKeyConstraint('transaction_hash', 'log_index', name='pk_imx_zkevm_sepolia_log_index'),
sa.UniqueConstraint('transaction_hash', 'log_index', name='uq_imx_zkevm_sepolia_log_index_transaction_hash_log_index')
)
op.create_index('idx_imx_zkevm_sepolia_logs_address_selector', 'imx_zkevm_sepolia_logs', ['address', 'selector'], unique=False)
op.create_index('idx_imx_zkevm_sepolia_logs_block_hash_log_index', 'imx_zkevm_sepolia_logs', ['block_hash', 'log_index'], unique=True)
op.create_index(op.f('ix_imx_zkevm_sepolia_logs_address'), 'imx_zkevm_sepolia_logs', ['address'], unique=False)
op.create_index(op.f('ix_imx_zkevm_sepolia_logs_block_hash'), 'imx_zkevm_sepolia_logs', ['block_hash'], unique=False)
op.create_index(op.f('ix_imx_zkevm_sepolia_logs_transaction_hash'), 'imx_zkevm_sepolia_logs', ['transaction_hash'], unique=False)
# ### end Alembic commands ###
def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(op.f('ix_imx_zkevm_sepolia_logs_transaction_hash'), table_name='imx_zkevm_sepolia_logs')
op.drop_index(op.f('ix_imx_zkevm_sepolia_logs_block_hash'), table_name='imx_zkevm_sepolia_logs')
op.drop_index(op.f('ix_imx_zkevm_sepolia_logs_address'), table_name='imx_zkevm_sepolia_logs')
op.drop_index('idx_imx_zkevm_sepolia_logs_block_hash_log_index', table_name='imx_zkevm_sepolia_logs')
op.drop_index('idx_imx_zkevm_sepolia_logs_address_selector', table_name='imx_zkevm_sepolia_logs')
op.drop_table('imx_zkevm_sepolia_logs')
op.drop_index(op.f('ix_imx_zkevm_logs_transaction_hash'), table_name='imx_zkevm_logs')
op.drop_index(op.f('ix_imx_zkevm_logs_block_hash'), table_name='imx_zkevm_logs')
op.drop_index(op.f('ix_imx_zkevm_logs_address'), table_name='imx_zkevm_logs')
op.drop_index('idx_imx_zkevm_logs_block_hash_log_index', table_name='imx_zkevm_logs')
op.drop_index('idx_imx_zkevm_logs_address_selector', table_name='imx_zkevm_logs')
op.drop_table('imx_zkevm_logs')
op.drop_index(op.f('ix_imx_zkevm_transactions_type'), table_name='imx_zkevm_transactions')
op.drop_index(op.f('ix_imx_zkevm_transactions_to_address'), table_name='imx_zkevm_transactions')
op.drop_index(op.f('ix_imx_zkevm_transactions_selector'), table_name='imx_zkevm_transactions')
op.drop_index(op.f('ix_imx_zkevm_transactions_index'), table_name='imx_zkevm_transactions')
op.drop_index(op.f('ix_imx_zkevm_transactions_hash'), table_name='imx_zkevm_transactions')
op.drop_index(op.f('ix_imx_zkevm_transactions_from_address'), table_name='imx_zkevm_transactions')
op.drop_index(op.f('ix_imx_zkevm_transactions_block_number'), table_name='imx_zkevm_transactions')
op.drop_index(op.f('ix_imx_zkevm_transactions_block_hash'), table_name='imx_zkevm_transactions')
op.drop_table('imx_zkevm_transactions')
op.drop_index(op.f('ix_imx_zkevm_sepolia_transactions_type'), table_name='imx_zkevm_sepolia_transactions')
op.drop_index(op.f('ix_imx_zkevm_sepolia_transactions_to_address'), table_name='imx_zkevm_sepolia_transactions')
op.drop_index(op.f('ix_imx_zkevm_sepolia_transactions_selector'), table_name='imx_zkevm_sepolia_transactions')
op.drop_index(op.f('ix_imx_zkevm_sepolia_transactions_index'), table_name='imx_zkevm_sepolia_transactions')
op.drop_index(op.f('ix_imx_zkevm_sepolia_transactions_hash'), table_name='imx_zkevm_sepolia_transactions')
op.drop_index(op.f('ix_imx_zkevm_sepolia_transactions_from_address'), table_name='imx_zkevm_sepolia_transactions')
op.drop_index(op.f('ix_imx_zkevm_sepolia_transactions_block_number'), table_name='imx_zkevm_sepolia_transactions')
op.drop_index(op.f('ix_imx_zkevm_sepolia_transactions_block_hash'), table_name='imx_zkevm_sepolia_transactions')
op.drop_table('imx_zkevm_sepolia_transactions')
op.drop_index(op.f('ix_imx_zkevm_sepolia_reorgs_block_number'), table_name='imx_zkevm_sepolia_reorgs')
op.drop_index(op.f('ix_imx_zkevm_sepolia_reorgs_block_hash'), table_name='imx_zkevm_sepolia_reorgs')
op.drop_table('imx_zkevm_sepolia_reorgs')
op.drop_index(op.f('ix_imx_zkevm_sepolia_blocks_block_timestamp'), table_name='imx_zkevm_sepolia_blocks')
op.drop_index(op.f('ix_imx_zkevm_sepolia_blocks_block_number'), table_name='imx_zkevm_sepolia_blocks')
op.drop_table('imx_zkevm_sepolia_blocks')
op.drop_index(op.f('ix_imx_zkevm_reorgs_block_number'), table_name='imx_zkevm_reorgs')
op.drop_index(op.f('ix_imx_zkevm_reorgs_block_hash'), table_name='imx_zkevm_reorgs')
op.drop_table('imx_zkevm_reorgs')
op.drop_index(op.f('ix_imx_zkevm_blocks_block_timestamp'), table_name='imx_zkevm_blocks')
op.drop_index(op.f('ix_imx_zkevm_blocks_block_number'), table_name='imx_zkevm_blocks')
op.drop_table('imx_zkevm_blocks')
# ### end Alembic commands ###

Wyświetl plik

@ -153,6 +153,9 @@ class EthereumReorgs(EvmBasedReorgs):
__tablename__ = "ethereum_reorgs"
### Sepolia
class SepoliaBlockIndex(EvmBasedBlocks):
__tablename__ = "sepolia_blocks"
@ -612,6 +615,116 @@ class MantleSepoliaReorgs(EvmBasedReorgs):
__tablename__ = "mantle_sepolia_reorgs"
### Immutable zkEvm
class ImxZkevmBlockIndex(EvmBasedBlocks):
__tablename__ = "imx_zkevm_blocks"
class ImxZkevmTransactionIndex(EvmBasedTransactions):
__tablename__ = "imx_zkevm_transactions"
block_number = Column(
BigInteger,
ForeignKey("imx_zkevm_blocks.block_number", ondelete="CASCADE"),
nullable=False,
index=True,
)
class ImxZkevmLogIndex(EvmBasedLogs):
__tablename__ = "imx_zkevm_logs"
__table_args__ = (
Index(
"idx_imx_zkevm_logs_address_selector",
"address",
"selector",
unique=False,
),
Index(
"idx_imx_zkevm_logs_block_hash_log_index",
"block_hash",
"log_index",
unique=True,
),
UniqueConstraint(
"transaction_hash",
"log_index",
name="uq_imx_zkevm_log_index_transaction_hash_log_index",
),
PrimaryKeyConstraint(
"transaction_hash", "log_index", name="pk_imx_zkevm_log_index"
),
)
transaction_hash = Column(
VARCHAR(256),
ForeignKey("imx_zkevm_transactions.hash", ondelete="CASCADE"),
nullable=False,
index=True,
)
class ImxZkevmReorgs(EvmBasedReorgs):
__tablename__ = "imx_zkevm_reorgs"
### Immutable zkEvm Sepolia
class ImxZkevmSepoliaBlockIndex(EvmBasedBlocks):
__tablename__ = "imx_zkevm_sepolia_blocks"
class ImxZkevmSepoliaTransactionIndex(EvmBasedTransactions):
__tablename__ = "imx_zkevm_sepolia_transactions"
block_number = Column(
BigInteger,
ForeignKey("imx_zkevm_sepolia_blocks.block_number", ondelete="CASCADE"),
nullable=False,
index=True,
)
class ImxZkevmSepoliaLogIndex(EvmBasedLogs):
__tablename__ = "imx_zkevm_sepolia_logs"
__table_args__ = (
Index(
"idx_imx_zkevm_sepolia_logs_address_selector",
"address",
"selector",
unique=False,
),
Index(
"idx_imx_zkevm_sepolia_logs_block_hash_log_index",
"block_hash",
"log_index",
unique=True,
),
UniqueConstraint(
"transaction_hash",
"log_index",
name="uq_imx_zkevm_sepolia_log_index_transaction_hash_log_index",
),
PrimaryKeyConstraint(
"transaction_hash", "log_index", name="pk_imx_zkevm_sepolia_log_index"
),
)
transaction_hash = Column(
VARCHAR(256),
ForeignKey("imx_zkevm_sepolia_transactions.hash", ondelete="CASCADE"),
nullable=False,
index=True,
)
class ImxZkevmSepoliaReorgs(EvmBasedReorgs):
__tablename__ = "imx_zkevm_sepolia_reorgs"
### ABI Jobs

Wyświetl plik

@ -1 +1 @@
0.0.14
0.0.15