110 lines
5.1 KiB
Python
110 lines
5.1 KiB
Python
"""initial migration
|
|
|
|
Revision ID: b61d5f5a1ded
|
|
Revises:
|
|
Create Date: 2023-10-05 12:00:00.000000
|
|
|
|
"""
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision = 'b61d5f5a1ded'
|
|
down_revision = None
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade():
|
|
# Create blocks table
|
|
op.create_table(
|
|
'blocks',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('slot', sa.Integer(), nullable=False),
|
|
sa.Column('blockhash', sa.String(), nullable=False),
|
|
sa.Column('parent_blockhash', sa.String(), nullable=False),
|
|
sa.Column('timestamp', sa.DateTime(), nullable=True),
|
|
sa.Column('processed', sa.Boolean(), nullable=True),
|
|
sa.PrimaryKeyConstraint('id'),
|
|
)
|
|
op.create_index(op.f('ix_blocks_blockhash'), 'blocks', ['blockhash'], unique=True)
|
|
op.create_index(op.f('ix_blocks_id'), 'blocks', ['id'], unique=False)
|
|
op.create_index(op.f('ix_blocks_parent_blockhash'), 'blocks', ['parent_blockhash'], unique=False)
|
|
op.create_index(op.f('ix_blocks_slot'), 'blocks', ['slot'], unique=True)
|
|
|
|
# Create transactions table
|
|
op.create_table(
|
|
'transactions',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('signature', sa.String(), nullable=False),
|
|
sa.Column('block_id', sa.Integer(), nullable=True),
|
|
sa.Column('timestamp', sa.DateTime(), nullable=True),
|
|
sa.Column('fee', sa.Integer(), nullable=True),
|
|
sa.Column('status', sa.String(), nullable=True),
|
|
sa.Column('raw_data', sa.Text(), nullable=True),
|
|
sa.ForeignKeyConstraint(['block_id'], ['blocks.slot'], ),
|
|
sa.PrimaryKeyConstraint('id'),
|
|
)
|
|
op.create_index(op.f('ix_transactions_id'), 'transactions', ['id'], unique=False)
|
|
op.create_index(op.f('ix_transactions_signature'), 'transactions', ['signature'], unique=True)
|
|
|
|
# Create token_transfers table
|
|
op.create_table(
|
|
'token_transfers',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('transaction_id', sa.Integer(), nullable=True),
|
|
sa.Column('token_address', sa.String(), nullable=True),
|
|
sa.Column('from_address', sa.String(), nullable=True),
|
|
sa.Column('to_address', sa.String(), nullable=True),
|
|
sa.Column('amount', sa.Float(), nullable=True),
|
|
sa.Column('program_id', sa.String(), nullable=True),
|
|
sa.Column('timestamp', sa.DateTime(), nullable=True),
|
|
sa.ForeignKeyConstraint(['transaction_id'], ['transactions.id'], ),
|
|
sa.PrimaryKeyConstraint('id'),
|
|
)
|
|
op.create_index(op.f('ix_token_transfers_from_address'), 'token_transfers', ['from_address'], unique=False)
|
|
op.create_index(op.f('ix_token_transfers_id'), 'token_transfers', ['id'], unique=False)
|
|
op.create_index(op.f('ix_token_transfers_program_id'), 'token_transfers', ['program_id'], unique=False)
|
|
op.create_index(op.f('ix_token_transfers_to_address'), 'token_transfers', ['to_address'], unique=False)
|
|
op.create_index(op.f('ix_token_transfers_token_address'), 'token_transfers', ['token_address'], unique=False)
|
|
|
|
# Create arbitrage_events table
|
|
op.create_table(
|
|
'arbitrage_events',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('transaction_id', sa.Integer(), nullable=True),
|
|
sa.Column('profit_token_address', sa.String(), nullable=True),
|
|
sa.Column('profit_amount', sa.Float(), nullable=True),
|
|
sa.Column('profit_usd', sa.Float(), nullable=True),
|
|
sa.Column('path', sa.Text(), nullable=True),
|
|
sa.Column('confidence_score', sa.Float(), nullable=True),
|
|
sa.Column('detected_at', sa.DateTime(), nullable=True),
|
|
sa.ForeignKeyConstraint(['transaction_id'], ['transactions.id'], ),
|
|
sa.PrimaryKeyConstraint('id'),
|
|
)
|
|
op.create_index(op.f('ix_arbitrage_events_id'), 'arbitrage_events', ['id'], unique=False)
|
|
op.create_index(op.f('ix_arbitrage_events_profit_token_address'), 'arbitrage_events', ['profit_token_address'], unique=False)
|
|
|
|
|
|
def downgrade():
|
|
op.drop_index(op.f('ix_arbitrage_events_profit_token_address'), table_name='arbitrage_events')
|
|
op.drop_index(op.f('ix_arbitrage_events_id'), table_name='arbitrage_events')
|
|
op.drop_table('arbitrage_events')
|
|
|
|
op.drop_index(op.f('ix_token_transfers_token_address'), table_name='token_transfers')
|
|
op.drop_index(op.f('ix_token_transfers_to_address'), table_name='token_transfers')
|
|
op.drop_index(op.f('ix_token_transfers_program_id'), table_name='token_transfers')
|
|
op.drop_index(op.f('ix_token_transfers_id'), table_name='token_transfers')
|
|
op.drop_index(op.f('ix_token_transfers_from_address'), table_name='token_transfers')
|
|
op.drop_table('token_transfers')
|
|
|
|
op.drop_index(op.f('ix_transactions_signature'), table_name='transactions')
|
|
op.drop_index(op.f('ix_transactions_id'), table_name='transactions')
|
|
op.drop_table('transactions')
|
|
|
|
op.drop_index(op.f('ix_blocks_slot'), table_name='blocks')
|
|
op.drop_index(op.f('ix_blocks_parent_blockhash'), table_name='blocks')
|
|
op.drop_index(op.f('ix_blocks_id'), table_name='blocks')
|
|
op.drop_index(op.f('ix_blocks_blockhash'), table_name='blocks')
|
|
op.drop_table('blocks') |