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"], + }, +)