kopia lustrzana https://github.com/bugout-dev/moonstream
Add initial version of v3 index db structure.
rodzic
7e346cc2ce
commit
19944c124f
|
@ -1,116 +0,0 @@
|
||||||
# A generic, single database configuration.
|
|
||||||
|
|
||||||
[alembic]
|
|
||||||
# path to migration scripts
|
|
||||||
script_location = moonstreamdbv3/alembic_indexes
|
|
||||||
|
|
||||||
# template used to generate migration file names; The default value is %%(rev)s_%%(slug)s
|
|
||||||
# Uncomment the line below if you want the files to be prepended with date and time
|
|
||||||
# see https://alembic.sqlalchemy.org/en/latest/tutorial.html#editing-the-ini-file
|
|
||||||
# for all available tokens
|
|
||||||
# file_template = %%(year)d_%%(month).2d_%%(day).2d_%%(hour).2d%%(minute).2d-%%(rev)s_%%(slug)s
|
|
||||||
|
|
||||||
# sys.path path, will be prepended to sys.path if present.
|
|
||||||
# defaults to the current working directory.
|
|
||||||
prepend_sys_path = .
|
|
||||||
|
|
||||||
# timezone to use when rendering the date within the migration file
|
|
||||||
# as well as the filename.
|
|
||||||
# If specified, requires the python>=3.9 or backports.zoneinfo library.
|
|
||||||
# Any required deps can installed by adding `alembic[tz]` to the pip requirements
|
|
||||||
# string value is passed to ZoneInfo()
|
|
||||||
# leave blank for localtime
|
|
||||||
# timezone =
|
|
||||||
|
|
||||||
# max length of characters to apply to the
|
|
||||||
# "slug" field
|
|
||||||
# truncate_slug_length = 40
|
|
||||||
|
|
||||||
# set to 'true' to run the environment during
|
|
||||||
# the 'revision' command, regardless of autogenerate
|
|
||||||
# revision_environment = false
|
|
||||||
|
|
||||||
# set to 'true' to allow .pyc and .pyo files without
|
|
||||||
# a source .py file to be detected as revisions in the
|
|
||||||
# versions/ directory
|
|
||||||
# sourceless = false
|
|
||||||
|
|
||||||
# version location specification; This defaults
|
|
||||||
# to moonstreamdbv3/alembic_indexes/versions. When using multiple version
|
|
||||||
# directories, initial revisions must be specified with --version-path.
|
|
||||||
# The path separator used here should be the separator specified by "version_path_separator" below.
|
|
||||||
# version_locations = %(here)s/bar:%(here)s/bat:moonstreamdbv3/alembic_indexes/versions
|
|
||||||
|
|
||||||
# version path separator; As mentioned above, this is the character used to split
|
|
||||||
# version_locations. The default within new alembic.ini files is "os", which uses os.pathsep.
|
|
||||||
# If this key is omitted entirely, it falls back to the legacy behavior of splitting on spaces and/or commas.
|
|
||||||
# Valid values for version_path_separator are:
|
|
||||||
#
|
|
||||||
# version_path_separator = :
|
|
||||||
# version_path_separator = ;
|
|
||||||
# version_path_separator = space
|
|
||||||
version_path_separator = os # Use os.pathsep. Default configuration used for new projects.
|
|
||||||
|
|
||||||
# set to 'true' to search source files recursively
|
|
||||||
# in each "version_locations" directory
|
|
||||||
# new in Alembic version 1.10
|
|
||||||
# recursive_version_locations = false
|
|
||||||
|
|
||||||
# the output encoding used when revision files
|
|
||||||
# are written from script.py.mako
|
|
||||||
# output_encoding = utf-8
|
|
||||||
|
|
||||||
sqlalchemy.url = driver://user:pass@localhost/dbname_indexes
|
|
||||||
|
|
||||||
|
|
||||||
[post_write_hooks]
|
|
||||||
# post_write_hooks defines scripts or Python functions that are run
|
|
||||||
# on newly generated revision scripts. See the documentation for further
|
|
||||||
# detail and examples
|
|
||||||
|
|
||||||
# format using "black" - use the console_scripts runner, against the "black" entrypoint
|
|
||||||
# hooks = black
|
|
||||||
# black.type = console_scripts
|
|
||||||
# black.entrypoint = black
|
|
||||||
# black.options = -l 79 REVISION_SCRIPT_FILENAME
|
|
||||||
|
|
||||||
# lint with attempts to fix using "ruff" - use the exec runner, execute a binary
|
|
||||||
# hooks = ruff
|
|
||||||
# ruff.type = exec
|
|
||||||
# ruff.executable = %(here)s/.venv/bin/ruff
|
|
||||||
# ruff.options = --fix REVISION_SCRIPT_FILENAME
|
|
||||||
|
|
||||||
# Logging configuration
|
|
||||||
[loggers]
|
|
||||||
keys = root,sqlalchemy,alembic
|
|
||||||
|
|
||||||
[handlers]
|
|
||||||
keys = console
|
|
||||||
|
|
||||||
[formatters]
|
|
||||||
keys = generic
|
|
||||||
|
|
||||||
[logger_root]
|
|
||||||
level = WARN
|
|
||||||
handlers = console
|
|
||||||
qualname =
|
|
||||||
|
|
||||||
[logger_sqlalchemy]
|
|
||||||
level = WARN
|
|
||||||
handlers =
|
|
||||||
qualname = sqlalchemy.engine
|
|
||||||
|
|
||||||
[logger_alembic]
|
|
||||||
level = INFO
|
|
||||||
handlers =
|
|
||||||
qualname = alembic
|
|
||||||
|
|
||||||
[handler_console]
|
|
||||||
class = StreamHandler
|
|
||||||
args = (sys.stderr,)
|
|
||||||
level = NOTSET
|
|
||||||
formatter = generic
|
|
||||||
|
|
||||||
[formatter_generic]
|
|
||||||
format = %(levelname)-5.5s [%(name)s] %(message)s
|
|
||||||
datefmt = %H:%M:%S
|
|
|
@ -28,14 +28,30 @@ target_metadata = MoonstreamBase.metadata
|
||||||
# ... etc.
|
# ... etc.
|
||||||
|
|
||||||
from moonstreamdbv3.models_indexes import (
|
from moonstreamdbv3.models_indexes import (
|
||||||
EvmBasedBlocks,
|
EthereumBlockIndex,
|
||||||
|
EthereumTransactionIndex,
|
||||||
|
EthereumLogIndex,
|
||||||
|
EthereumReorgs,
|
||||||
|
PolygonBlockIndex,
|
||||||
|
PolygonTransactionIndex,
|
||||||
|
PolygonLogIndex,
|
||||||
|
PolygonReorgs,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def include_symbol(tablename, schema):
|
def include_symbol(tablename, schema):
|
||||||
return tablename in {
|
return tablename in {
|
||||||
EvmBasedBlocks.__tablename__,
|
EthereumBlockIndex.__tablename__,
|
||||||
|
EthereumTransactionIndex.__tablename__,
|
||||||
|
EthereumLogIndex.__tablename__,
|
||||||
|
EthereumReorgs.__tablename__,
|
||||||
|
PolygonBlockIndex.__tablename__,
|
||||||
|
PolygonTransactionIndex.__tablename__,
|
||||||
|
PolygonLogIndex.__tablename__,
|
||||||
|
PolygonReorgs.__tablename__,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def run_migrations_offline() -> None:
|
def run_migrations_offline() -> None:
|
||||||
"""Run migrations in 'offline' mode.
|
"""Run migrations in 'offline' mode.
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,225 @@
|
||||||
|
"""init-v3-index
|
||||||
|
|
||||||
|
Revision ID: 5fe77896ce1f
|
||||||
|
Revises:
|
||||||
|
Create Date: 2024-05-23 17:13:54.485718
|
||||||
|
|
||||||
|
"""
|
||||||
|
from typing import Sequence, Union
|
||||||
|
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision: str = '5fe77896ce1f'
|
||||||
|
down_revision: Union[str, None] = None
|
||||||
|
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('abi_jobs',
|
||||||
|
sa.Column('id', sa.UUID(), nullable=False),
|
||||||
|
sa.Column('address', sa.LargeBinary(), nullable=False),
|
||||||
|
sa.Column('user_id', sa.UUID(), nullable=False),
|
||||||
|
sa.Column('customer_id', sa.UUID(), nullable=True),
|
||||||
|
sa.Column('abi_selector', sa.VARCHAR(length=256), nullable=False),
|
||||||
|
sa.Column('chain', sa.VARCHAR(length=256), nullable=False),
|
||||||
|
sa.Column('abi_name', sa.VARCHAR(length=256), nullable=False),
|
||||||
|
sa.Column('status', sa.VARCHAR(length=256), nullable=False),
|
||||||
|
sa.Column('historical_crawl_status', sa.VARCHAR(length=256), nullable=False),
|
||||||
|
sa.Column('progress', sa.Integer(), nullable=False),
|
||||||
|
sa.Column('moonworm_task_pickedup', sa.Boolean(), nullable=False),
|
||||||
|
sa.Column('abi', sa.Text(), nullable=False),
|
||||||
|
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False),
|
||||||
|
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False),
|
||||||
|
sa.PrimaryKeyConstraint('id', name=op.f('pk_abi_jobs')),
|
||||||
|
sa.UniqueConstraint('chain', 'address', 'abi_selector', 'customer_id', name='uq_abi_jobs')
|
||||||
|
)
|
||||||
|
op.create_index(op.f('ix_abi_jobs_abi_name'), 'abi_jobs', ['abi_name'], unique=False)
|
||||||
|
op.create_index(op.f('ix_abi_jobs_abi_selector'), 'abi_jobs', ['abi_selector'], unique=False)
|
||||||
|
op.create_index(op.f('ix_abi_jobs_address'), 'abi_jobs', ['address'], unique=False)
|
||||||
|
op.create_index(op.f('ix_abi_jobs_chain'), 'abi_jobs', ['chain'], unique=False)
|
||||||
|
op.create_index(op.f('ix_abi_jobs_customer_id'), 'abi_jobs', ['customer_id'], unique=False)
|
||||||
|
op.create_index(op.f('ix_abi_jobs_historical_crawl_status'), 'abi_jobs', ['historical_crawl_status'], unique=False)
|
||||||
|
op.create_index(op.f('ix_abi_jobs_status'), 'abi_jobs', ['status'], unique=False)
|
||||||
|
op.create_index(op.f('ix_abi_jobs_user_id'), 'abi_jobs', ['user_id'], unique=False)
|
||||||
|
op.create_table('ethereum_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_ethereum_blocks'))
|
||||||
|
)
|
||||||
|
op.create_index(op.f('ix_ethereum_blocks_block_number'), 'ethereum_blocks', ['block_number'], unique=False)
|
||||||
|
op.create_index(op.f('ix_ethereum_blocks_block_timestamp'), 'ethereum_blocks', ['block_timestamp'], unique=False)
|
||||||
|
op.create_table('ethereum_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_ethereum_reorgs'))
|
||||||
|
)
|
||||||
|
op.create_index(op.f('ix_ethereum_reorgs_block_hash'), 'ethereum_reorgs', ['block_hash'], unique=False)
|
||||||
|
op.create_index(op.f('ix_ethereum_reorgs_block_number'), 'ethereum_reorgs', ['block_number'], unique=False)
|
||||||
|
op.create_table('polygon_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_polygon_blocks'))
|
||||||
|
)
|
||||||
|
op.create_index(op.f('ix_polygon_blocks_block_number'), 'polygon_blocks', ['block_number'], unique=False)
|
||||||
|
op.create_index(op.f('ix_polygon_blocks_block_timestamp'), 'polygon_blocks', ['block_timestamp'], unique=False)
|
||||||
|
op.create_table('polygon_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_polygon_reorgs'))
|
||||||
|
)
|
||||||
|
op.create_index(op.f('ix_polygon_reorgs_block_hash'), 'polygon_reorgs', ['block_hash'], unique=False)
|
||||||
|
op.create_index(op.f('ix_polygon_reorgs_block_number'), 'polygon_reorgs', ['block_number'], unique=False)
|
||||||
|
op.create_table('ethereum_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=False),
|
||||||
|
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'], ['ethereum_blocks.block_number'], name=op.f('fk_ethereum_transactions_block_number_ethereum_blocks'), ondelete='CASCADE'),
|
||||||
|
sa.PrimaryKeyConstraint('hash', name=op.f('pk_ethereum_transactions'))
|
||||||
|
)
|
||||||
|
op.create_index(op.f('ix_ethereum_transactions_block_hash'), 'ethereum_transactions', ['block_hash'], unique=False)
|
||||||
|
op.create_index(op.f('ix_ethereum_transactions_block_number'), 'ethereum_transactions', ['block_number'], unique=False)
|
||||||
|
op.create_index(op.f('ix_ethereum_transactions_from_address'), 'ethereum_transactions', ['from_address'], unique=False)
|
||||||
|
op.create_index(op.f('ix_ethereum_transactions_hash'), 'ethereum_transactions', ['hash'], unique=True)
|
||||||
|
op.create_index(op.f('ix_ethereum_transactions_index'), 'ethereum_transactions', ['index'], unique=False)
|
||||||
|
op.create_index(op.f('ix_ethereum_transactions_selector'), 'ethereum_transactions', ['selector'], unique=False)
|
||||||
|
op.create_index(op.f('ix_ethereum_transactions_to_address'), 'ethereum_transactions', ['to_address'], unique=False)
|
||||||
|
op.create_index(op.f('ix_ethereum_transactions_type'), 'ethereum_transactions', ['type'], unique=False)
|
||||||
|
op.create_table('polygon_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=False),
|
||||||
|
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'], ['polygon_blocks.block_number'], name=op.f('fk_polygon_transactions_block_number_polygon_blocks'), ondelete='CASCADE'),
|
||||||
|
sa.PrimaryKeyConstraint('hash', name=op.f('pk_polygon_transactions'))
|
||||||
|
)
|
||||||
|
op.create_index(op.f('ix_polygon_transactions_block_hash'), 'polygon_transactions', ['block_hash'], unique=False)
|
||||||
|
op.create_index(op.f('ix_polygon_transactions_block_number'), 'polygon_transactions', ['block_number'], unique=False)
|
||||||
|
op.create_index(op.f('ix_polygon_transactions_from_address'), 'polygon_transactions', ['from_address'], unique=False)
|
||||||
|
op.create_index(op.f('ix_polygon_transactions_hash'), 'polygon_transactions', ['hash'], unique=True)
|
||||||
|
op.create_index(op.f('ix_polygon_transactions_index'), 'polygon_transactions', ['index'], unique=False)
|
||||||
|
op.create_index(op.f('ix_polygon_transactions_selector'), 'polygon_transactions', ['selector'], unique=False)
|
||||||
|
op.create_index(op.f('ix_polygon_transactions_to_address'), 'polygon_transactions', ['to_address'], unique=False)
|
||||||
|
op.create_index(op.f('ix_polygon_transactions_type'), 'polygon_transactions', ['type'], unique=False)
|
||||||
|
op.create_table('ethereum_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('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'], ['ethereum_transactions.hash'], name=op.f('fk_ethereum_logs_transaction_hash_ethereum_transactions'), ondelete='CASCADE'),
|
||||||
|
sa.PrimaryKeyConstraint('transaction_hash', 'log_index', name='pk_ethereum_log_index'),
|
||||||
|
sa.UniqueConstraint('transaction_hash', 'log_index', name='uq_ethereum_log_index_transaction_hash_log_index')
|
||||||
|
)
|
||||||
|
op.create_index('idx_ethereum_logs_block_hash_log_index', 'ethereum_logs', ['block_hash', 'log_index'], unique=True)
|
||||||
|
op.create_index(op.f('ix_ethereum_logs_address'), 'ethereum_logs', ['address'], unique=False)
|
||||||
|
op.create_index(op.f('ix_ethereum_logs_block_hash'), 'ethereum_logs', ['block_hash'], unique=False)
|
||||||
|
op.create_index(op.f('ix_ethereum_logs_transaction_hash'), 'ethereum_logs', ['transaction_hash'], unique=False)
|
||||||
|
op.create_table('polygon_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('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'], ['polygon_transactions.hash'], name=op.f('fk_polygon_logs_transaction_hash_polygon_transactions'), ondelete='CASCADE'),
|
||||||
|
sa.PrimaryKeyConstraint('transaction_hash', 'log_index', name='pk_polygon_log_index'),
|
||||||
|
sa.UniqueConstraint('transaction_hash', 'log_index', name='uq_polygon_log_index_transaction_hash_log_index')
|
||||||
|
)
|
||||||
|
op.create_index(op.f('ix_polygon_logs_address'), 'polygon_logs', ['address'], unique=False)
|
||||||
|
op.create_index(op.f('ix_polygon_logs_block_hash'), 'polygon_logs', ['block_hash'], unique=False)
|
||||||
|
op.create_index(op.f('ix_polygon_logs_transaction_hash'), 'polygon_logs', ['transaction_hash'], unique=False)
|
||||||
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade() -> None:
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.drop_index(op.f('ix_polygon_logs_transaction_hash'), table_name='polygon_logs')
|
||||||
|
op.drop_index(op.f('ix_polygon_logs_block_hash'), table_name='polygon_logs')
|
||||||
|
op.drop_index(op.f('ix_polygon_logs_address'), table_name='polygon_logs')
|
||||||
|
op.drop_table('polygon_logs')
|
||||||
|
op.drop_index(op.f('ix_ethereum_logs_transaction_hash'), table_name='ethereum_logs')
|
||||||
|
op.drop_index(op.f('ix_ethereum_logs_block_hash'), table_name='ethereum_logs')
|
||||||
|
op.drop_index(op.f('ix_ethereum_logs_address'), table_name='ethereum_logs')
|
||||||
|
op.drop_index('idx_ethereum_logs_block_hash_log_index', table_name='ethereum_logs')
|
||||||
|
op.drop_table('ethereum_logs')
|
||||||
|
op.drop_index(op.f('ix_polygon_transactions_type'), table_name='polygon_transactions')
|
||||||
|
op.drop_index(op.f('ix_polygon_transactions_to_address'), table_name='polygon_transactions')
|
||||||
|
op.drop_index(op.f('ix_polygon_transactions_selector'), table_name='polygon_transactions')
|
||||||
|
op.drop_index(op.f('ix_polygon_transactions_index'), table_name='polygon_transactions')
|
||||||
|
op.drop_index(op.f('ix_polygon_transactions_hash'), table_name='polygon_transactions')
|
||||||
|
op.drop_index(op.f('ix_polygon_transactions_from_address'), table_name='polygon_transactions')
|
||||||
|
op.drop_index(op.f('ix_polygon_transactions_block_number'), table_name='polygon_transactions')
|
||||||
|
op.drop_index(op.f('ix_polygon_transactions_block_hash'), table_name='polygon_transactions')
|
||||||
|
op.drop_table('polygon_transactions')
|
||||||
|
op.drop_index(op.f('ix_ethereum_transactions_type'), table_name='ethereum_transactions')
|
||||||
|
op.drop_index(op.f('ix_ethereum_transactions_to_address'), table_name='ethereum_transactions')
|
||||||
|
op.drop_index(op.f('ix_ethereum_transactions_selector'), table_name='ethereum_transactions')
|
||||||
|
op.drop_index(op.f('ix_ethereum_transactions_index'), table_name='ethereum_transactions')
|
||||||
|
op.drop_index(op.f('ix_ethereum_transactions_hash'), table_name='ethereum_transactions')
|
||||||
|
op.drop_index(op.f('ix_ethereum_transactions_from_address'), table_name='ethereum_transactions')
|
||||||
|
op.drop_index(op.f('ix_ethereum_transactions_block_number'), table_name='ethereum_transactions')
|
||||||
|
op.drop_index(op.f('ix_ethereum_transactions_block_hash'), table_name='ethereum_transactions')
|
||||||
|
op.drop_table('ethereum_transactions')
|
||||||
|
op.drop_index(op.f('ix_polygon_reorgs_block_number'), table_name='polygon_reorgs')
|
||||||
|
op.drop_index(op.f('ix_polygon_reorgs_block_hash'), table_name='polygon_reorgs')
|
||||||
|
op.drop_table('polygon_reorgs')
|
||||||
|
op.drop_index(op.f('ix_polygon_blocks_block_timestamp'), table_name='polygon_blocks')
|
||||||
|
op.drop_index(op.f('ix_polygon_blocks_block_number'), table_name='polygon_blocks')
|
||||||
|
op.drop_table('polygon_blocks')
|
||||||
|
op.drop_index(op.f('ix_ethereum_reorgs_block_number'), table_name='ethereum_reorgs')
|
||||||
|
op.drop_index(op.f('ix_ethereum_reorgs_block_hash'), table_name='ethereum_reorgs')
|
||||||
|
op.drop_table('ethereum_reorgs')
|
||||||
|
op.drop_index(op.f('ix_ethereum_blocks_block_timestamp'), table_name='ethereum_blocks')
|
||||||
|
op.drop_index(op.f('ix_ethereum_blocks_block_number'), table_name='ethereum_blocks')
|
||||||
|
op.drop_table('ethereum_blocks')
|
||||||
|
op.drop_index(op.f('ix_abi_jobs_user_id'), table_name='abi_jobs')
|
||||||
|
op.drop_index(op.f('ix_abi_jobs_status'), table_name='abi_jobs')
|
||||||
|
op.drop_index(op.f('ix_abi_jobs_historical_crawl_status'), table_name='abi_jobs')
|
||||||
|
op.drop_index(op.f('ix_abi_jobs_customer_id'), table_name='abi_jobs')
|
||||||
|
op.drop_index(op.f('ix_abi_jobs_chain'), table_name='abi_jobs')
|
||||||
|
op.drop_index(op.f('ix_abi_jobs_address'), table_name='abi_jobs')
|
||||||
|
op.drop_index(op.f('ix_abi_jobs_abi_selector'), table_name='abi_jobs')
|
||||||
|
op.drop_index(op.f('ix_abi_jobs_abi_name'), table_name='abi_jobs')
|
||||||
|
op.drop_table('abi_jobs')
|
||||||
|
# ### end Alembic commands ###
|
|
@ -1,27 +1,29 @@
|
||||||
"""
|
|
||||||
Moonstream database V3 indexes
|
|
||||||
"""
|
|
||||||
|
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from sqlalchemy import (
|
from sqlalchemy import (
|
||||||
|
LargeBinary,
|
||||||
VARCHAR,
|
VARCHAR,
|
||||||
BigInteger,
|
BigInteger,
|
||||||
Column,
|
Column,
|
||||||
DateTime,
|
DateTime,
|
||||||
Index,
|
|
||||||
Integer,
|
Integer,
|
||||||
|
Index,
|
||||||
MetaData,
|
MetaData,
|
||||||
Text,
|
Text,
|
||||||
|
Boolean,
|
||||||
|
UniqueConstraint,
|
||||||
|
ForeignKey,
|
||||||
|
PrimaryKeyConstraint,
|
||||||
)
|
)
|
||||||
from sqlalchemy.dialects.postgresql import JSONB, UUID
|
from sqlalchemy.dialects.postgresql import UUID
|
||||||
from sqlalchemy.ext.compiler import compiles
|
from sqlalchemy.ext.compiler import compiles
|
||||||
from sqlalchemy.ext.declarative import declarative_base
|
from sqlalchemy.ext.declarative import declarative_base
|
||||||
from sqlalchemy.sql import expression, text
|
from sqlalchemy.sql import expression
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Naming conventions doc
|
Naming conventions doc
|
||||||
https://docs.sqlalchemy.org/en/20/core/constraints.html#configuring-constraint-naming-conventions
|
https://docs.sqlalchemy.org/en/13/core/constraints.html#configuring-constraint-naming-conventions
|
||||||
"""
|
"""
|
||||||
convention = {
|
convention = {
|
||||||
"ix": "ix_%(column_0_label)s",
|
"ix": "ix_%(column_0_label)s",
|
||||||
|
@ -33,15 +35,6 @@ convention = {
|
||||||
metadata = MetaData(naming_convention=convention)
|
metadata = MetaData(naming_convention=convention)
|
||||||
Base = declarative_base(metadata=metadata)
|
Base = declarative_base(metadata=metadata)
|
||||||
|
|
||||||
"""
|
|
||||||
Creating a utcnow function which runs on the Posgres database server when created_at and updated_at
|
|
||||||
fields are populated.
|
|
||||||
Following:
|
|
||||||
1. https://docs.sqlalchemy.org/en/13/core/compiler.html#utc-timestamp-function
|
|
||||||
2. https://www.postgresql.org/docs/current/functions-datetime.html#FUNCTIONS-DATETIME-CURRENT
|
|
||||||
3. https://stackoverflow.com/a/33532154/13659585
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
class utcnow(expression.FunctionElement):
|
class utcnow(expression.FunctionElement):
|
||||||
type = DateTime # type: ignore
|
type = DateTime # type: ignore
|
||||||
|
@ -59,7 +52,175 @@ class EvmBasedBlocks(Base):
|
||||||
block_hash = Column(VARCHAR(256), nullable=False, index=False)
|
block_hash = Column(VARCHAR(256), nullable=False, index=False)
|
||||||
block_timestamp = Column(BigInteger, nullable=False, index=True)
|
block_timestamp = Column(BigInteger, nullable=False, index=True)
|
||||||
parent_hash = Column(VARCHAR(256), nullable=False)
|
parent_hash = Column(VARCHAR(256), nullable=False)
|
||||||
|
row_id = Column(BigInteger, nullable=False, index=False)
|
||||||
path = Column(Text, nullable=False)
|
path = Column(Text, nullable=False)
|
||||||
indexed_at = Column(
|
indexed_at = Column(
|
||||||
DateTime(timezone=True), server_default=utcnow(), nullable=False
|
DateTime(timezone=True), server_default=utcnow(), nullable=False
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class EvmBasedTransactions(Base):
|
||||||
|
__abstract__ = True
|
||||||
|
|
||||||
|
hash = Column(
|
||||||
|
VARCHAR(256), primary_key=True, unique=True, nullable=False, index=True
|
||||||
|
)
|
||||||
|
from_address = Column(LargeBinary(length=20), nullable=False, index=True)
|
||||||
|
to_address = Column(LargeBinary(length=20), nullable=False, index=True)
|
||||||
|
selector = Column(VARCHAR(256), nullable=True, index=True)
|
||||||
|
type = Column(Integer, nullable=False, index=True)
|
||||||
|
row_id = Column(BigInteger, nullable=False, index=False)
|
||||||
|
block_hash = Column(VARCHAR(256), nullable=False, index=True)
|
||||||
|
index = Column(BigInteger, nullable=False, index=True)
|
||||||
|
path = Column(Text, nullable=False)
|
||||||
|
indexed_at = Column(
|
||||||
|
DateTime(timezone=True), server_default=utcnow(), nullable=False
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class EvmBasedLogs(Base):
|
||||||
|
__abstract__ = True
|
||||||
|
|
||||||
|
block_hash = Column(VARCHAR(256), nullable=False, index=True)
|
||||||
|
address = Column(LargeBinary(length=20), nullable=False, index=True)
|
||||||
|
row_id = Column(BigInteger, nullable=False, index=False)
|
||||||
|
selector = Column(VARCHAR(256), nullable=True, index=False)
|
||||||
|
topic1 = Column(VARCHAR(256), nullable=True, index=False)
|
||||||
|
topic2 = Column(VARCHAR(256), nullable=True, index=False)
|
||||||
|
log_index = Column(BigInteger, nullable=False, index=False)
|
||||||
|
path = Column(Text, nullable=False)
|
||||||
|
indexed_at = Column(
|
||||||
|
DateTime(timezone=True), server_default=utcnow(), nullable=False
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class EvmBasedReorgs(Base):
|
||||||
|
__abstract__ = True
|
||||||
|
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||||
|
block_number = Column(BigInteger, nullable=False, index=True)
|
||||||
|
block_hash = Column(VARCHAR(256), nullable=False, index=True)
|
||||||
|
|
||||||
|
|
||||||
|
### Ethereum
|
||||||
|
|
||||||
|
|
||||||
|
class EthereumBlockIndex(EvmBasedBlocks):
|
||||||
|
__tablename__ = "ethereum_blocks"
|
||||||
|
|
||||||
|
|
||||||
|
class EthereumTransactionIndex(EvmBasedTransactions):
|
||||||
|
__tablename__ = "ethereum_transactions"
|
||||||
|
|
||||||
|
block_number = Column(
|
||||||
|
BigInteger,
|
||||||
|
ForeignKey("ethereum_blocks.block_number", ondelete="CASCADE"),
|
||||||
|
nullable=False,
|
||||||
|
index=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class EthereumLogIndex(EvmBasedLogs):
|
||||||
|
__tablename__ = "ethereum_logs"
|
||||||
|
|
||||||
|
__table_args__ = (
|
||||||
|
Index(
|
||||||
|
"idx_ethereum_logs_block_hash_log_index",
|
||||||
|
"block_hash",
|
||||||
|
"log_index",
|
||||||
|
unique=True,
|
||||||
|
),
|
||||||
|
UniqueConstraint(
|
||||||
|
"transaction_hash",
|
||||||
|
"log_index",
|
||||||
|
name="uq_ethereum_log_index_transaction_hash_log_index",
|
||||||
|
),
|
||||||
|
PrimaryKeyConstraint(
|
||||||
|
"transaction_hash", "log_index", name="pk_ethereum_log_index"
|
||||||
|
),
|
||||||
|
)
|
||||||
|
transaction_hash = Column(
|
||||||
|
VARCHAR(256),
|
||||||
|
ForeignKey("ethereum_transactions.hash", ondelete="CASCADE"),
|
||||||
|
nullable=False,
|
||||||
|
index=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class EthereumReorgs(EvmBasedReorgs):
|
||||||
|
__tablename__ = "ethereum_reorgs"
|
||||||
|
|
||||||
|
|
||||||
|
### Polygon
|
||||||
|
|
||||||
|
|
||||||
|
class PolygonBlockIndex(EvmBasedBlocks):
|
||||||
|
__tablename__ = "polygon_blocks"
|
||||||
|
|
||||||
|
|
||||||
|
class PolygonTransactionIndex(EvmBasedTransactions):
|
||||||
|
__tablename__ = "polygon_transactions"
|
||||||
|
|
||||||
|
block_number = Column(
|
||||||
|
BigInteger,
|
||||||
|
ForeignKey("polygon_blocks.block_number", ondelete="CASCADE"),
|
||||||
|
nullable=False,
|
||||||
|
index=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class PolygonLogIndex(EvmBasedLogs):
|
||||||
|
|
||||||
|
__tablename__ = "polygon_logs"
|
||||||
|
|
||||||
|
__table_args__ = (
|
||||||
|
UniqueConstraint(
|
||||||
|
"transaction_hash",
|
||||||
|
"log_index",
|
||||||
|
name="uq_polygon_log_index_transaction_hash_log_index",
|
||||||
|
),
|
||||||
|
PrimaryKeyConstraint(
|
||||||
|
"transaction_hash", "log_index", name="pk_polygon_log_index"
|
||||||
|
),
|
||||||
|
)
|
||||||
|
transaction_hash = Column(
|
||||||
|
VARCHAR(256),
|
||||||
|
ForeignKey("polygon_transactions.hash", ondelete="CASCADE"),
|
||||||
|
nullable=False,
|
||||||
|
index=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class PolygonReorgs(EvmBasedReorgs):
|
||||||
|
__tablename__ = "polygon_reorgs"
|
||||||
|
|
||||||
|
|
||||||
|
### ABI Jobs
|
||||||
|
|
||||||
|
|
||||||
|
class AbiJobs(Base):
|
||||||
|
__tablename__ = "abi_jobs"
|
||||||
|
|
||||||
|
__table_args__ = (
|
||||||
|
UniqueConstraint(
|
||||||
|
"chain", "address", "abi_selector", "customer_id", name="uq_abi_jobs"
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||||
|
address = Column(LargeBinary, nullable=False, index=True)
|
||||||
|
user_id = Column(UUID(as_uuid=True), nullable=False, index=True)
|
||||||
|
customer_id = Column(UUID(as_uuid=True), nullable=True, index=True)
|
||||||
|
abi_selector = Column(VARCHAR(256), nullable=False, index=True)
|
||||||
|
chain = Column(VARCHAR(256), nullable=False, index=True)
|
||||||
|
abi_name = Column(VARCHAR(256), nullable=False, index=True)
|
||||||
|
status = Column(VARCHAR(256), nullable=False, index=True)
|
||||||
|
historical_crawl_status = Column(VARCHAR(256), nullable=False, index=True)
|
||||||
|
progress = Column(Integer, nullable=False, index=False)
|
||||||
|
moonworm_task_pickedup = Column(Boolean, nullable=False, index=False)
|
||||||
|
abi = Column(Text, nullable=False)
|
||||||
|
created_at = Column(
|
||||||
|
DateTime(timezone=True), server_default=utcnow(), nullable=False
|
||||||
|
)
|
||||||
|
updated_at = Column(
|
||||||
|
DateTime(timezone=True), server_default=utcnow(), nullable=False
|
||||||
|
)
|
||||||
|
|
Ładowanie…
Reference in New Issue