Automated Action cae8527a4b s
2025-05-28 22:44:22 +00:00

89 lines
3.9 KiB
Python

"""add instruction tables
Revision ID: f9c3a857d9e6
Revises: b61d5f5a1ded
Create Date: 2023-10-10 12:00:00.000000
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'f9c3a857d9e6'
down_revision = 'b61d5f5a1ded'
branch_labels = None
depends_on = None
def upgrade():
# Create instructions table
op.create_table(
'instructions',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('transaction_id', sa.Integer(), nullable=True),
sa.Column('program_id', sa.String(), nullable=True),
sa.Column('instruction_type', sa.String(), nullable=True),
sa.Column('instruction_index', sa.Integer(), nullable=True),
sa.Column('accounts', sa.Text(), nullable=True),
sa.Column('data', sa.Text(), nullable=True),
sa.Column('parsed_data', sa.JSON(), nullable=True),
sa.ForeignKeyConstraint(['transaction_id'], ['transactions.id'], ),
sa.PrimaryKeyConstraint('id'),
)
op.create_index(op.f('ix_instructions_id'), 'instructions', ['id'], unique=False)
op.create_index(op.f('ix_instructions_program_id'), 'instructions', ['program_id'], unique=False)
op.create_index(op.f('ix_instructions_instruction_type'), 'instructions', ['instruction_type'], unique=False)
# Create swaps table
op.create_table(
'swaps',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('transaction_id', sa.Integer(), nullable=True),
sa.Column('instruction_id', sa.Integer(), nullable=True),
sa.Column('program_id', sa.String(), nullable=True),
sa.Column('token_in_address', sa.String(), nullable=True),
sa.Column('token_out_address', sa.String(), nullable=True),
sa.Column('amount_in', sa.Float(), nullable=True),
sa.Column('amount_out', sa.Float(), nullable=True),
sa.Column('user_account', sa.String(), nullable=True),
sa.Column('timestamp', sa.DateTime(), nullable=True),
sa.ForeignKeyConstraint(['instruction_id'], ['instructions.id'], ),
sa.ForeignKeyConstraint(['transaction_id'], ['transactions.id'], ),
sa.PrimaryKeyConstraint('id'),
)
op.create_index(op.f('ix_swaps_id'), 'swaps', ['id'], unique=False)
op.create_index(op.f('ix_swaps_program_id'), 'swaps', ['program_id'], unique=False)
op.create_index(op.f('ix_swaps_token_in_address'), 'swaps', ['token_in_address'], unique=False)
op.create_index(op.f('ix_swaps_token_out_address'), 'swaps', ['token_out_address'], unique=False)
op.create_index(op.f('ix_swaps_user_account'), 'swaps', ['user_account'], unique=False)
# Add instruction_id to token_transfers
op.add_column('token_transfers', sa.Column('instruction_id', sa.Integer(), nullable=True))
op.create_foreign_key(None, 'token_transfers', 'instructions', ['instruction_id'], ['id'])
# Add swap_sequence to arbitrage_events
op.add_column('arbitrage_events', sa.Column('swap_sequence', sa.Text(), nullable=True))
def downgrade():
# Remove swap_sequence from arbitrage_events
op.drop_column('arbitrage_events', 'swap_sequence')
# Remove instruction_id from token_transfers
op.drop_constraint(None, 'token_transfers', type_='foreignkey')
op.drop_column('token_transfers', 'instruction_id')
# Drop swaps table
op.drop_index(op.f('ix_swaps_user_account'), table_name='swaps')
op.drop_index(op.f('ix_swaps_token_out_address'), table_name='swaps')
op.drop_index(op.f('ix_swaps_token_in_address'), table_name='swaps')
op.drop_index(op.f('ix_swaps_program_id'), table_name='swaps')
op.drop_index(op.f('ix_swaps_id'), table_name='swaps')
op.drop_table('swaps')
# Drop instructions table
op.drop_index(op.f('ix_instructions_instruction_type'), table_name='instructions')
op.drop_index(op.f('ix_instructions_program_id'), table_name='instructions')
op.drop_index(op.f('ix_instructions_id'), table_name='instructions')
op.drop_table('instructions')