From 002ef76ecc10f0ce8c371b8b8fc33efda6c4bcd7 Mon Sep 17 00:00:00 2001 From: Luke Van Seters Date: Fri, 6 Aug 2021 13:05:47 -0400 Subject: [PATCH] Store trace addresses as arrays --- ...e_change_trace_addresses_to_array_types.py | 50 +++++++++++++++++++ mev_inspect/models/classified_traces.py | 4 +- mev_inspect/models/swaps.py | 4 +- 3 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 alembic/versions/7eec417a4f3e_change_trace_addresses_to_array_types.py diff --git a/alembic/versions/7eec417a4f3e_change_trace_addresses_to_array_types.py b/alembic/versions/7eec417a4f3e_change_trace_addresses_to_array_types.py new file mode 100644 index 0000000..b3d4f29 --- /dev/null +++ b/alembic/versions/7eec417a4f3e_change_trace_addresses_to_array_types.py @@ -0,0 +1,50 @@ +"""Change trace addresses to array types + +Revision ID: 7eec417a4f3e +Revises: 9d8c69b3dccb +Create Date: 2021-08-06 15:58:04.556762 + +""" +import sqlalchemy as sa +from alembic import op + + +# revision identifiers, used by Alembic. +revision = "7eec417a4f3e" +down_revision = "9d8c69b3dccb" +branch_labels = None +depends_on = None + + +def upgrade(): + op.drop_constraint("swaps_pkey", "swaps") + op.drop_column("swaps", "trace_address") + op.add_column("swaps", sa.Column("trace_address", sa.ARRAY(sa.Integer))) + op.create_primary_key("swaps_pkey", "swaps", ["transaction_hash", "trace_address"]) + + op.drop_constraint("classified_traces_pkey", "classified_traces") + op.drop_column("classified_traces", "trace_address") + op.add_column("classified_traces", sa.Column("trace_address", sa.ARRAY(sa.Integer))) + op.create_primary_key( + "classified_traces_pkey", + "classified_traces", + ["transaction_hash", "trace_address"], + ) + + +def downgrade(): + op.drop_constraint("swaps_pkey", "swaps") + op.drop_column("swaps", "trace_address") + op.add_column("swaps", sa.Column("trace_address", sa.String)) + + op.create_primary_key("swaps_pkey", "swaps", ["transaction_hash", "trace_address"]) + + op.drop_constraint("classified_traces_pkey", "classified_traces") + op.drop_column("classified_traces", "trace_address") + op.add_column("classified_traces", sa.Column("trace_address", sa.String)) + + op.create_primary_key( + "classified_traces_pkey", + "classified_traces", + ["transaction_hash", "trace_address"], + ) diff --git a/mev_inspect/models/classified_traces.py b/mev_inspect/models/classified_traces.py index bf898e0..529bf25 100644 --- a/mev_inspect/models/classified_traces.py +++ b/mev_inspect/models/classified_traces.py @@ -1,4 +1,4 @@ -from sqlalchemy import Column, JSON, Numeric, String +from sqlalchemy import Column, JSON, Numeric, String, ARRAY, Integer from .base import Base @@ -10,7 +10,7 @@ class ClassifiedTraceModel(Base): block_number = Column(Numeric, nullable=False) classification = Column(String, nullable=False) trace_type = Column(String, nullable=False) - trace_address = Column(String, nullable=False) + trace_address = Column(ARRAY(Integer), nullable=False) protocol = Column(String, nullable=True) abi_name = Column(String, nullable=True) function_name = Column(String, nullable=True) diff --git a/mev_inspect/models/swaps.py b/mev_inspect/models/swaps.py index 0e80e25..318aa24 100644 --- a/mev_inspect/models/swaps.py +++ b/mev_inspect/models/swaps.py @@ -1,4 +1,4 @@ -from sqlalchemy import Column, Numeric, String +from sqlalchemy import Column, Numeric, String, ARRAY, Integer from .base import Base @@ -9,7 +9,7 @@ class SwapModel(Base): abi_name = Column(String, nullable=False) transaction_hash = Column(String, primary_key=True) block_number = Column(Numeric, nullable=False) - trace_address = Column(String, primary_key=True) + trace_address = Column(ARRAY(Integer), nullable=False) protocol = Column(String, nullable=True) pool_address = Column(String, nullable=False) from_address = Column(String, nullable=False)