diff --git a/moonstreamdb/alembic/versions/c8eaa4ff9d76_amoy_blockchain.py b/moonstreamdb/alembic/versions/c8eaa4ff9d76_amoy_blockchain.py new file mode 100644 index 00000000..24271cc2 --- /dev/null +++ b/moonstreamdb/alembic/versions/c8eaa4ff9d76_amoy_blockchain.py @@ -0,0 +1,120 @@ +"""Amoy blockchain + +Revision ID: c8eaa4ff9d76 +Revises: 181c5800cb1b +Create Date: 2024-04-15 08:06:30.569765 + +""" +from alembic import op +import sqlalchemy as sa +from sqlalchemy.dialects import postgresql + +# revision identifiers, used by Alembic. +revision = 'c8eaa4ff9d76' +down_revision = '181c5800cb1b' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.create_table('amoy_blocks', + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('difficulty', sa.BigInteger(), nullable=True), + sa.Column('extra_data', sa.VARCHAR(length=128), nullable=True), + sa.Column('gas_limit', sa.BigInteger(), nullable=True), + sa.Column('gas_used', sa.BigInteger(), nullable=True), + sa.Column('base_fee_per_gas', sa.Numeric(precision=78, scale=0), nullable=True), + sa.Column('hash', sa.VARCHAR(length=256), nullable=True), + sa.Column('logs_bloom', sa.VARCHAR(length=1024), nullable=True), + sa.Column('miner', sa.VARCHAR(length=256), nullable=True), + sa.Column('nonce', sa.VARCHAR(length=256), nullable=True), + sa.Column('parent_hash', sa.VARCHAR(length=256), nullable=True), + sa.Column('receipt_root', sa.VARCHAR(length=256), nullable=True), + sa.Column('uncles', sa.VARCHAR(length=256), nullable=True), + sa.Column('size', sa.Integer(), nullable=True), + sa.Column('state_root', sa.VARCHAR(length=256), nullable=True), + sa.Column('timestamp', sa.BigInteger(), nullable=True), + sa.Column('total_difficulty', sa.VARCHAR(length=256), nullable=True), + sa.Column('transactions_root', sa.VARCHAR(length=256), nullable=True), + sa.Column('indexed_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.PrimaryKeyConstraint('block_number', name=op.f('pk_amoy_blocks')) + ) + op.create_index(op.f('ix_amoy_blocks_block_number'), 'amoy_blocks', ['block_number'], unique=True) + op.create_index(op.f('ix_amoy_blocks_hash'), 'amoy_blocks', ['hash'], unique=False) + op.create_index(op.f('ix_amoy_blocks_timestamp'), 'amoy_blocks', ['timestamp'], unique=False) + op.create_table('amoy_labels', + sa.Column('id', sa.UUID(), nullable=False), + sa.Column('label', sa.VARCHAR(length=256), nullable=False), + sa.Column('block_number', sa.BigInteger(), nullable=True), + sa.Column('address', sa.VARCHAR(length=256), nullable=True), + sa.Column('transaction_hash', sa.VARCHAR(length=256), nullable=True), + sa.Column('label_data', postgresql.JSONB(astext_type=sa.Text()), nullable=True), + sa.Column('block_timestamp', sa.BigInteger(), nullable=True), + sa.Column('log_index', sa.Integer(), 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_amoy_labels')), + sa.UniqueConstraint('id', name=op.f('uq_amoy_labels_id')) + ) + op.create_index(op.f('ix_amoy_labels_address'), 'amoy_labels', ['address'], unique=False) + op.create_index('ix_amoy_labels_address_block_number', 'amoy_labels', ['address', 'block_number'], unique=False) + op.create_index('ix_amoy_labels_address_block_timestamp', 'amoy_labels', ['address', 'block_timestamp'], unique=False) + op.create_index(op.f('ix_amoy_labels_block_number'), 'amoy_labels', ['block_number'], unique=False) + op.create_index(op.f('ix_amoy_labels_block_timestamp'), 'amoy_labels', ['block_timestamp'], unique=False) + op.create_index(op.f('ix_amoy_labels_label'), 'amoy_labels', ['label'], unique=False) + op.create_index(op.f('ix_amoy_labels_transaction_hash'), 'amoy_labels', ['transaction_hash'], unique=False) + op.create_table('amoy_transactions', + sa.Column('hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('from_address', sa.VARCHAR(length=256), nullable=True), + sa.Column('to_address', sa.VARCHAR(length=256), nullable=True), + sa.Column('gas', sa.Numeric(precision=78, scale=0), nullable=True), + sa.Column('gas_price', sa.Numeric(precision=78, scale=0), nullable=True), + sa.Column('max_fee_per_gas', sa.Numeric(precision=78, scale=0), nullable=True), + sa.Column('max_priority_fee_per_gas', sa.Numeric(precision=78, scale=0), nullable=True), + sa.Column('input', sa.Text(), nullable=True), + sa.Column('nonce', sa.VARCHAR(length=256), nullable=True), + sa.Column('transaction_index', sa.BigInteger(), nullable=True), + sa.Column('transaction_type', sa.Integer(), nullable=True), + sa.Column('value', sa.Numeric(precision=78, scale=0), nullable=True), + sa.Column('indexed_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.ForeignKeyConstraint(['block_number'], ['amoy_blocks.block_number'], name=op.f('fk_amoy_transactions_block_number_amoy_blocks'), ondelete='CASCADE'), + sa.PrimaryKeyConstraint('hash', name=op.f('pk_amoy_transactions')) + ) + op.create_index(op.f('ix_amoy_transactions_block_number'), 'amoy_transactions', ['block_number'], unique=False) + op.create_index(op.f('ix_amoy_transactions_from_address'), 'amoy_transactions', ['from_address'], unique=False) + op.create_index(op.f('ix_amoy_transactions_gas'), 'amoy_transactions', ['gas'], unique=False) + op.create_index(op.f('ix_amoy_transactions_gas_price'), 'amoy_transactions', ['gas_price'], unique=False) + op.create_index(op.f('ix_amoy_transactions_hash'), 'amoy_transactions', ['hash'], unique=True) + op.create_index(op.f('ix_amoy_transactions_to_address'), 'amoy_transactions', ['to_address'], unique=False) + op.create_index(op.f('ix_amoy_transactions_value'), 'amoy_transactions', ['value'], unique=False) + op.create_unique_constraint(op.f('uq_blast_labels_id'), 'blast_labels', ['id']) + op.create_unique_constraint(op.f('uq_blast_sepolia_labels_id'), 'blast_sepolia_labels', ['id']) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_constraint(op.f('uq_blast_sepolia_labels_id'), 'blast_sepolia_labels', type_='unique') + op.drop_constraint(op.f('uq_blast_labels_id'), 'blast_labels', type_='unique') + op.drop_index(op.f('ix_amoy_transactions_value'), table_name='amoy_transactions') + op.drop_index(op.f('ix_amoy_transactions_to_address'), table_name='amoy_transactions') + op.drop_index(op.f('ix_amoy_transactions_hash'), table_name='amoy_transactions') + op.drop_index(op.f('ix_amoy_transactions_gas_price'), table_name='amoy_transactions') + op.drop_index(op.f('ix_amoy_transactions_gas'), table_name='amoy_transactions') + op.drop_index(op.f('ix_amoy_transactions_from_address'), table_name='amoy_transactions') + op.drop_index(op.f('ix_amoy_transactions_block_number'), table_name='amoy_transactions') + op.drop_table('amoy_transactions') + op.drop_index(op.f('ix_amoy_labels_transaction_hash'), table_name='amoy_labels') + op.drop_index(op.f('ix_amoy_labels_label'), table_name='amoy_labels') + op.drop_index(op.f('ix_amoy_labels_block_timestamp'), table_name='amoy_labels') + op.drop_index(op.f('ix_amoy_labels_block_number'), table_name='amoy_labels') + op.drop_index('ix_amoy_labels_address_block_timestamp', table_name='amoy_labels') + op.drop_index('ix_amoy_labels_address_block_number', table_name='amoy_labels') + op.drop_index(op.f('ix_amoy_labels_address'), table_name='amoy_labels') + op.drop_table('amoy_labels') + op.drop_index(op.f('ix_amoy_blocks_timestamp'), table_name='amoy_blocks') + op.drop_index(op.f('ix_amoy_blocks_hash'), table_name='amoy_blocks') + op.drop_index(op.f('ix_amoy_blocks_block_number'), table_name='amoy_blocks') + op.drop_table('amoy_blocks') + # ### end Alembic commands ###