From f913ec73ae8f9223f3dad4655b2ca14c0071984f Mon Sep 17 00:00:00 2001 From: kompotkot Date: Thu, 14 Mar 2024 13:05:07 +0000 Subject: [PATCH 1/8] Initial version of moonstreamdb-v3 --- moonstreamdb-v3/.gitignore | 197 +++++++ moonstreamdb-v3/README.md | 1 + moonstreamdb-v3/alembic.sample.ini | 116 ++++ moonstreamdb-v3/alembic.sh | 3 + moonstreamdb-v3/alembic/README | 1 + moonstreamdb-v3/alembic/env.py | 118 ++++ moonstreamdb-v3/alembic/script.py.mako | 26 + .../994e614b5500_tables_initial_generation.py | 509 ++++++++++++++++++ moonstreamdb-v3/moonstreamdb_v3/models.py | 287 ++++++++++ moonstreamdb-v3/moonstreamdb_v3/version.py | 11 + moonstreamdb-v3/moonstreamdb_v3/version.txt | 1 + moonstreamdb-v3/setup.py | 40 ++ 12 files changed, 1310 insertions(+) create mode 100644 moonstreamdb-v3/.gitignore create mode 100644 moonstreamdb-v3/README.md create mode 100644 moonstreamdb-v3/alembic.sample.ini create mode 100755 moonstreamdb-v3/alembic.sh create mode 100644 moonstreamdb-v3/alembic/README create mode 100644 moonstreamdb-v3/alembic/env.py create mode 100644 moonstreamdb-v3/alembic/script.py.mako create mode 100644 moonstreamdb-v3/alembic/versions/994e614b5500_tables_initial_generation.py create mode 100644 moonstreamdb-v3/moonstreamdb_v3/models.py create mode 100644 moonstreamdb-v3/moonstreamdb_v3/version.py create mode 100644 moonstreamdb-v3/moonstreamdb_v3/version.txt create mode 100644 moonstreamdb-v3/setup.py diff --git a/moonstreamdb-v3/.gitignore b/moonstreamdb-v3/.gitignore new file mode 100644 index 00000000..ff508ca8 --- /dev/null +++ b/moonstreamdb-v3/.gitignore @@ -0,0 +1,197 @@ + +# Created by https://www.toptal.com/developers/gitignore/api/python,visualstudiocode +# Edit at https://www.toptal.com/developers/gitignore?templates=python,visualstudiocode + +### Python ### +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +### VisualStudioCode ### +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +*.code-workspace + +# Local History for Visual Studio Code +.history/ + +### VisualStudioCode Patch ### +# Ignore all local history of files +.history +.ionide + +# End of https://www.toptal.com/developers/gitignore/api/python,visualstudiocode + +# Envionments +.moonstream/ +.moonstreamdb/ +.moonstreamdb-v3/ +.db/ +.venv/ +.env/ + +# Environment variables +dev.env +test.env +prod.env +moonstreamdb.env +moonstreamdb-v3.env +docker.env +docker.dev.env +docker.test.dev +docker.prod.env +docker.moonstreamdb-v3.env + +.secrets/ + +# Alembic migrations +alembic.test.ini +alembic.dev.ini +alembic.prod.ini +alembic.moonstreamdb-v3.ini +alembic.docker.ini + +# Schematic +srv/ +.schematic.env + +# Custom +scratch/ diff --git a/moonstreamdb-v3/README.md b/moonstreamdb-v3/README.md new file mode 100644 index 00000000..1f2927ab --- /dev/null +++ b/moonstreamdb-v3/README.md @@ -0,0 +1 @@ +# moonstreamdb-v3 diff --git a/moonstreamdb-v3/alembic.sample.ini b/moonstreamdb-v3/alembic.sample.ini new file mode 100644 index 00000000..c10d4ca0 --- /dev/null +++ b/moonstreamdb-v3/alembic.sample.ini @@ -0,0 +1,116 @@ +# A generic, single database configuration. + +[alembic] +# path to migration scripts +script_location = alembic + +# 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 alembic/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:alembic/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 + + +[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 diff --git a/moonstreamdb-v3/alembic.sh b/moonstreamdb-v3/alembic.sh new file mode 100755 index 00000000..9ca8b9b8 --- /dev/null +++ b/moonstreamdb-v3/alembic.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env sh + +PYTHONPATH=".:$PYTHONPATH" alembic "$@" diff --git a/moonstreamdb-v3/alembic/README b/moonstreamdb-v3/alembic/README new file mode 100644 index 00000000..98e4f9c4 --- /dev/null +++ b/moonstreamdb-v3/alembic/README @@ -0,0 +1 @@ +Generic single-database configuration. \ No newline at end of file diff --git a/moonstreamdb-v3/alembic/env.py b/moonstreamdb-v3/alembic/env.py new file mode 100644 index 00000000..10ff657f --- /dev/null +++ b/moonstreamdb-v3/alembic/env.py @@ -0,0 +1,118 @@ +from logging.config import fileConfig + +from sqlalchemy import engine_from_config +from sqlalchemy import pool + +from alembic import context + +# this is the Alembic Config object, which provides +# access to the values within the .ini file in use. +config = context.config + +# Interpret the config file for Python logging. +# This line sets up loggers basically. +if config.config_file_name is not None: + fileConfig(config.config_file_name) + +# add your model's MetaData object here +# for 'autogenerate' support +# from myapp import mymodel +# target_metadata = mymodel.Base.metadata +from moonstreamdb_v3.models import Base as MoonstreamBase + +target_metadata = MoonstreamBase.metadata + +# other values from the config, defined by the needs of env.py, +# can be acquired: +# my_important_option = config.get_main_option("my_important_option") +# ... etc. +from moonstreamdb_v3.models import ( + EthereumLabel, + SepoliaLabel, + PolygonLabel, + MumbaiLabel, + XDaiLabel, + WyrmLabel, + ZkSyncEraLabel, + ZkSyncEraTestnetLabel, + BaseLabel, + ArbitrumNovaLabel, + ArbitrumSepoliaLabel, + XaiSepoliaLabel, +) + + +def include_symbol(tablename, schema): + return tablename in { + EthereumLabel.__tablename__, + SepoliaLabel.__tablename__, + PolygonLabel.__tablename__, + MumbaiLabel.__tablename__, + XDaiLabel.__tablename__, + WyrmLabel.__tablename__, + ZkSyncEraLabel.__tablename__, + ZkSyncEraTestnetLabel.__tablename__, + BaseLabel.__tablename__, + ArbitrumNovaLabel.__tablename__, + ArbitrumSepoliaLabel.__tablename__, + XaiSepoliaLabel.__tablename__, + } + + +def run_migrations_offline() -> None: + """Run migrations in 'offline' mode. + + This configures the context with just a URL + and not an Engine, though an Engine is acceptable + here as well. By skipping the Engine creation + we don't even need a DBAPI to be available. + + Calls to context.execute() here emit the given string to the + script output. + + """ + url = config.get_main_option("sqlalchemy.url") + context.configure( + url=url, + target_metadata=target_metadata, + literal_binds=True, + dialect_opts={"paramstyle": "named"}, + version_table="alembic_version", + include_schemas=True, + include_symbol=include_symbol, + ) + + with context.begin_transaction(): + context.run_migrations() + + +def run_migrations_online() -> None: + """Run migrations in 'online' mode. + + In this scenario we need to create an Engine + and associate a connection with the context. + + """ + connectable = engine_from_config( + config.get_section(config.config_ini_section, {}), + prefix="sqlalchemy.", + poolclass=pool.NullPool, + ) + + with connectable.connect() as connection: + context.configure( + connection=connection, + target_metadata=target_metadata, + version_table="alembic_version", + include_schemas=True, + include_symbol=include_symbol, + ) + + with context.begin_transaction(): + context.run_migrations() + + +if context.is_offline_mode(): + run_migrations_offline() +else: + run_migrations_online() diff --git a/moonstreamdb-v3/alembic/script.py.mako b/moonstreamdb-v3/alembic/script.py.mako new file mode 100644 index 00000000..fbc4b07d --- /dev/null +++ b/moonstreamdb-v3/alembic/script.py.mako @@ -0,0 +1,26 @@ +"""${message} + +Revision ID: ${up_revision} +Revises: ${down_revision | comma,n} +Create Date: ${create_date} + +""" +from typing import Sequence, Union + +from alembic import op +import sqlalchemy as sa +${imports if imports else ""} + +# revision identifiers, used by Alembic. +revision: str = ${repr(up_revision)} +down_revision: Union[str, None] = ${repr(down_revision)} +branch_labels: Union[str, Sequence[str], None] = ${repr(branch_labels)} +depends_on: Union[str, Sequence[str], None] = ${repr(depends_on)} + + +def upgrade() -> None: + ${upgrades if upgrades else "pass"} + + +def downgrade() -> None: + ${downgrades if downgrades else "pass"} diff --git a/moonstreamdb-v3/alembic/versions/994e614b5500_tables_initial_generation.py b/moonstreamdb-v3/alembic/versions/994e614b5500_tables_initial_generation.py new file mode 100644 index 00000000..4b971275 --- /dev/null +++ b/moonstreamdb-v3/alembic/versions/994e614b5500_tables_initial_generation.py @@ -0,0 +1,509 @@ +"""Tables initial generation + +Revision ID: 994e614b5500 +Revises: +Create Date: 2024-03-14 07:03:35.586195 + +""" +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 = '994e614b5500' +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('arbitrum_nova_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.VARCHAR(length=64), nullable=True), + sa.Column('origin_address', sa.VARCHAR(length=64), nullable=True), + sa.Column('address', sa.VARCHAR(length=64), nullable=True), + 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_arbitrum_nova_labels')), + sa.UniqueConstraint('id', name=op.f('uq_arbitrum_nova_labels_id')), + ) + op.create_index('ix_arbitrum_nova_labels_addr_block_num', 'arbitrum_nova_labels', ['address', 'block_number'], unique=False) + op.create_index(op.f('ix_arbitrum_nova_labels_address'), 'arbitrum_nova_labels', ['address'], unique=False) + op.create_index(op.f('ix_arbitrum_nova_labels_block_number'), 'arbitrum_nova_labels', ['block_number'], unique=False) + op.create_index(op.f('ix_arbitrum_nova_labels_caller_address'), 'arbitrum_nova_labels', ['caller_address'], unique=False) + op.create_index(op.f('ix_arbitrum_nova_labels_label'), 'arbitrum_nova_labels', ['label'], unique=False) + op.create_index(op.f('ix_arbitrum_nova_labels_label_name'), 'arbitrum_nova_labels', ['label_name'], unique=False) + op.create_index(op.f('ix_arbitrum_nova_labels_label_type'), 'arbitrum_nova_labels', ['label_type'], unique=False) + op.create_index(op.f('ix_arbitrum_nova_labels_origin_address'), 'arbitrum_nova_labels', ['origin_address'], unique=False) + op.create_index(op.f('ix_arbitrum_nova_labels_transaction_hash'), 'arbitrum_nova_labels', ['transaction_hash'], unique=False) + op.create_table('arbitrum_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.VARCHAR(length=64), nullable=True), + sa.Column('origin_address', sa.VARCHAR(length=64), nullable=True), + sa.Column('address', sa.VARCHAR(length=64), nullable=True), + 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_arbitrum_sepolia_labels')), + sa.UniqueConstraint('id', name=op.f('uq_arbitrum_sepolia_labels_id')) + ) + op.create_index('ix_arbitrum_sepolia_labels_addr_block_num', 'arbitrum_sepolia_labels', ['address', 'block_number'], unique=False) + op.create_index(op.f('ix_arbitrum_sepolia_labels_address'), 'arbitrum_sepolia_labels', ['address'], unique=False) + op.create_index(op.f('ix_arbitrum_sepolia_labels_block_number'), 'arbitrum_sepolia_labels', ['block_number'], unique=False) + op.create_index(op.f('ix_arbitrum_sepolia_labels_caller_address'), 'arbitrum_sepolia_labels', ['caller_address'], unique=False) + op.create_index(op.f('ix_arbitrum_sepolia_labels_label'), 'arbitrum_sepolia_labels', ['label'], unique=False) + op.create_index(op.f('ix_arbitrum_sepolia_labels_label_name'), 'arbitrum_sepolia_labels', ['label_name'], unique=False) + op.create_index(op.f('ix_arbitrum_sepolia_labels_label_type'), 'arbitrum_sepolia_labels', ['label_type'], unique=False) + op.create_index(op.f('ix_arbitrum_sepolia_labels_origin_address'), 'arbitrum_sepolia_labels', ['origin_address'], unique=False) + op.create_index(op.f('ix_arbitrum_sepolia_labels_transaction_hash'), 'arbitrum_sepolia_labels', ['transaction_hash'], unique=False) + op.create_table('base_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.VARCHAR(length=64), nullable=True), + sa.Column('origin_address', sa.VARCHAR(length=64), nullable=True), + sa.Column('address', sa.VARCHAR(length=64), nullable=True), + 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_base_labels')), + sa.UniqueConstraint('id', name=op.f('uq_base_labels_id')) + ) + op.create_index('ix_base_labels_addr_block_num', 'base_labels', ['address', 'block_number'], unique=False) + op.create_index(op.f('ix_base_labels_address'), 'base_labels', ['address'], unique=False) + op.create_index(op.f('ix_base_labels_block_number'), 'base_labels', ['block_number'], unique=False) + op.create_index(op.f('ix_base_labels_caller_address'), 'base_labels', ['caller_address'], unique=False) + op.create_index(op.f('ix_base_labels_label'), 'base_labels', ['label'], unique=False) + op.create_index(op.f('ix_base_labels_label_name'), 'base_labels', ['label_name'], unique=False) + op.create_index(op.f('ix_base_labels_label_type'), 'base_labels', ['label_type'], unique=False) + op.create_index(op.f('ix_base_labels_origin_address'), 'base_labels', ['origin_address'], unique=False) + op.create_index(op.f('ix_base_labels_transaction_hash'), 'base_labels', ['transaction_hash'], unique=False) + op.create_table('ethereum_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.VARCHAR(length=64), nullable=True), + sa.Column('origin_address', sa.VARCHAR(length=64), nullable=True), + sa.Column('address', sa.VARCHAR(length=64), nullable=True), + 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_ethereum_labels')), + sa.UniqueConstraint('id', name=op.f('uq_ethereum_labels_id')) + ) + op.create_index('ix_ethereum_labels_addr_block_num', 'ethereum_labels', ['address', 'block_number'], unique=False) + op.create_index(op.f('ix_ethereum_labels_address'), 'ethereum_labels', ['address'], unique=False) + op.create_index(op.f('ix_ethereum_labels_block_number'), 'ethereum_labels', ['block_number'], unique=False) + op.create_index(op.f('ix_ethereum_labels_caller_address'), 'ethereum_labels', ['caller_address'], unique=False) + op.create_index(op.f('ix_ethereum_labels_label'), 'ethereum_labels', ['label'], unique=False) + op.create_index(op.f('ix_ethereum_labels_label_name'), 'ethereum_labels', ['label_name'], unique=False) + op.create_index(op.f('ix_ethereum_labels_label_type'), 'ethereum_labels', ['label_type'], unique=False) + op.create_index(op.f('ix_ethereum_labels_origin_address'), 'ethereum_labels', ['origin_address'], unique=False) + op.create_index(op.f('ix_ethereum_labels_transaction_hash'), 'ethereum_labels', ['transaction_hash'], unique=False) + op.create_table('mumbai_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.VARCHAR(length=64), nullable=True), + sa.Column('origin_address', sa.VARCHAR(length=64), nullable=True), + sa.Column('address', sa.VARCHAR(length=64), nullable=True), + 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_mumbai_labels')), + sa.UniqueConstraint('id', name=op.f('uq_mumbai_labels_id')) + ) + op.create_index('ix_mumbai_labels_addr_block_num', 'mumbai_labels', ['address', 'block_number'], unique=False) + op.create_index(op.f('ix_mumbai_labels_address'), 'mumbai_labels', ['address'], unique=False) + op.create_index(op.f('ix_mumbai_labels_block_number'), 'mumbai_labels', ['block_number'], unique=False) + op.create_index(op.f('ix_mumbai_labels_caller_address'), 'mumbai_labels', ['caller_address'], unique=False) + op.create_index(op.f('ix_mumbai_labels_label'), 'mumbai_labels', ['label'], unique=False) + op.create_index(op.f('ix_mumbai_labels_label_name'), 'mumbai_labels', ['label_name'], unique=False) + op.create_index(op.f('ix_mumbai_labels_label_type'), 'mumbai_labels', ['label_type'], unique=False) + op.create_index(op.f('ix_mumbai_labels_origin_address'), 'mumbai_labels', ['origin_address'], unique=False) + op.create_index(op.f('ix_mumbai_labels_transaction_hash'), 'mumbai_labels', ['transaction_hash'], unique=False) + op.create_table('polygon_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.VARCHAR(length=64), nullable=True), + sa.Column('origin_address', sa.VARCHAR(length=64), nullable=True), + sa.Column('address', sa.VARCHAR(length=64), nullable=True), + 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_polygon_labels')), + sa.UniqueConstraint('id', name=op.f('uq_polygon_labels_id')) + ) + op.create_index('ix_polygon_labels_addr_block_num', 'polygon_labels', ['address', 'block_number'], unique=False) + op.create_index(op.f('ix_polygon_labels_address'), 'polygon_labels', ['address'], unique=False) + op.create_index(op.f('ix_polygon_labels_block_number'), 'polygon_labels', ['block_number'], unique=False) + op.create_index(op.f('ix_polygon_labels_caller_address'), 'polygon_labels', ['caller_address'], unique=False) + op.create_index(op.f('ix_polygon_labels_label'), 'polygon_labels', ['label'], unique=False) + op.create_index(op.f('ix_polygon_labels_label_name'), 'polygon_labels', ['label_name'], unique=False) + op.create_index(op.f('ix_polygon_labels_label_type'), 'polygon_labels', ['label_type'], unique=False) + op.create_index(op.f('ix_polygon_labels_origin_address'), 'polygon_labels', ['origin_address'], unique=False) + op.create_index(op.f('ix_polygon_labels_transaction_hash'), 'polygon_labels', ['transaction_hash'], unique=False) + op.create_table('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.VARCHAR(length=64), nullable=True), + sa.Column('origin_address', sa.VARCHAR(length=64), nullable=True), + sa.Column('address', sa.VARCHAR(length=64), nullable=True), + 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_sepolia_labels')), + sa.UniqueConstraint('id', name=op.f('uq_sepolia_labels_id')) + ) + op.create_index('ix_sepolia_labels_addr_block_num', 'sepolia_labels', ['address', 'block_number'], unique=False) + op.create_index(op.f('ix_sepolia_labels_address'), 'sepolia_labels', ['address'], unique=False) + op.create_index(op.f('ix_sepolia_labels_block_number'), 'sepolia_labels', ['block_number'], unique=False) + op.create_index(op.f('ix_sepolia_labels_caller_address'), 'sepolia_labels', ['caller_address'], unique=False) + op.create_index(op.f('ix_sepolia_labels_label'), 'sepolia_labels', ['label'], unique=False) + op.create_index(op.f('ix_sepolia_labels_label_name'), 'sepolia_labels', ['label_name'], unique=False) + op.create_index(op.f('ix_sepolia_labels_label_type'), 'sepolia_labels', ['label_type'], unique=False) + op.create_index(op.f('ix_sepolia_labels_origin_address'), 'sepolia_labels', ['origin_address'], unique=False) + op.create_index(op.f('ix_sepolia_labels_transaction_hash'), 'sepolia_labels', ['transaction_hash'], unique=False) + op.create_table('wyrm_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.VARCHAR(length=64), nullable=True), + sa.Column('origin_address', sa.VARCHAR(length=64), nullable=True), + sa.Column('address', sa.VARCHAR(length=64), nullable=True), + 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_wyrm_labels')), + sa.UniqueConstraint('id', name=op.f('uq_wyrm_labels_id')) + ) + op.create_index('ix_wyrm_labels_addr_block_num', 'wyrm_labels', ['address', 'block_number'], unique=False) + op.create_index(op.f('ix_wyrm_labels_address'), 'wyrm_labels', ['address'], unique=False) + op.create_index(op.f('ix_wyrm_labels_block_number'), 'wyrm_labels', ['block_number'], unique=False) + op.create_index(op.f('ix_wyrm_labels_caller_address'), 'wyrm_labels', ['caller_address'], unique=False) + op.create_index(op.f('ix_wyrm_labels_label'), 'wyrm_labels', ['label'], unique=False) + op.create_index(op.f('ix_wyrm_labels_label_name'), 'wyrm_labels', ['label_name'], unique=False) + op.create_index(op.f('ix_wyrm_labels_label_type'), 'wyrm_labels', ['label_type'], unique=False) + op.create_index(op.f('ix_wyrm_labels_origin_address'), 'wyrm_labels', ['origin_address'], unique=False) + op.create_index(op.f('ix_wyrm_labels_transaction_hash'), 'wyrm_labels', ['transaction_hash'], unique=False) + op.create_table('xai_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.VARCHAR(length=64), nullable=True), + sa.Column('origin_address', sa.VARCHAR(length=64), nullable=True), + sa.Column('address', sa.VARCHAR(length=64), nullable=True), + 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_xai_labels')), + sa.UniqueConstraint('id', name=op.f('uq_xai_labels_id')) + ) + op.create_index('ix_xai_labels_addr_block_num', 'xai_labels', ['address', 'block_number'], unique=False) + op.create_index(op.f('ix_xai_labels_address'), 'xai_labels', ['address'], unique=False) + op.create_index(op.f('ix_xai_labels_block_number'), 'xai_labels', ['block_number'], unique=False) + op.create_index(op.f('ix_xai_labels_caller_address'), 'xai_labels', ['caller_address'], unique=False) + op.create_index(op.f('ix_xai_labels_label'), 'xai_labels', ['label'], unique=False) + op.create_index(op.f('ix_xai_labels_label_name'), 'xai_labels', ['label_name'], unique=False) + op.create_index(op.f('ix_xai_labels_label_type'), 'xai_labels', ['label_type'], unique=False) + op.create_index(op.f('ix_xai_labels_origin_address'), 'xai_labels', ['origin_address'], unique=False) + op.create_index(op.f('ix_xai_labels_transaction_hash'), 'xai_labels', ['transaction_hash'], unique=False) + op.create_table('xai_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.VARCHAR(length=64), nullable=True), + sa.Column('origin_address', sa.VARCHAR(length=64), nullable=True), + sa.Column('address', sa.VARCHAR(length=64), nullable=True), + 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_xai_sepolia_labels')), + sa.UniqueConstraint('id', name=op.f('uq_xai_sepolia_labels_id')) + ) + op.create_index('ix_xai_sepolia_labels_addr_block_num', 'xai_sepolia_labels', ['address', 'block_number'], unique=False) + op.create_index(op.f('ix_xai_sepolia_labels_address'), 'xai_sepolia_labels', ['address'], unique=False) + op.create_index(op.f('ix_xai_sepolia_labels_block_number'), 'xai_sepolia_labels', ['block_number'], unique=False) + op.create_index(op.f('ix_xai_sepolia_labels_caller_address'), 'xai_sepolia_labels', ['caller_address'], unique=False) + op.create_index(op.f('ix_xai_sepolia_labels_label'), 'xai_sepolia_labels', ['label'], unique=False) + op.create_index(op.f('ix_xai_sepolia_labels_label_name'), 'xai_sepolia_labels', ['label_name'], unique=False) + op.create_index(op.f('ix_xai_sepolia_labels_label_type'), 'xai_sepolia_labels', ['label_type'], unique=False) + op.create_index(op.f('ix_xai_sepolia_labels_origin_address'), 'xai_sepolia_labels', ['origin_address'], unique=False) + op.create_index(op.f('ix_xai_sepolia_labels_transaction_hash'), 'xai_sepolia_labels', ['transaction_hash'], unique=False) + op.create_table('xdai_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.VARCHAR(length=64), nullable=True), + sa.Column('origin_address', sa.VARCHAR(length=64), nullable=True), + sa.Column('address', sa.VARCHAR(length=64), nullable=True), + 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_xdai_labels')), + sa.UniqueConstraint('id', name=op.f('uq_xdai_labels_id')) + ) + op.create_index('ix_xdai_labels_addr_block_num', 'xdai_labels', ['address', 'block_number'], unique=False) + op.create_index(op.f('ix_xdai_labels_address'), 'xdai_labels', ['address'], unique=False) + op.create_index(op.f('ix_xdai_labels_block_number'), 'xdai_labels', ['block_number'], unique=False) + op.create_index(op.f('ix_xdai_labels_caller_address'), 'xdai_labels', ['caller_address'], unique=False) + op.create_index(op.f('ix_xdai_labels_label'), 'xdai_labels', ['label'], unique=False) + op.create_index(op.f('ix_xdai_labels_label_name'), 'xdai_labels', ['label_name'], unique=False) + op.create_index(op.f('ix_xdai_labels_label_type'), 'xdai_labels', ['label_type'], unique=False) + op.create_index(op.f('ix_xdai_labels_origin_address'), 'xdai_labels', ['origin_address'], unique=False) + op.create_index(op.f('ix_xdai_labels_transaction_hash'), 'xdai_labels', ['transaction_hash'], unique=False) + op.create_table('zksync_era_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.VARCHAR(length=64), nullable=True), + sa.Column('origin_address', sa.VARCHAR(length=64), nullable=True), + sa.Column('address', sa.VARCHAR(length=64), nullable=True), + 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_zksync_era_labels')), + sa.UniqueConstraint('id', name=op.f('uq_zksync_era_labels_id')) + ) + op.create_index('ix_zksync_era_labels_addr_block_num', 'zksync_era_labels', ['address', 'block_number'], unique=False) + op.create_index(op.f('ix_zksync_era_labels_address'), 'zksync_era_labels', ['address'], unique=False) + op.create_index(op.f('ix_zksync_era_labels_block_number'), 'zksync_era_labels', ['block_number'], unique=False) + op.create_index(op.f('ix_zksync_era_labels_caller_address'), 'zksync_era_labels', ['caller_address'], unique=False) + op.create_index(op.f('ix_zksync_era_labels_label'), 'zksync_era_labels', ['label'], unique=False) + op.create_index(op.f('ix_zksync_era_labels_label_name'), 'zksync_era_labels', ['label_name'], unique=False) + op.create_index(op.f('ix_zksync_era_labels_label_type'), 'zksync_era_labels', ['label_type'], unique=False) + op.create_index(op.f('ix_zksync_era_labels_origin_address'), 'zksync_era_labels', ['origin_address'], unique=False) + op.create_index(op.f('ix_zksync_era_labels_transaction_hash'), 'zksync_era_labels', ['transaction_hash'], unique=False) + op.create_table('zksync_era_testnet_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.VARCHAR(length=64), nullable=True), + sa.Column('origin_address', sa.VARCHAR(length=64), nullable=True), + sa.Column('address', sa.VARCHAR(length=64), nullable=True), + 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_zksync_era_testnet_labels')), + sa.UniqueConstraint('id', name=op.f('uq_zksync_era_testnet_labels_id')) + ) + op.create_index('ix_zksync_era_testnet_labels_addr_block_num', 'zksync_era_testnet_labels', ['address', 'block_number'], unique=False) + op.create_index(op.f('ix_zksync_era_testnet_labels_address'), 'zksync_era_testnet_labels', ['address'], unique=False) + op.create_index(op.f('ix_zksync_era_testnet_labels_block_number'), 'zksync_era_testnet_labels', ['block_number'], unique=False) + op.create_index(op.f('ix_zksync_era_testnet_labels_caller_address'), 'zksync_era_testnet_labels', ['caller_address'], unique=False) + op.create_index(op.f('ix_zksync_era_testnet_labels_label'), 'zksync_era_testnet_labels', ['label'], unique=False) + op.create_index(op.f('ix_zksync_era_testnet_labels_label_name'), 'zksync_era_testnet_labels', ['label_name'], unique=False) + op.create_index(op.f('ix_zksync_era_testnet_labels_label_type'), 'zksync_era_testnet_labels', ['label_type'], unique=False) + op.create_index(op.f('ix_zksync_era_testnet_labels_origin_address'), 'zksync_era_testnet_labels', ['origin_address'], unique=False) + op.create_index(op.f('ix_zksync_era_testnet_labels_transaction_hash'), 'zksync_era_testnet_labels', ['transaction_hash'], unique=False) + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.drop_index(op.f('ix_zksync_era_testnet_labels_transaction_hash'), table_name='zksync_era_testnet_labels') + op.drop_index(op.f('ix_zksync_era_testnet_labels_origin_address'), table_name='zksync_era_testnet_labels') + op.drop_index(op.f('ix_zksync_era_testnet_labels_label_type'), table_name='zksync_era_testnet_labels') + op.drop_index(op.f('ix_zksync_era_testnet_labels_label_name'), table_name='zksync_era_testnet_labels') + op.drop_index(op.f('ix_zksync_era_testnet_labels_label'), table_name='zksync_era_testnet_labels') + op.drop_index(op.f('ix_zksync_era_testnet_labels_caller_address'), table_name='zksync_era_testnet_labels') + op.drop_index(op.f('ix_zksync_era_testnet_labels_block_number'), table_name='zksync_era_testnet_labels') + op.drop_index(op.f('ix_zksync_era_testnet_labels_address'), table_name='zksync_era_testnet_labels') + op.drop_index('ix_zksync_era_testnet_labels_addr_block_num', table_name='zksync_era_testnet_labels') + op.drop_table('zksync_era_testnet_labels') + op.drop_index(op.f('ix_zksync_era_labels_transaction_hash'), table_name='zksync_era_labels') + op.drop_index(op.f('ix_zksync_era_labels_origin_address'), table_name='zksync_era_labels') + op.drop_index(op.f('ix_zksync_era_labels_label_type'), table_name='zksync_era_labels') + op.drop_index(op.f('ix_zksync_era_labels_label_name'), table_name='zksync_era_labels') + op.drop_index(op.f('ix_zksync_era_labels_label'), table_name='zksync_era_labels') + op.drop_index(op.f('ix_zksync_era_labels_caller_address'), table_name='zksync_era_labels') + op.drop_index(op.f('ix_zksync_era_labels_block_number'), table_name='zksync_era_labels') + op.drop_index(op.f('ix_zksync_era_labels_address'), table_name='zksync_era_labels') + op.drop_index('ix_zksync_era_labels_addr_block_num', table_name='zksync_era_labels') + op.drop_table('zksync_era_labels') + op.drop_index(op.f('ix_xdai_labels_transaction_hash'), table_name='xdai_labels') + op.drop_index(op.f('ix_xdai_labels_origin_address'), table_name='xdai_labels') + op.drop_index(op.f('ix_xdai_labels_label_type'), table_name='xdai_labels') + op.drop_index(op.f('ix_xdai_labels_label_name'), table_name='xdai_labels') + op.drop_index(op.f('ix_xdai_labels_label'), table_name='xdai_labels') + op.drop_index(op.f('ix_xdai_labels_caller_address'), table_name='xdai_labels') + op.drop_index(op.f('ix_xdai_labels_block_number'), table_name='xdai_labels') + op.drop_index(op.f('ix_xdai_labels_address'), table_name='xdai_labels') + op.drop_index('ix_xdai_labels_addr_block_num', table_name='xdai_labels') + op.drop_table('xdai_labels') + op.drop_index(op.f('ix_xai_sepolia_labels_transaction_hash'), table_name='xai_sepolia_labels') + op.drop_index(op.f('ix_xai_sepolia_labels_origin_address'), table_name='xai_sepolia_labels') + op.drop_index(op.f('ix_xai_sepolia_labels_label_type'), table_name='xai_sepolia_labels') + op.drop_index(op.f('ix_xai_sepolia_labels_label_name'), table_name='xai_sepolia_labels') + op.drop_index(op.f('ix_xai_sepolia_labels_label'), table_name='xai_sepolia_labels') + op.drop_index(op.f('ix_xai_sepolia_labels_caller_address'), table_name='xai_sepolia_labels') + op.drop_index(op.f('ix_xai_sepolia_labels_block_number'), table_name='xai_sepolia_labels') + op.drop_index(op.f('ix_xai_sepolia_labels_address'), table_name='xai_sepolia_labels') + op.drop_index('ix_xai_sepolia_labels_addr_block_num', table_name='xai_sepolia_labels') + op.drop_table('xai_sepolia_labels') + op.drop_index(op.f('ix_xai_labels_transaction_hash'), table_name='xai_labels') + op.drop_index(op.f('ix_xai_labels_origin_address'), table_name='xai_labels') + op.drop_index(op.f('ix_xai_labels_label_type'), table_name='xai_labels') + op.drop_index(op.f('ix_xai_labels_label_name'), table_name='xai_labels') + op.drop_index(op.f('ix_xai_labels_label'), table_name='xai_labels') + op.drop_index(op.f('ix_xai_labels_caller_address'), table_name='xai_labels') + op.drop_index(op.f('ix_xai_labels_block_number'), table_name='xai_labels') + op.drop_index(op.f('ix_xai_labels_address'), table_name='xai_labels') + op.drop_index('ix_xai_labels_addr_block_num', table_name='xai_labels') + op.drop_table('xai_labels') + op.drop_index(op.f('ix_wyrm_labels_transaction_hash'), table_name='wyrm_labels') + op.drop_index(op.f('ix_wyrm_labels_origin_address'), table_name='wyrm_labels') + op.drop_index(op.f('ix_wyrm_labels_label_type'), table_name='wyrm_labels') + op.drop_index(op.f('ix_wyrm_labels_label_name'), table_name='wyrm_labels') + op.drop_index(op.f('ix_wyrm_labels_label'), table_name='wyrm_labels') + op.drop_index(op.f('ix_wyrm_labels_caller_address'), table_name='wyrm_labels') + op.drop_index(op.f('ix_wyrm_labels_block_number'), table_name='wyrm_labels') + op.drop_index(op.f('ix_wyrm_labels_address'), table_name='wyrm_labels') + op.drop_index('ix_wyrm_labels_addr_block_num', table_name='wyrm_labels') + op.drop_table('wyrm_labels') + op.drop_index(op.f('ix_sepolia_labels_transaction_hash'), table_name='sepolia_labels') + op.drop_index(op.f('ix_sepolia_labels_origin_address'), table_name='sepolia_labels') + op.drop_index(op.f('ix_sepolia_labels_label_type'), table_name='sepolia_labels') + op.drop_index(op.f('ix_sepolia_labels_label_name'), table_name='sepolia_labels') + op.drop_index(op.f('ix_sepolia_labels_label'), table_name='sepolia_labels') + op.drop_index(op.f('ix_sepolia_labels_caller_address'), table_name='sepolia_labels') + op.drop_index(op.f('ix_sepolia_labels_block_number'), table_name='sepolia_labels') + op.drop_index(op.f('ix_sepolia_labels_address'), table_name='sepolia_labels') + op.drop_index('ix_sepolia_labels_addr_block_num', table_name='sepolia_labels') + op.drop_table('sepolia_labels') + op.drop_index(op.f('ix_polygon_labels_transaction_hash'), table_name='polygon_labels') + op.drop_index(op.f('ix_polygon_labels_origin_address'), table_name='polygon_labels') + op.drop_index(op.f('ix_polygon_labels_label_type'), table_name='polygon_labels') + op.drop_index(op.f('ix_polygon_labels_label_name'), table_name='polygon_labels') + op.drop_index(op.f('ix_polygon_labels_label'), table_name='polygon_labels') + op.drop_index(op.f('ix_polygon_labels_caller_address'), table_name='polygon_labels') + op.drop_index(op.f('ix_polygon_labels_block_number'), table_name='polygon_labels') + op.drop_index(op.f('ix_polygon_labels_address'), table_name='polygon_labels') + op.drop_index('ix_polygon_labels_addr_block_num', table_name='polygon_labels') + op.drop_table('polygon_labels') + op.drop_index(op.f('ix_mumbai_labels_transaction_hash'), table_name='mumbai_labels') + op.drop_index(op.f('ix_mumbai_labels_origin_address'), table_name='mumbai_labels') + op.drop_index(op.f('ix_mumbai_labels_label_type'), table_name='mumbai_labels') + op.drop_index(op.f('ix_mumbai_labels_label_name'), table_name='mumbai_labels') + op.drop_index(op.f('ix_mumbai_labels_label'), table_name='mumbai_labels') + op.drop_index(op.f('ix_mumbai_labels_caller_address'), table_name='mumbai_labels') + op.drop_index(op.f('ix_mumbai_labels_block_number'), table_name='mumbai_labels') + op.drop_index(op.f('ix_mumbai_labels_address'), table_name='mumbai_labels') + op.drop_index('ix_mumbai_labels_addr_block_num', table_name='mumbai_labels') + op.drop_table('mumbai_labels') + op.drop_index(op.f('ix_ethereum_labels_transaction_hash'), table_name='ethereum_labels') + op.drop_index(op.f('ix_ethereum_labels_origin_address'), table_name='ethereum_labels') + op.drop_index(op.f('ix_ethereum_labels_label_type'), table_name='ethereum_labels') + op.drop_index(op.f('ix_ethereum_labels_label_name'), table_name='ethereum_labels') + op.drop_index(op.f('ix_ethereum_labels_label'), table_name='ethereum_labels') + op.drop_index(op.f('ix_ethereum_labels_caller_address'), table_name='ethereum_labels') + op.drop_index(op.f('ix_ethereum_labels_block_number'), table_name='ethereum_labels') + op.drop_index(op.f('ix_ethereum_labels_address'), table_name='ethereum_labels') + op.drop_index('ix_ethereum_labels_addr_block_num', table_name='ethereum_labels') + op.drop_table('ethereum_labels') + op.drop_index(op.f('ix_base_labels_transaction_hash'), table_name='base_labels') + op.drop_index(op.f('ix_base_labels_origin_address'), table_name='base_labels') + op.drop_index(op.f('ix_base_labels_label_type'), table_name='base_labels') + op.drop_index(op.f('ix_base_labels_label_name'), table_name='base_labels') + op.drop_index(op.f('ix_base_labels_label'), table_name='base_labels') + op.drop_index(op.f('ix_base_labels_caller_address'), table_name='base_labels') + op.drop_index(op.f('ix_base_labels_block_number'), table_name='base_labels') + op.drop_index(op.f('ix_base_labels_address'), table_name='base_labels') + op.drop_index('ix_base_labels_addr_block_num', table_name='base_labels') + op.drop_table('base_labels') + op.drop_index(op.f('ix_arbitrum_sepolia_labels_transaction_hash'), table_name='arbitrum_sepolia_labels') + op.drop_index(op.f('ix_arbitrum_sepolia_labels_origin_address'), table_name='arbitrum_sepolia_labels') + op.drop_index(op.f('ix_arbitrum_sepolia_labels_label_type'), table_name='arbitrum_sepolia_labels') + op.drop_index(op.f('ix_arbitrum_sepolia_labels_label_name'), table_name='arbitrum_sepolia_labels') + op.drop_index(op.f('ix_arbitrum_sepolia_labels_label'), table_name='arbitrum_sepolia_labels') + op.drop_index(op.f('ix_arbitrum_sepolia_labels_caller_address'), table_name='arbitrum_sepolia_labels') + op.drop_index(op.f('ix_arbitrum_sepolia_labels_block_number'), table_name='arbitrum_sepolia_labels') + op.drop_index(op.f('ix_arbitrum_sepolia_labels_address'), table_name='arbitrum_sepolia_labels') + op.drop_index('ix_arbitrum_sepolia_labels_addr_block_num', table_name='arbitrum_sepolia_labels') + op.drop_table('arbitrum_sepolia_labels') + op.drop_index(op.f('ix_arbitrum_nova_labels_transaction_hash'), table_name='arbitrum_nova_labels') + op.drop_index(op.f('ix_arbitrum_nova_labels_origin_address'), table_name='arbitrum_nova_labels') + op.drop_index(op.f('ix_arbitrum_nova_labels_label_type'), table_name='arbitrum_nova_labels') + op.drop_index(op.f('ix_arbitrum_nova_labels_label_name'), table_name='arbitrum_nova_labels') + op.drop_index(op.f('ix_arbitrum_nova_labels_label'), table_name='arbitrum_nova_labels') + op.drop_index(op.f('ix_arbitrum_nova_labels_caller_address'), table_name='arbitrum_nova_labels') + op.drop_index(op.f('ix_arbitrum_nova_labels_block_number'), table_name='arbitrum_nova_labels') + op.drop_index(op.f('ix_arbitrum_nova_labels_address'), table_name='arbitrum_nova_labels') + op.drop_index('ix_arbitrum_nova_labels_addr_block_num', table_name='arbitrum_nova_labels') + op.drop_table('arbitrum_nova_labels') + # ### end Alembic commands ### diff --git a/moonstreamdb-v3/moonstreamdb_v3/models.py b/moonstreamdb-v3/moonstreamdb_v3/models.py new file mode 100644 index 00000000..47f0cb1e --- /dev/null +++ b/moonstreamdb-v3/moonstreamdb_v3/models.py @@ -0,0 +1,287 @@ +""" +Moonstream database V3 + +Example of label_data column record: + { + "label": "ERC20", + "label_data": { + "name": "Uniswap", + "symbol": "UNI" + } + }, + { + "label": "Exchange" + "label_data": {...} + } +""" + +import os +import uuid + +from sqlalchemy import ( + VARCHAR, + BigInteger, + Column, + DateTime, + Index, + Integer, + MetaData, + Text, +) +from sqlalchemy.dialects.postgresql import JSONB, UUID +from sqlalchemy.ext.compiler import compiles +from sqlalchemy.ext.declarative import declarative_base +from sqlalchemy.sql import expression + +""" +Naming conventions doc +https://docs.sqlalchemy.org/en/20/core/constraints.html#configuring-constraint-naming-conventions +""" +convention = { + "ix": "ix_%(column_0_label)s", + "uq": "uq_%(table_name)s_%(column_0_name)s", + "ck": "ck_%(table_name)s_%(constraint_name)s", + "fk": "fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s", + "pk": "pk_%(table_name)s", +} +metadata = MetaData(naming_convention=convention) +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): + type = DateTime # type: ignore + + +@compiles(utcnow, "postgresql") +def pg_utcnow(element, compiler, **kwargs): + return "TIMEZONE('utc', statement_timestamp())" + + +class EvmBasedLabel(Base): # type: ignore + __abstract__ = True + + id = Column( + UUID(as_uuid=True), + primary_key=True, + default=uuid.uuid4, + unique=True, + nullable=False, + ) + label = Column(VARCHAR(256), nullable=False, index=True) + + transaction_hash = Column( + VARCHAR(128), + nullable=False, + index=True, + ) + log_index = Column(Integer, nullable=True) + + block_number = Column( + BigInteger, + nullable=False, + index=True, + ) + block_hash = Column(VARCHAR(256), nullable=False) + block_timestamp = Column(BigInteger, nullable=False) + + caller_address = Column( + VARCHAR(64), + nullable=True, + index=True, + ) + origin_address = Column( + VARCHAR(64), + nullable=True, + index=True, + ) + address = Column( + VARCHAR(64), + nullable=True, + index=True, + ) + + label_name = Column(Text, nullable=True, index=True) + label_type = Column(VARCHAR(64), nullable=True, index=True) + label_data = Column(JSONB, nullable=True) + + created_at = Column( + DateTime(timezone=True), server_default=utcnow(), nullable=False + ) + + +class EthereumLabel(EvmBasedLabel): # type: ignore + __tablename__ = "ethereum_labels" + + __table_args__ = ( + Index( + "ix_ethereum_labels_addr_block_num", + "address", + "block_number", + unique=False, + ), + ) + + +class SepoliaLabel(EvmBasedLabel): # type: ignore + __tablename__ = "sepolia_labels" + + __table_args__ = ( + Index( + "ix_sepolia_labels_addr_block_num", + "address", + "block_number", + unique=False, + ), + ) + + +class PolygonLabel(EvmBasedLabel): # type: ignore + __tablename__ = "polygon_labels" + + __table_args__ = ( + Index( + "ix_polygon_labels_addr_block_num", + "address", + "block_number", + unique=False, + ), + ) + + +class MumbaiLabel(EvmBasedLabel): # type: ignore + __tablename__ = "mumbai_labels" + + __table_args__ = ( + Index( + "ix_mumbai_labels_addr_block_num", + "address", + "block_number", + unique=False, + ), + ) + + +class XDaiLabel(EvmBasedLabel): # type: ignore + __tablename__ = "xdai_labels" + + __table_args__ = ( + Index( + "ix_xdai_labels_addr_block_num", + "address", + "block_number", + unique=False, + ), + ) + + +class WyrmLabel(EvmBasedLabel): # type: ignore + __tablename__ = "wyrm_labels" + + __table_args__ = ( + Index( + "ix_wyrm_labels_addr_block_num", + "address", + "block_number", + unique=False, + ), + ) + + +class ZkSyncEraLabel(EvmBasedLabel): # type: ignore + __tablename__ = "zksync_era_labels" + + __table_args__ = ( + Index( + "ix_zksync_era_labels_addr_block_num", + "address", + "block_number", + unique=False, + ), + ) + + +class ZkSyncEraTestnetLabel(EvmBasedLabel): # type: ignore + __tablename__ = "zksync_era_testnet_labels" + + __table_args__ = ( + Index( + "ix_zksync_era_testnet_labels_addr_block_num", + "address", + "block_number", + unique=False, + ), + ) + + +class BaseLabel(EvmBasedLabel): # type: ignore + __tablename__ = "base_labels" + + __table_args__ = ( + Index( + "ix_base_labels_addr_block_num", + "address", + "block_number", + unique=False, + ), + ) + + +class ArbitrumNovaLabel(EvmBasedLabel): # type: ignore + __tablename__ = "arbitrum_nova_labels" + + __table_args__ = ( + Index( + "ix_arbitrum_nova_labels_addr_block_num", + "address", + "block_number", + unique=False, + ), + ) + + +class ArbitrumSepoliaLabel(EvmBasedLabel): # type: ignore + __tablename__ = "arbitrum_sepolia_labels" + + __table_args__ = ( + Index( + "ix_arbitrum_sepolia_labels_addr_block_num", + "address", + "block_number", + unique=False, + ), + ) + + +class XaiLabel(EvmBasedLabel): # type: ignore + __tablename__ = "xai_labels" + + __table_args__ = ( + Index( + "ix_xai_labels_addr_block_num", + "address", + "block_number", + unique=False, + ), + ) + + +class XaiSepoliaLabel(EvmBasedLabel): # type: ignore + __tablename__ = "xai_sepolia_labels" + + __table_args__ = ( + Index( + "ix_xai_sepolia_labels_addr_block_num", + "address", + "block_number", + unique=False, + ), + ) diff --git a/moonstreamdb-v3/moonstreamdb_v3/version.py b/moonstreamdb-v3/moonstreamdb_v3/version.py new file mode 100644 index 00000000..24c4e81f --- /dev/null +++ b/moonstreamdb-v3/moonstreamdb_v3/version.py @@ -0,0 +1,11 @@ +import os + +VERSION = "UNKNOWN" + +try: + PATH = os.path.abspath(os.path.dirname(__file__)) + VERSION_FILE = os.path.join(PATH, "version.txt") + with open(VERSION_FILE) as ifp: + VERSION = ifp.read().strip() +except: + pass \ No newline at end of file diff --git a/moonstreamdb-v3/moonstreamdb_v3/version.txt b/moonstreamdb-v3/moonstreamdb_v3/version.txt new file mode 100644 index 00000000..a2268e2d --- /dev/null +++ b/moonstreamdb-v3/moonstreamdb_v3/version.txt @@ -0,0 +1 @@ +0.3.1 \ No newline at end of file diff --git a/moonstreamdb-v3/setup.py b/moonstreamdb-v3/setup.py new file mode 100644 index 00000000..8ff713c1 --- /dev/null +++ b/moonstreamdb-v3/setup.py @@ -0,0 +1,40 @@ +from setuptools import find_packages, setup + +from moonstreamdb_v3.version import VERSION + +long_description = "" +with open("README.md") as ifp: + long_description = ifp.read() + +setup( + name="moonstreamdb-v3", + version=VERSION, + author="Bugout.dev", + author_email="engineers@bugout.dev", + license="Apache License 2.0", + description="Moonstream V3 database", + long_description=long_description, + long_description_content_type="text/markdown", + url="https://github.com/bugout-dev/moonstream", + platforms="all", + classifiers=[ + "Development Status :: 2 - Pre-Alpha", + "Intended Audience :: Developers", + "Natural Language :: English", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: Implementation :: CPython", + "Topic :: Software Development :: Libraries", + "Topic :: Software Development :: Libraries :: Python Modules", + ], + python_requires=">=3.8", + packages=find_packages(), + package_data={"moonstreamdb_v3": ["py.typed"]}, + zip_safe=False, + install_requires=["alembic", "psycopg2-binary", "sqlalchemy>=2.0.4"], + extras_require={ + "dev": ["black", "isort", "mypy"], + "distribute": ["setuptools", "twine", "wheel"], + }, +) From 650d45a334c26004a13f6e2cbf0af624391bab1d Mon Sep 17 00:00:00 2001 From: kompotkot Date: Thu, 21 Mar 2024 15:24:59 +0000 Subject: [PATCH 2/8] Some fixes for correct packaging --- moonstreamdb-v3/.isort.cfg | 3 + moonstreamdb-v3/moonstreamdbv3/__init__.py | 0 moonstreamdb-v3/moonstreamdbv3/db.py | 111 ++++++++++++++++++ .../models.py | 1 - .../version.py | 2 +- .../version.txt | 0 moonstreamdb-v3/setup.py | 4 +- 7 files changed, 117 insertions(+), 4 deletions(-) create mode 100644 moonstreamdb-v3/.isort.cfg create mode 100644 moonstreamdb-v3/moonstreamdbv3/__init__.py create mode 100644 moonstreamdb-v3/moonstreamdbv3/db.py rename moonstreamdb-v3/{moonstreamdb_v3 => moonstreamdbv3}/models.py (99%) rename moonstreamdb-v3/{moonstreamdb_v3 => moonstreamdbv3}/version.py (96%) rename moonstreamdb-v3/{moonstreamdb_v3 => moonstreamdbv3}/version.txt (100%) diff --git a/moonstreamdb-v3/.isort.cfg b/moonstreamdb-v3/.isort.cfg new file mode 100644 index 00000000..81d54de1 --- /dev/null +++ b/moonstreamdb-v3/.isort.cfg @@ -0,0 +1,3 @@ +[settings] +profile = black +multi_line_output = 3 \ No newline at end of file diff --git a/moonstreamdb-v3/moonstreamdbv3/__init__.py b/moonstreamdb-v3/moonstreamdbv3/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/moonstreamdb-v3/moonstreamdbv3/db.py b/moonstreamdb-v3/moonstreamdbv3/db.py new file mode 100644 index 00000000..e99487bb --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/db.py @@ -0,0 +1,111 @@ +""" +Moonstream database connection. +""" + +import logging +import os +from contextlib import contextmanager +from typing import Generator + +from sqlalchemy import create_engine +from sqlalchemy.orm import Session, sessionmaker + +logging.basicConfig(level=logging.INFO) +logger = logging.getLogger(__name__) + +# try: +# MOONSTREAM_DB_URI = os.environ.get("MOONSTREAM_DB_URI") +# if MOONSTREAM_DB_URI is None: +# raise Warning("MOONSTREAM_DB_URI environment variable must be set") + +# MOONSTREAM_DB_URI_READ_ONLY = os.environ.get("MOONSTREAM_DB_URI_READ_ONLY") +# if MOONSTREAM_DB_URI_READ_ONLY is None: +# raise Warning("MOONSTREAM_DB_URI_READ_ONLY environment variable must be set") + +# MOONSTREAM_POOL_SIZE_RAW = os.environ.get("MOONSTREAM_POOL_SIZE") +# MOONSTREAM_POOL_SIZE = 1 +# try: +# if MOONSTREAM_POOL_SIZE_RAW is not None: +# MOONSTREAM_POOL_SIZE = int(MOONSTREAM_POOL_SIZE_RAW) +# except: +# raise ValueError( +# f"Could not parse MOONSTREAM_POOL_SIZE as int: {MOONSTREAM_POOL_SIZE_RAW}" +# ) + +# MOONSTREAM_DB_STATEMENT_TIMEOUT_MILLIS_RAW = os.environ.get( +# "MOONSTREAM_DB_STATEMENT_TIMEOUT_MILLIS" +# ) +# MOONSTREAM_DB_STATEMENT_TIMEOUT_MILLIS = 30000 +# try: +# if MOONSTREAM_DB_STATEMENT_TIMEOUT_MILLIS_RAW is not None: +# MOONSTREAM_DB_STATEMENT_TIMEOUT_MILLIS = int( +# MOONSTREAM_DB_STATEMENT_TIMEOUT_MILLIS_RAW +# ) +# except: +# raise ValueError( +# f"MOONSTREAM_DB_STATEMENT_TIMEOUT_MILLIS must be an integer: {MOONSTREAM_DB_STATEMENT_TIMEOUT_MILLIS_RAW}" +# ) +# except ValueError as e: +# raise ValueError(e) +# except Warning: +# logger.warning("Database variables not set") + + +def create_moonstream_engine( + url: str, pool_size: int, statement_timeout: int, pool_pre_ping: bool = False +): + # Pooling: https://docs.sqlalchemy.org/en/14/core/pooling.html#sqlalchemy.pool.QueuePool + # Statement timeout: https://stackoverflow.com/a/44936982 + return create_engine( + url=url, + pool_pre_ping=pool_pre_ping, + pool_size=pool_size, + connect_args={"options": f"-c statement_timeout={statement_timeout}"}, + ) + +# engine = create_moonstream_engine( +# url=MOONSTREAM_DB_URI, # type: ignore +# pool_size=MOONSTREAM_POOL_SIZE, +# statement_timeout=MOONSTREAM_DB_STATEMENT_TIMEOUT_MILLIS, +# ) +# SessionLocal = sessionmaker(bind=engine) + + +# def yield_db_session() -> Generator[Session, None, None]: +# """ +# Yields a database connection (created using environment variables). +# As per FastAPI docs: +# https://fastapi.tiangolo.com/tutorial/sql-databases/#create-a-dependency +# """ +# session = SessionLocal() +# try: +# yield session +# finally: +# session.close() + + +# yield_db_session_ctx = contextmanager(yield_db_session) + +# # Read only +# RO_engine = create_moonstream_engine( +# url=MOONSTREAM_DB_URI_READ_ONLY, # type: ignore +# pool_size=MOONSTREAM_POOL_SIZE, +# statement_timeout=MOONSTREAM_DB_STATEMENT_TIMEOUT_MILLIS, +# ) +# RO_SessionLocal = sessionmaker(bind=RO_engine) + + +# def yield_db_read_only_session() -> Generator[Session, None, None]: +# """ +# Yields a database connection (created using environment variables). +# As per FastAPI docs: +# https://fastapi.tiangolo.com/tutorial/sql-databases/#create-a-dependency +# """ +# session = RO_SessionLocal() +# try: +# yield session +# finally: +# session.close() + + +# yield_db_read_only_session_ctx = contextmanager(yield_db_read_only_session) diff --git a/moonstreamdb-v3/moonstreamdb_v3/models.py b/moonstreamdb-v3/moonstreamdbv3/models.py similarity index 99% rename from moonstreamdb-v3/moonstreamdb_v3/models.py rename to moonstreamdb-v3/moonstreamdbv3/models.py index 47f0cb1e..efdfc7e8 100644 --- a/moonstreamdb-v3/moonstreamdb_v3/models.py +++ b/moonstreamdb-v3/moonstreamdbv3/models.py @@ -15,7 +15,6 @@ Example of label_data column record: } """ -import os import uuid from sqlalchemy import ( diff --git a/moonstreamdb-v3/moonstreamdb_v3/version.py b/moonstreamdb-v3/moonstreamdbv3/version.py similarity index 96% rename from moonstreamdb-v3/moonstreamdb_v3/version.py rename to moonstreamdb-v3/moonstreamdbv3/version.py index 24c4e81f..d6ffd744 100644 --- a/moonstreamdb-v3/moonstreamdb_v3/version.py +++ b/moonstreamdb-v3/moonstreamdbv3/version.py @@ -8,4 +8,4 @@ try: with open(VERSION_FILE) as ifp: VERSION = ifp.read().strip() except: - pass \ No newline at end of file + pass diff --git a/moonstreamdb-v3/moonstreamdb_v3/version.txt b/moonstreamdb-v3/moonstreamdbv3/version.txt similarity index 100% rename from moonstreamdb-v3/moonstreamdb_v3/version.txt rename to moonstreamdb-v3/moonstreamdbv3/version.txt diff --git a/moonstreamdb-v3/setup.py b/moonstreamdb-v3/setup.py index 8ff713c1..34e36f05 100644 --- a/moonstreamdb-v3/setup.py +++ b/moonstreamdb-v3/setup.py @@ -1,6 +1,6 @@ from setuptools import find_packages, setup -from moonstreamdb_v3.version import VERSION +from moonstreamdbv3.version import VERSION long_description = "" with open("README.md") as ifp: @@ -30,7 +30,7 @@ setup( ], python_requires=">=3.8", packages=find_packages(), - package_data={"moonstreamdb_v3": ["py.typed"]}, + package_data={"moonstreamdbv3": ["py.typed"]}, zip_safe=False, install_requires=["alembic", "psycopg2-binary", "sqlalchemy>=2.0.4"], extras_require={ From d0cd24dd5f66ee160719838d7124cb3dab3eef00 Mon Sep 17 00:00:00 2001 From: kompotkot Date: Mon, 25 Mar 2024 10:47:28 +0000 Subject: [PATCH 3/8] Fixed package import --- moonstreamdb-v3/alembic/env.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/moonstreamdb-v3/alembic/env.py b/moonstreamdb-v3/alembic/env.py index 10ff657f..d46ce5c6 100644 --- a/moonstreamdb-v3/alembic/env.py +++ b/moonstreamdb-v3/alembic/env.py @@ -18,7 +18,7 @@ if config.config_file_name is not None: # for 'autogenerate' support # from myapp import mymodel # target_metadata = mymodel.Base.metadata -from moonstreamdb_v3.models import Base as MoonstreamBase +from moonstreamdbv3.models import Base as MoonstreamBase target_metadata = MoonstreamBase.metadata @@ -26,7 +26,7 @@ target_metadata = MoonstreamBase.metadata # can be acquired: # my_important_option = config.get_main_option("my_important_option") # ... etc. -from moonstreamdb_v3.models import ( +from moonstreamdbv3.models import ( EthereumLabel, SepoliaLabel, PolygonLabel, From 44b656fb9b626b8197207473f3071092b7c0250f Mon Sep 17 00:00:00 2001 From: kompotkot Date: Mon, 25 Mar 2024 10:58:54 +0000 Subject: [PATCH 4/8] Optimized db.py for future use --- moonstreamdb-v3/moonstreamdbv3/db.py | 176 ++++++++++++++++----------- 1 file changed, 103 insertions(+), 73 deletions(-) diff --git a/moonstreamdb-v3/moonstreamdbv3/db.py b/moonstreamdb-v3/moonstreamdbv3/db.py index e99487bb..a4d733ab 100644 --- a/moonstreamdb-v3/moonstreamdbv3/db.py +++ b/moonstreamdb-v3/moonstreamdbv3/db.py @@ -13,46 +13,49 @@ from sqlalchemy.orm import Session, sessionmaker logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) -# try: -# MOONSTREAM_DB_URI = os.environ.get("MOONSTREAM_DB_URI") -# if MOONSTREAM_DB_URI is None: -# raise Warning("MOONSTREAM_DB_URI environment variable must be set") +try: + MOONSTREAM_DB_URI = os.environ.get("MOONSTREAM_DB_URI") + if MOONSTREAM_DB_URI is None: + raise Warning("MOONSTREAM_DB_URI environment variable must be set") -# MOONSTREAM_DB_URI_READ_ONLY = os.environ.get("MOONSTREAM_DB_URI_READ_ONLY") -# if MOONSTREAM_DB_URI_READ_ONLY is None: -# raise Warning("MOONSTREAM_DB_URI_READ_ONLY environment variable must be set") + MOONSTREAM_DB_URI_READ_ONLY = os.environ.get("MOONSTREAM_DB_URI_READ_ONLY") + if MOONSTREAM_DB_URI_READ_ONLY is None: + raise Warning("MOONSTREAM_DB_URI_READ_ONLY environment variable must be set") -# MOONSTREAM_POOL_SIZE_RAW = os.environ.get("MOONSTREAM_POOL_SIZE") -# MOONSTREAM_POOL_SIZE = 1 -# try: -# if MOONSTREAM_POOL_SIZE_RAW is not None: -# MOONSTREAM_POOL_SIZE = int(MOONSTREAM_POOL_SIZE_RAW) -# except: -# raise ValueError( -# f"Could not parse MOONSTREAM_POOL_SIZE as int: {MOONSTREAM_POOL_SIZE_RAW}" -# ) + MOONSTREAM_POOL_SIZE_RAW = os.environ.get("MOONSTREAM_POOL_SIZE") + MOONSTREAM_POOL_SIZE = 1 + try: + if MOONSTREAM_POOL_SIZE_RAW is not None: + MOONSTREAM_POOL_SIZE = int(MOONSTREAM_POOL_SIZE_RAW) + except: + raise ValueError( + f"Could not parse MOONSTREAM_POOL_SIZE as int: {MOONSTREAM_POOL_SIZE_RAW}" + ) -# MOONSTREAM_DB_STATEMENT_TIMEOUT_MILLIS_RAW = os.environ.get( -# "MOONSTREAM_DB_STATEMENT_TIMEOUT_MILLIS" -# ) -# MOONSTREAM_DB_STATEMENT_TIMEOUT_MILLIS = 30000 -# try: -# if MOONSTREAM_DB_STATEMENT_TIMEOUT_MILLIS_RAW is not None: -# MOONSTREAM_DB_STATEMENT_TIMEOUT_MILLIS = int( -# MOONSTREAM_DB_STATEMENT_TIMEOUT_MILLIS_RAW -# ) -# except: -# raise ValueError( -# f"MOONSTREAM_DB_STATEMENT_TIMEOUT_MILLIS must be an integer: {MOONSTREAM_DB_STATEMENT_TIMEOUT_MILLIS_RAW}" -# ) -# except ValueError as e: -# raise ValueError(e) -# except Warning: -# logger.warning("Database variables not set") + MOONSTREAM_DB_STATEMENT_TIMEOUT_MILLIS_RAW = os.environ.get( + "MOONSTREAM_DB_STATEMENT_TIMEOUT_MILLIS" + ) + MOONSTREAM_DB_STATEMENT_TIMEOUT_MILLIS = 30000 + try: + if MOONSTREAM_DB_STATEMENT_TIMEOUT_MILLIS_RAW is not None: + MOONSTREAM_DB_STATEMENT_TIMEOUT_MILLIS = int( + MOONSTREAM_DB_STATEMENT_TIMEOUT_MILLIS_RAW + ) + except: + raise ValueError( + f"MOONSTREAM_DB_STATEMENT_TIMEOUT_MILLIS must be an integer: {MOONSTREAM_DB_STATEMENT_TIMEOUT_MILLIS_RAW}" + ) +except ValueError as e: + raise ValueError(e) +except Warning: + logger.warning("Database variables not set") def create_moonstream_engine( - url: str, pool_size: int, statement_timeout: int, pool_pre_ping: bool = False + url: str, + pool_size: int, + statement_timeout: int, + pool_pre_ping: bool = False, ): # Pooling: https://docs.sqlalchemy.org/en/14/core/pooling.html#sqlalchemy.pool.QueuePool # Statement timeout: https://stackoverflow.com/a/44936982 @@ -63,49 +66,76 @@ def create_moonstream_engine( connect_args={"options": f"-c statement_timeout={statement_timeout}"}, ) -# engine = create_moonstream_engine( -# url=MOONSTREAM_DB_URI, # type: ignore -# pool_size=MOONSTREAM_POOL_SIZE, -# statement_timeout=MOONSTREAM_DB_STATEMENT_TIMEOUT_MILLIS, -# ) -# SessionLocal = sessionmaker(bind=engine) + +class MoonstreamDBEngine: + def __init__(self) -> None: + self._engine = create_moonstream_engine( + url=MOONSTREAM_DB_URI, # type: ignore + pool_size=MOONSTREAM_POOL_SIZE, + statement_timeout=MOONSTREAM_DB_STATEMENT_TIMEOUT_MILLIS, + ) + self._session_local = sessionmaker(bind=self.engine) + + self._yield_db_session_ctx = contextmanager(self.yield_db_session) + + @property + def engine(self): + return self._engine + + @property + def session_local(self): + return self._session_local + + @property + def yield_db_session_ctx(self): + return self._yield_db_session_ctx + + def yield_db_session( + self, + ) -> Generator[Session, None, None]: + """ + Yields a database connection (created using environment variables). + As per FastAPI docs: + https://fastapi.tiangolo.com/tutorial/sql-databases/#create-a-dependency + """ + session = self._session_local() + try: + yield session + finally: + session.close() -# def yield_db_session() -> Generator[Session, None, None]: -# """ -# Yields a database connection (created using environment variables). -# As per FastAPI docs: -# https://fastapi.tiangolo.com/tutorial/sql-databases/#create-a-dependency -# """ -# session = SessionLocal() -# try: -# yield session -# finally: -# session.close() +class MoonstreamDBEngineRO: + def __init__(self) -> None: + self._RO_engine = create_moonstream_engine( + url=MOONSTREAM_DB_URI_READ_ONLY, # type: ignore + pool_size=MOONSTREAM_POOL_SIZE, + statement_timeout=MOONSTREAM_DB_STATEMENT_TIMEOUT_MILLIS, + ) + self._RO_session_local = sessionmaker(bind=self.RO_engine) + self._RO_yield_db_session_ctx = contextmanager(self.yield_db_read_only_session) -# yield_db_session_ctx = contextmanager(yield_db_session) + @property + def RO_engine(self): + return self._RO_engine -# # Read only -# RO_engine = create_moonstream_engine( -# url=MOONSTREAM_DB_URI_READ_ONLY, # type: ignore -# pool_size=MOONSTREAM_POOL_SIZE, -# statement_timeout=MOONSTREAM_DB_STATEMENT_TIMEOUT_MILLIS, -# ) -# RO_SessionLocal = sessionmaker(bind=RO_engine) + @property + def RO_session_local(self): + return self._RO_session_local + @property + def RO_yield_db_session_ctx(self): + return self._RO_yield_db_session_ctx -# def yield_db_read_only_session() -> Generator[Session, None, None]: -# """ -# Yields a database connection (created using environment variables). -# As per FastAPI docs: -# https://fastapi.tiangolo.com/tutorial/sql-databases/#create-a-dependency -# """ -# session = RO_SessionLocal() -# try: -# yield session -# finally: -# session.close() - - -# yield_db_read_only_session_ctx = contextmanager(yield_db_read_only_session) + def yield_db_read_only_session(self) -> Generator[Session, None, None]: + """ + Yields read-only database connection (created using environment variables). + As per FastAPI docs: + https://fastapi.tiangolo.com/tutorial/sql-databases/#create-a-dependency + """ + session = self._RO_session_local() + try: + yield session + finally: + session.close() From 51f6e5d02e3835cc018a7fd1687276fb3982f4d8 Mon Sep 17 00:00:00 2001 From: kompotkot Date: Tue, 26 Mar 2024 09:38:40 +0000 Subject: [PATCH 5/8] Alembic migrations in package --- moonstreamdb-v3/{ => moonstreamdbv3}/alembic/README | 0 moonstreamdb-v3/{ => moonstreamdbv3}/alembic/env.py | 0 moonstreamdb-v3/{ => moonstreamdbv3}/alembic/script.py.mako | 0 .../alembic/versions/994e614b5500_tables_initial_generation.py | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename moonstreamdb-v3/{ => moonstreamdbv3}/alembic/README (100%) rename moonstreamdb-v3/{ => moonstreamdbv3}/alembic/env.py (100%) rename moonstreamdb-v3/{ => moonstreamdbv3}/alembic/script.py.mako (100%) rename moonstreamdb-v3/{ => moonstreamdbv3}/alembic/versions/994e614b5500_tables_initial_generation.py (100%) diff --git a/moonstreamdb-v3/alembic/README b/moonstreamdb-v3/moonstreamdbv3/alembic/README similarity index 100% rename from moonstreamdb-v3/alembic/README rename to moonstreamdb-v3/moonstreamdbv3/alembic/README diff --git a/moonstreamdb-v3/alembic/env.py b/moonstreamdb-v3/moonstreamdbv3/alembic/env.py similarity index 100% rename from moonstreamdb-v3/alembic/env.py rename to moonstreamdb-v3/moonstreamdbv3/alembic/env.py diff --git a/moonstreamdb-v3/alembic/script.py.mako b/moonstreamdb-v3/moonstreamdbv3/alembic/script.py.mako similarity index 100% rename from moonstreamdb-v3/alembic/script.py.mako rename to moonstreamdb-v3/moonstreamdbv3/alembic/script.py.mako diff --git a/moonstreamdb-v3/alembic/versions/994e614b5500_tables_initial_generation.py b/moonstreamdb-v3/moonstreamdbv3/alembic/versions/994e614b5500_tables_initial_generation.py similarity index 100% rename from moonstreamdb-v3/alembic/versions/994e614b5500_tables_initial_generation.py rename to moonstreamdb-v3/moonstreamdbv3/alembic/versions/994e614b5500_tables_initial_generation.py From 5030865ef1e28902c6aaac4632f495394b19d699 Mon Sep 17 00:00:00 2001 From: kompotkot Date: Thu, 28 Mar 2024 08:20:41 +0000 Subject: [PATCH 6/8] Allow to specify schema in engine --- moonstreamdb-v3/moonstreamdbv3/db.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/moonstreamdb-v3/moonstreamdbv3/db.py b/moonstreamdb-v3/moonstreamdbv3/db.py index a4d733ab..9bb47505 100644 --- a/moonstreamdb-v3/moonstreamdbv3/db.py +++ b/moonstreamdb-v3/moonstreamdbv3/db.py @@ -5,7 +5,7 @@ Moonstream database connection. import logging import os from contextlib import contextmanager -from typing import Generator +from typing import Generator, Optional from sqlalchemy import create_engine from sqlalchemy.orm import Session, sessionmaker @@ -56,23 +56,28 @@ def create_moonstream_engine( pool_size: int, statement_timeout: int, pool_pre_ping: bool = False, + schema: Optional[str] = None, ): # Pooling: https://docs.sqlalchemy.org/en/14/core/pooling.html#sqlalchemy.pool.QueuePool # Statement timeout: https://stackoverflow.com/a/44936982 + options = f"-c statement_timeout={statement_timeout}" + if schema is not None: + options += f" -c search_path={schema}" return create_engine( url=url, pool_pre_ping=pool_pre_ping, pool_size=pool_size, - connect_args={"options": f"-c statement_timeout={statement_timeout}"}, + connect_args={"options": options}, ) class MoonstreamDBEngine: - def __init__(self) -> None: + def __init__(self, schema: Optional[str] = None) -> None: self._engine = create_moonstream_engine( url=MOONSTREAM_DB_URI, # type: ignore pool_size=MOONSTREAM_POOL_SIZE, statement_timeout=MOONSTREAM_DB_STATEMENT_TIMEOUT_MILLIS, + schema=schema, ) self._session_local = sessionmaker(bind=self.engine) @@ -106,11 +111,12 @@ class MoonstreamDBEngine: class MoonstreamDBEngineRO: - def __init__(self) -> None: + def __init__(self, schema: Optional[str] = None) -> None: self._RO_engine = create_moonstream_engine( url=MOONSTREAM_DB_URI_READ_ONLY, # type: ignore pool_size=MOONSTREAM_POOL_SIZE, statement_timeout=MOONSTREAM_DB_STATEMENT_TIMEOUT_MILLIS, + schema=schema, ) self._RO_session_local = sessionmaker(bind=self.RO_engine) From d85870b525f21c20349358a466cae2431ca8d8eb Mon Sep 17 00:00:00 2001 From: kompotkot Date: Sat, 30 Mar 2024 09:49:05 +0300 Subject: [PATCH 7/8] Starknet models --- moonstreamdb-v3/alembic.sample.ini | 2 +- moonstreamdb-v3/moonstreamdbv3/models.py | 122 ++++++++++++++++++++++- 2 files changed, 120 insertions(+), 4 deletions(-) diff --git a/moonstreamdb-v3/alembic.sample.ini b/moonstreamdb-v3/alembic.sample.ini index c10d4ca0..055dec4a 100644 --- a/moonstreamdb-v3/alembic.sample.ini +++ b/moonstreamdb-v3/alembic.sample.ini @@ -2,7 +2,7 @@ [alembic] # path to migration scripts -script_location = alembic +script_location = moonstreamdbv3/alembic # 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 diff --git a/moonstreamdb-v3/moonstreamdbv3/models.py b/moonstreamdb-v3/moonstreamdbv3/models.py index efdfc7e8..d5fa0366 100644 --- a/moonstreamdb-v3/moonstreamdbv3/models.py +++ b/moonstreamdb-v3/moonstreamdbv3/models.py @@ -127,6 +127,12 @@ class EthereumLabel(EvmBasedLabel): # type: ignore "block_number", unique=False, ), + Index( + "ix_ethereum_labels_addr_block_ts", + "address", + "block_timestamp", + unique=False, + ), ) @@ -140,6 +146,12 @@ class SepoliaLabel(EvmBasedLabel): # type: ignore "block_number", unique=False, ), + Index( + "ix_sepolia_labels_addr_block_ts", + "address", + "block_timestamp", + unique=False, + ), ) @@ -153,6 +165,12 @@ class PolygonLabel(EvmBasedLabel): # type: ignore "block_number", unique=False, ), + Index( + "ix_polygon_labels_addr_block_ts", + "address", + "block_timestamp", + unique=False, + ), ) @@ -166,6 +184,12 @@ class MumbaiLabel(EvmBasedLabel): # type: ignore "block_number", unique=False, ), + Index( + "ix_mumbai_labels_addr_block_ts", + "address", + "block_timestamp", + unique=False, + ), ) @@ -179,6 +203,12 @@ class XDaiLabel(EvmBasedLabel): # type: ignore "block_number", unique=False, ), + Index( + "ix_xdai_labels_addr_block_ts", + "address", + "block_timestamp", + unique=False, + ), ) @@ -192,6 +222,12 @@ class WyrmLabel(EvmBasedLabel): # type: ignore "block_number", unique=False, ), + Index( + "ix_wyrm_labels_addr_block_ts", + "address", + "block_timestamp", + unique=False, + ), ) @@ -205,19 +241,31 @@ class ZkSyncEraLabel(EvmBasedLabel): # type: ignore "block_number", unique=False, ), + Index( + "ix_zksync_era_labels_addr_block_ts", + "address", + "block_timestamp", + unique=False, + ), ) -class ZkSyncEraTestnetLabel(EvmBasedLabel): # type: ignore - __tablename__ = "zksync_era_testnet_labels" +class ZkSyncEraSepoliaLabel(EvmBasedLabel): # type: ignore + __tablename__ = "zksync_era_sepolia_labels" __table_args__ = ( Index( - "ix_zksync_era_testnet_labels_addr_block_num", + "ix_zksync_era_sepolia_labels_addr_block_num", "address", "block_number", unique=False, ), + Index( + "ix_zksync_era_sepolia_labels_addr_block_ts", + "address", + "block_timestamp", + unique=False, + ), ) @@ -231,6 +279,12 @@ class BaseLabel(EvmBasedLabel): # type: ignore "block_number", unique=False, ), + Index( + "ix_base_labels_addr_block_ts", + "address", + "block_timestamp", + unique=False, + ), ) @@ -244,6 +298,12 @@ class ArbitrumNovaLabel(EvmBasedLabel): # type: ignore "block_number", unique=False, ), + Index( + "ix_arbitrum_nova_labels_addr_block_ts", + "address", + "block_timestamp", + unique=False, + ), ) @@ -257,6 +317,12 @@ class ArbitrumSepoliaLabel(EvmBasedLabel): # type: ignore "block_number", unique=False, ), + Index( + "ix_arbitrum_sepolia_labels_addr_block_ts", + "address", + "block_timestamp", + unique=False, + ), ) @@ -270,6 +336,12 @@ class XaiLabel(EvmBasedLabel): # type: ignore "block_number", unique=False, ), + Index( + "ix_xai_labels_addr_block_ts", + "address", + "block_timestamp", + unique=False, + ), ) @@ -283,4 +355,48 @@ class XaiSepoliaLabel(EvmBasedLabel): # type: ignore "block_number", unique=False, ), + Index( + "ix_xai_sepolia_labels_addr_block_ts", + "address", + "block_timestamp", + unique=False, + ), + ) + + +class StarknetLabel(EvmBasedLabel): # type: ignore + __tablename__ = "starknet_labels" + + __table_args__ = ( + Index( + "ix_starknet_labels_addr_block_num", + "address", + "block_number", + unique=False, + ), + Index( + "ix_starknet_labels_addr_block_ts", + "address", + "block_timestamp", + unique=False, + ), + ) + + +class StarknetSepoliaLabel(EvmBasedLabel): # type: ignore + __tablename__ = "starknet_sepolia_labels" + + __table_args__ = ( + Index( + "ix_starknet_sepolia_labels_addr_block_num", + "address", + "block_number", + unique=False, + ), + Index( + "ix_starknet_sepolia_labels_addr_block_ts", + "address", + "block_timestamp", + unique=False, + ), ) From 640a8d12a0dcc5bc660ea1b4179428b8733d2736 Mon Sep 17 00:00:00 2001 From: kompotkot Date: Mon, 1 Apr 2024 13:17:50 +0000 Subject: [PATCH 8/8] Updated migration with starknet and avalanche --- moonstreamdb-v3/moonstreamdbv3/alembic/env.py | 16 +- .../994e614b5500_tables_initial_generation.py | 229 +++++++++++++----- moonstreamdb-v3/moonstreamdbv3/models.py | 57 +++-- moonstreamdb-v3/moonstreamdbv3/version.txt | 2 +- 4 files changed, 221 insertions(+), 83 deletions(-) diff --git a/moonstreamdb-v3/moonstreamdbv3/alembic/env.py b/moonstreamdb-v3/moonstreamdbv3/alembic/env.py index d46ce5c6..df4c573a 100644 --- a/moonstreamdb-v3/moonstreamdbv3/alembic/env.py +++ b/moonstreamdb-v3/moonstreamdbv3/alembic/env.py @@ -32,13 +32,17 @@ from moonstreamdbv3.models import ( PolygonLabel, MumbaiLabel, XDaiLabel, - WyrmLabel, ZkSyncEraLabel, - ZkSyncEraTestnetLabel, + ZkSyncEraSepoliaLabel, BaseLabel, ArbitrumNovaLabel, ArbitrumSepoliaLabel, + XaiLabel, XaiSepoliaLabel, + AvalancheLabel, + AvalancheFujiLabel, + StarknetLabel, + StarknetSepoliaLabel, ) @@ -49,13 +53,17 @@ def include_symbol(tablename, schema): PolygonLabel.__tablename__, MumbaiLabel.__tablename__, XDaiLabel.__tablename__, - WyrmLabel.__tablename__, ZkSyncEraLabel.__tablename__, - ZkSyncEraTestnetLabel.__tablename__, + ZkSyncEraSepoliaLabel.__tablename__, BaseLabel.__tablename__, ArbitrumNovaLabel.__tablename__, ArbitrumSepoliaLabel.__tablename__, + XaiLabel.__tablename__, XaiSepoliaLabel.__tablename__, + AvalancheLabel.__tablename__, + AvalancheFujiLabel.__tablename__, + StarknetLabel.__tablename__, + StarknetSepoliaLabel.__tablename__, } diff --git a/moonstreamdb-v3/moonstreamdbv3/alembic/versions/994e614b5500_tables_initial_generation.py b/moonstreamdb-v3/moonstreamdbv3/alembic/versions/994e614b5500_tables_initial_generation.py index 4b971275..b902c582 100644 --- a/moonstreamdb-v3/moonstreamdbv3/alembic/versions/994e614b5500_tables_initial_generation.py +++ b/moonstreamdb-v3/moonstreamdbv3/alembic/versions/994e614b5500_tables_initial_generation.py @@ -209,33 +209,6 @@ def upgrade() -> None: op.create_index(op.f('ix_sepolia_labels_label_type'), 'sepolia_labels', ['label_type'], unique=False) op.create_index(op.f('ix_sepolia_labels_origin_address'), 'sepolia_labels', ['origin_address'], unique=False) op.create_index(op.f('ix_sepolia_labels_transaction_hash'), 'sepolia_labels', ['transaction_hash'], unique=False) - op.create_table('wyrm_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.VARCHAR(length=64), nullable=True), - sa.Column('origin_address', sa.VARCHAR(length=64), nullable=True), - sa.Column('address', sa.VARCHAR(length=64), nullable=True), - 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_wyrm_labels')), - sa.UniqueConstraint('id', name=op.f('uq_wyrm_labels_id')) - ) - op.create_index('ix_wyrm_labels_addr_block_num', 'wyrm_labels', ['address', 'block_number'], unique=False) - op.create_index(op.f('ix_wyrm_labels_address'), 'wyrm_labels', ['address'], unique=False) - op.create_index(op.f('ix_wyrm_labels_block_number'), 'wyrm_labels', ['block_number'], unique=False) - op.create_index(op.f('ix_wyrm_labels_caller_address'), 'wyrm_labels', ['caller_address'], unique=False) - op.create_index(op.f('ix_wyrm_labels_label'), 'wyrm_labels', ['label'], unique=False) - op.create_index(op.f('ix_wyrm_labels_label_name'), 'wyrm_labels', ['label_name'], unique=False) - op.create_index(op.f('ix_wyrm_labels_label_type'), 'wyrm_labels', ['label_type'], unique=False) - op.create_index(op.f('ix_wyrm_labels_origin_address'), 'wyrm_labels', ['origin_address'], unique=False) - op.create_index(op.f('ix_wyrm_labels_transaction_hash'), 'wyrm_labels', ['transaction_hash'], unique=False) op.create_table('xai_labels', sa.Column('id', sa.UUID(), nullable=False), sa.Column('label', sa.VARCHAR(length=256), nullable=False), @@ -344,7 +317,7 @@ def upgrade() -> None: op.create_index(op.f('ix_zksync_era_labels_label_type'), 'zksync_era_labels', ['label_type'], unique=False) op.create_index(op.f('ix_zksync_era_labels_origin_address'), 'zksync_era_labels', ['origin_address'], unique=False) op.create_index(op.f('ix_zksync_era_labels_transaction_hash'), 'zksync_era_labels', ['transaction_hash'], unique=False) - op.create_table('zksync_era_testnet_labels', + op.create_table('zksync_era_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), @@ -359,33 +332,141 @@ def upgrade() -> None: 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_zksync_era_testnet_labels')), - sa.UniqueConstraint('id', name=op.f('uq_zksync_era_testnet_labels_id')) + sa.PrimaryKeyConstraint('id', name=op.f('pk_zksync_era_sepolia_labels')), + sa.UniqueConstraint('id', name=op.f('uq_zksync_era_sepolia_labels_id')) ) - op.create_index('ix_zksync_era_testnet_labels_addr_block_num', 'zksync_era_testnet_labels', ['address', 'block_number'], unique=False) - op.create_index(op.f('ix_zksync_era_testnet_labels_address'), 'zksync_era_testnet_labels', ['address'], unique=False) - op.create_index(op.f('ix_zksync_era_testnet_labels_block_number'), 'zksync_era_testnet_labels', ['block_number'], unique=False) - op.create_index(op.f('ix_zksync_era_testnet_labels_caller_address'), 'zksync_era_testnet_labels', ['caller_address'], unique=False) - op.create_index(op.f('ix_zksync_era_testnet_labels_label'), 'zksync_era_testnet_labels', ['label'], unique=False) - op.create_index(op.f('ix_zksync_era_testnet_labels_label_name'), 'zksync_era_testnet_labels', ['label_name'], unique=False) - op.create_index(op.f('ix_zksync_era_testnet_labels_label_type'), 'zksync_era_testnet_labels', ['label_type'], unique=False) - op.create_index(op.f('ix_zksync_era_testnet_labels_origin_address'), 'zksync_era_testnet_labels', ['origin_address'], unique=False) - op.create_index(op.f('ix_zksync_era_testnet_labels_transaction_hash'), 'zksync_era_testnet_labels', ['transaction_hash'], unique=False) + op.create_index('ix_zksync_era_sepolia_labels_addr_block_num', 'zksync_era_sepolia_labels', ['address', 'block_number'], unique=False) + op.create_index(op.f('ix_zksync_era_sepolia_labels_address'), 'zksync_era_sepolia_labels', ['address'], unique=False) + op.create_index(op.f('ix_zksync_era_sepolia_labels_block_number'), 'zksync_era_sepolia_labels', ['block_number'], unique=False) + op.create_index(op.f('ix_zksync_era_sepolia_labels_caller_address'), 'zksync_era_sepolia_labels', ['caller_address'], unique=False) + op.create_index(op.f('ix_zksync_era_sepolia_labels_label'), 'zksync_era_sepolia_labels', ['label'], unique=False) + op.create_index(op.f('ix_zksync_era_sepolia_labels_label_name'), 'zksync_era_sepolia_labels', ['label_name'], unique=False) + op.create_index(op.f('ix_zksync_era_sepolia_labels_label_type'), 'zksync_era_sepolia_labels', ['label_type'], unique=False) + op.create_index(op.f('ix_zksync_era_sepolia_labels_origin_address'), 'zksync_era_sepolia_labels', ['origin_address'], unique=False) + op.create_index(op.f('ix_zksync_era_sepolia_labels_transaction_hash'), 'zksync_era_sepolia_labels', ['transaction_hash'], unique=False) + op.create_table('avalanche_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.VARCHAR(length=64), nullable=True), + sa.Column('origin_address', sa.VARCHAR(length=64), nullable=True), + sa.Column('address', sa.VARCHAR(length=64), nullable=True), + 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_avalanche_labels')), + sa.UniqueConstraint('id', name=op.f('uq_avalanche_labels_id')) + ) + op.create_index('ix_avalanche_labels_addr_block_num', 'avalanche_labels', ['address', 'block_number'], unique=False) + op.create_index(op.f('ix_avalanche_labels_address'), 'avalanche_labels', ['address'], unique=False) + op.create_index(op.f('ix_avalanche_labels_block_number'), 'avalanche_labels', ['block_number'], unique=False) + op.create_index(op.f('ix_avalanche_labels_caller_address'), 'avalanche_labels', ['caller_address'], unique=False) + op.create_index(op.f('ix_avalanche_labels_label'), 'avalanche_labels', ['label'], unique=False) + op.create_index(op.f('ix_avalanche_labels_label_name'), 'avalanche_labels', ['label_name'], unique=False) + op.create_index(op.f('ix_avalanche_labels_label_type'), 'avalanche_labels', ['label_type'], unique=False) + op.create_index(op.f('ix_avalanche_labels_origin_address'), 'avalanche_labels', ['origin_address'], unique=False) + op.create_index(op.f('ix_avalanche_labels_transaction_hash'), 'avalanche_labels', ['transaction_hash'], unique=False) + op.create_table('avalanche_fuji_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.VARCHAR(length=64), nullable=True), + sa.Column('origin_address', sa.VARCHAR(length=64), nullable=True), + sa.Column('address', sa.VARCHAR(length=64), nullable=True), + 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_avalanche_fuji_labels')), + sa.UniqueConstraint('id', name=op.f('uq_avalanche_fuji_labels_id')) + ) + op.create_index('ix_avalanche_fuji_labels_addr_block_num', 'avalanche_fuji_labels', ['address', 'block_number'], unique=False) + op.create_index(op.f('ix_avalanche_fuji_labels_address'), 'avalanche_fuji_labels', ['address'], unique=False) + op.create_index(op.f('ix_avalanche_fuji_labels_block_number'), 'avalanche_fuji_labels', ['block_number'], unique=False) + op.create_index(op.f('ix_avalanche_fuji_labels_caller_address'), 'avalanche_fuji_labels', ['caller_address'], unique=False) + op.create_index(op.f('ix_avalanche_fuji_labels_label'), 'avalanche_fuji_labels', ['label'], unique=False) + op.create_index(op.f('ix_avalanche_fuji_labels_label_name'), 'avalanche_fuji_labels', ['label_name'], unique=False) + op.create_index(op.f('ix_avalanche_fuji_labels_label_type'), 'avalanche_fuji_labels', ['label_type'], unique=False) + op.create_index(op.f('ix_avalanche_fuji_labels_origin_address'), 'avalanche_fuji_labels', ['origin_address'], unique=False) + op.create_index(op.f('ix_avalanche_fuji_labels_transaction_hash'), 'avalanche_fuji_labels', ['transaction_hash'], unique=False) + op.create_table('starknet_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.VARCHAR(length=64), nullable=True), + sa.Column('origin_address', sa.VARCHAR(length=64), nullable=True), + sa.Column('address', sa.VARCHAR(length=64), nullable=True), + 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_starknet_labels')), + sa.UniqueConstraint('id', name=op.f('uq_starknet_labels_id')) + ) + op.create_index('ix_starknet_labels_addr_block_num', 'starknet_labels', ['address', 'block_number'], unique=False) + op.create_index(op.f('ix_starknet_labels_address'), 'starknet_labels', ['address'], unique=False) + op.create_index(op.f('ix_starknet_labels_block_number'), 'starknet_labels', ['block_number'], unique=False) + op.create_index(op.f('ix_starknet_labels_caller_address'), 'starknet_labels', ['caller_address'], unique=False) + op.create_index(op.f('ix_starknet_labels_label'), 'starknet_labels', ['label'], unique=False) + op.create_index(op.f('ix_starknet_labels_label_name'), 'starknet_labels', ['label_name'], unique=False) + op.create_index(op.f('ix_starknet_labels_label_type'), 'starknet_labels', ['label_type'], unique=False) + op.create_index(op.f('ix_starknet_labels_origin_address'), 'starknet_labels', ['origin_address'], unique=False) + op.create_index(op.f('ix_starknet_labels_transaction_hash'), 'starknet_labels', ['transaction_hash'], unique=False) + op.create_table('starknet_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.VARCHAR(length=64), nullable=True), + sa.Column('origin_address', sa.VARCHAR(length=64), nullable=True), + sa.Column('address', sa.VARCHAR(length=64), nullable=True), + 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_starknet_sepolia_labels')), + sa.UniqueConstraint('id', name=op.f('uq_starknet_sepolia_labels_id')) + ) + op.create_index('ix_starknet_sepolia_labels_addr_block_num', 'starknet_sepolia_labels', ['address', 'block_number'], unique=False) + op.create_index(op.f('ix_starknet_sepolia_labels_address'), 'starknet_sepolia_labels', ['address'], unique=False) + op.create_index(op.f('ix_starknet_sepolia_labels_block_number'), 'starknet_sepolia_labels', ['block_number'], unique=False) + op.create_index(op.f('ix_starknet_sepolia_labels_caller_address'), 'starknet_sepolia_labels', ['caller_address'], unique=False) + op.create_index(op.f('ix_starknet_sepolia_labels_label'), 'starknet_sepolia_labels', ['label'], unique=False) + op.create_index(op.f('ix_starknet_sepolia_labels_label_name'), 'starknet_sepolia_labels', ['label_name'], unique=False) + op.create_index(op.f('ix_starknet_sepolia_labels_label_type'), 'starknet_sepolia_labels', ['label_type'], unique=False) + op.create_index(op.f('ix_starknet_sepolia_labels_origin_address'), 'starknet_sepolia_labels', ['origin_address'], unique=False) + op.create_index(op.f('ix_starknet_sepolia_labels_transaction_hash'), 'starknet_sepolia_labels', ['transaction_hash'], unique=False) # ### end Alembic commands ### def downgrade() -> None: # ### commands auto generated by Alembic - please adjust! ### - op.drop_index(op.f('ix_zksync_era_testnet_labels_transaction_hash'), table_name='zksync_era_testnet_labels') - op.drop_index(op.f('ix_zksync_era_testnet_labels_origin_address'), table_name='zksync_era_testnet_labels') - op.drop_index(op.f('ix_zksync_era_testnet_labels_label_type'), table_name='zksync_era_testnet_labels') - op.drop_index(op.f('ix_zksync_era_testnet_labels_label_name'), table_name='zksync_era_testnet_labels') - op.drop_index(op.f('ix_zksync_era_testnet_labels_label'), table_name='zksync_era_testnet_labels') - op.drop_index(op.f('ix_zksync_era_testnet_labels_caller_address'), table_name='zksync_era_testnet_labels') - op.drop_index(op.f('ix_zksync_era_testnet_labels_block_number'), table_name='zksync_era_testnet_labels') - op.drop_index(op.f('ix_zksync_era_testnet_labels_address'), table_name='zksync_era_testnet_labels') - op.drop_index('ix_zksync_era_testnet_labels_addr_block_num', table_name='zksync_era_testnet_labels') - op.drop_table('zksync_era_testnet_labels') + op.drop_index(op.f('ix_zksync_era_sepolia_labels_transaction_hash'), table_name='zksync_era_sepolia_labels') + op.drop_index(op.f('ix_zksync_era_sepolia_labels_origin_address'), table_name='zksync_era_sepolia_labels') + op.drop_index(op.f('ix_zksync_era_sepolia_labels_label_type'), table_name='zksync_era_sepolia_labels') + op.drop_index(op.f('ix_zksync_era_sepolia_labels_label_name'), table_name='zksync_era_sepolia_labels') + op.drop_index(op.f('ix_zksync_era_sepolia_labels_label'), table_name='zksync_era_sepolia_labels') + op.drop_index(op.f('ix_zksync_era_sepolia_labels_caller_address'), table_name='zksync_era_sepolia_labels') + op.drop_index(op.f('ix_zksync_era_sepolia_labels_block_number'), table_name='zksync_era_sepolia_labels') + op.drop_index(op.f('ix_zksync_era_sepolia_labels_address'), table_name='zksync_era_sepolia_labels') + op.drop_index('ix_zksync_era_sepolia_labels_addr_block_num', table_name='zksync_era_sepolia_labels') + op.drop_table('zksync_era_sepolia_labels') op.drop_index(op.f('ix_zksync_era_labels_transaction_hash'), table_name='zksync_era_labels') op.drop_index(op.f('ix_zksync_era_labels_origin_address'), table_name='zksync_era_labels') op.drop_index(op.f('ix_zksync_era_labels_label_type'), table_name='zksync_era_labels') @@ -426,16 +507,6 @@ def downgrade() -> None: op.drop_index(op.f('ix_xai_labels_address'), table_name='xai_labels') op.drop_index('ix_xai_labels_addr_block_num', table_name='xai_labels') op.drop_table('xai_labels') - op.drop_index(op.f('ix_wyrm_labels_transaction_hash'), table_name='wyrm_labels') - op.drop_index(op.f('ix_wyrm_labels_origin_address'), table_name='wyrm_labels') - op.drop_index(op.f('ix_wyrm_labels_label_type'), table_name='wyrm_labels') - op.drop_index(op.f('ix_wyrm_labels_label_name'), table_name='wyrm_labels') - op.drop_index(op.f('ix_wyrm_labels_label'), table_name='wyrm_labels') - op.drop_index(op.f('ix_wyrm_labels_caller_address'), table_name='wyrm_labels') - op.drop_index(op.f('ix_wyrm_labels_block_number'), table_name='wyrm_labels') - op.drop_index(op.f('ix_wyrm_labels_address'), table_name='wyrm_labels') - op.drop_index('ix_wyrm_labels_addr_block_num', table_name='wyrm_labels') - op.drop_table('wyrm_labels') op.drop_index(op.f('ix_sepolia_labels_transaction_hash'), table_name='sepolia_labels') op.drop_index(op.f('ix_sepolia_labels_origin_address'), table_name='sepolia_labels') op.drop_index(op.f('ix_sepolia_labels_label_type'), table_name='sepolia_labels') @@ -506,4 +577,44 @@ def downgrade() -> None: op.drop_index(op.f('ix_arbitrum_nova_labels_address'), table_name='arbitrum_nova_labels') op.drop_index('ix_arbitrum_nova_labels_addr_block_num', table_name='arbitrum_nova_labels') op.drop_table('arbitrum_nova_labels') + op.drop_index(op.f('ix_avalanche_labels_transaction_hash'), table_name='avalanche_labels') + op.drop_index(op.f('ix_avalanche_labels_origin_address'), table_name='avalanche_labels') + op.drop_index(op.f('ix_avalanche_labels_label_type'), table_name='avalanche_labels') + op.drop_index(op.f('ix_avalanche_labels_label_name'), table_name='avalanche_labels') + op.drop_index(op.f('ix_avalanche_labels_label'), table_name='avalanche_labels') + op.drop_index(op.f('ix_avalanche_labels_caller_address'), table_name='avalanche_labels') + op.drop_index(op.f('ix_avalanche_labels_block_number'), table_name='avalanche_labels') + op.drop_index(op.f('ix_avalanche_labels_address'), table_name='avalanche_labels') + op.drop_index('ix_avalanche_labels_addr_block_num', table_name='avalanche_labels') + op.drop_table('avalanche_labels') + op.drop_index(op.f('ix_avalanche_fuji_labels_transaction_hash'), table_name='avalanche_fuji_labels') + op.drop_index(op.f('ix_avalanche_fuji_labels_origin_address'), table_name='avalanche_fuji_labels') + op.drop_index(op.f('ix_avalanche_fuji_labels_label_type'), table_name='avalanche_fuji_labels') + op.drop_index(op.f('ix_avalanche_fuji_labels_label_name'), table_name='avalanche_fuji_labels') + op.drop_index(op.f('ix_avalanche_fuji_labels_label'), table_name='avalanche_fuji_labels') + op.drop_index(op.f('ix_avalanche_fuji_labels_caller_address'), table_name='avalanche_fuji_labels') + op.drop_index(op.f('ix_avalanche_fuji_labels_block_number'), table_name='avalanche_fuji_labels') + op.drop_index(op.f('ix_avalanche_fuji_labels_address'), table_name='avalanche_fuji_labels') + op.drop_index('ix_avalanche_fuji_labels_addr_block_num', table_name='avalanche_fuji_labels') + op.drop_table('avalanche_fuji_labels') + op.drop_index(op.f('ix_starknet_labels_transaction_hash'), table_name='starknet_labels') + op.drop_index(op.f('ix_starknet_labels_origin_address'), table_name='starknet_labels') + op.drop_index(op.f('ix_starknet_labels_label_type'), table_name='starknet_labels') + op.drop_index(op.f('ix_starknet_labels_label_name'), table_name='starknet_labels') + op.drop_index(op.f('ix_starknet_labels_label'), table_name='starknet_labels') + op.drop_index(op.f('ix_starknet_labels_caller_address'), table_name='starknet_labels') + op.drop_index(op.f('ix_starknet_labels_block_number'), table_name='starknet_labels') + op.drop_index(op.f('ix_starknet_labels_address'), table_name='starknet_labels') + op.drop_index('ix_starknet_labels_addr_block_num', table_name='starknet_labels') + op.drop_table('starknet_labels') + op.drop_index(op.f('ix_starknet_sepolia_labels_transaction_hash'), table_name='starknet_sepolia_labels') + op.drop_index(op.f('ix_starknet_sepolia_labels_origin_address'), table_name='starknet_sepolia_labels') + op.drop_index(op.f('ix_starknet_sepolia_labels_label_type'), table_name='starknet_sepolia_labels') + op.drop_index(op.f('ix_starknet_sepolia_labels_label_name'), table_name='starknet_sepolia_labels') + op.drop_index(op.f('ix_starknet_sepolia_labels_label'), table_name='starknet_sepolia_labels') + op.drop_index(op.f('ix_starknet_sepolia_labels_caller_address'), table_name='starknet_sepolia_labels') + op.drop_index(op.f('ix_starknet_sepolia_labels_block_number'), table_name='starknet_sepolia_labels') + op.drop_index(op.f('ix_starknet_sepolia_labels_address'), table_name='starknet_sepolia_labels') + op.drop_index('ix_starknet_sepolia_labels_addr_block_num', table_name='starknet_sepolia_labels') + op.drop_table('starknet_sepolia_labels') # ### end Alembic commands ### diff --git a/moonstreamdb-v3/moonstreamdbv3/models.py b/moonstreamdb-v3/moonstreamdbv3/models.py index d5fa0366..ae6b9e5c 100644 --- a/moonstreamdb-v3/moonstreamdbv3/models.py +++ b/moonstreamdb-v3/moonstreamdbv3/models.py @@ -212,25 +212,6 @@ class XDaiLabel(EvmBasedLabel): # type: ignore ) -class WyrmLabel(EvmBasedLabel): # type: ignore - __tablename__ = "wyrm_labels" - - __table_args__ = ( - Index( - "ix_wyrm_labels_addr_block_num", - "address", - "block_number", - unique=False, - ), - Index( - "ix_wyrm_labels_addr_block_ts", - "address", - "block_timestamp", - unique=False, - ), - ) - - class ZkSyncEraLabel(EvmBasedLabel): # type: ignore __tablename__ = "zksync_era_labels" @@ -364,6 +345,44 @@ class XaiSepoliaLabel(EvmBasedLabel): # type: ignore ) +class AvalancheLabel(EvmBasedLabel): # type: ignore + __tablename__ = "avalanche_labels" + + __table_args__ = ( + Index( + "ix_avalanche_labels_addr_block_num", + "address", + "block_number", + unique=False, + ), + Index( + "ix_avalanche_labels_addr_block_ts", + "address", + "block_timestamp", + unique=False, + ), + ) + + +class AvalancheFujiLabel(EvmBasedLabel): # type: ignore + __tablename__ = "avalanche_fuji_labels" + + __table_args__ = ( + Index( + "ix_avalanche_fuji_labels_addr_block_num", + "address", + "block_number", + unique=False, + ), + Index( + "ix_avalanche_fuji_labels_addr_block_ts", + "address", + "block_timestamp", + unique=False, + ), + ) + + class StarknetLabel(EvmBasedLabel): # type: ignore __tablename__ = "starknet_labels" diff --git a/moonstreamdb-v3/moonstreamdbv3/version.txt b/moonstreamdb-v3/moonstreamdbv3/version.txt index a2268e2d..8a9ecc2e 100644 --- a/moonstreamdb-v3/moonstreamdbv3/version.txt +++ b/moonstreamdb-v3/moonstreamdbv3/version.txt @@ -1 +1 @@ -0.3.1 \ No newline at end of file +0.0.1 \ No newline at end of file