Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add zksync era model. #910

Merged
merged 1 commit into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
270 changes: 270 additions & 0 deletions moonstreamdb/alembic/versions/0f8ee1ebb45f_zksync_era_mainnet_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,270 @@
"""ZkSync Era mainnet model

Revision ID: 0f8ee1ebb45f
Revises: e4a796c0407d
Create Date: 2023-08-29 03:24:33.102586

"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = "0f8ee1ebb45f"
down_revision = "e4a796c0407d"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###

### zksync_era_blocks ###
op.create_table(
"zksync_era_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.Column("mix_hash", sa.VARCHAR(length=256), nullable=True),
sa.Column("sha3_uncles", sa.VARCHAR(length=256), nullable=True),
sa.Column("l1_batch_number", sa.BigInteger(), nullable=True),
sa.Column("l1_batch_timestamp", sa.BigInteger(), nullable=True),
sa.PrimaryKeyConstraint("block_number", name=op.f("pk_zksync_era_blocks")),
)
op.create_index(
op.f("ix_zksync_era_blocks_block_number"),
"zksync_era_blocks",
["block_number"],
unique=True,
)
op.create_index(
op.f("ix_zksync_era_blocks_hash"), "zksync_era_blocks", ["hash"], unique=False
)
op.create_index(
op.f("ix_zksync_era_blocks_timestamp"),
"zksync_era_blocks",
["timestamp"],
unique=False,
)

### zksync_era_labels ###
op.create_table(
"zksync_era_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_zksync_era_labels")),
sa.UniqueConstraint("id", name=op.f("uq_zksync_era_labels_id")),
)
op.create_index(
op.f("ix_zksync_era_labels_address"),
"zksync_era_labels",
["address"],
unique=False,
)
op.create_index(
"ix_zksync_era_labels_address_block_number",
"zksync_era_labels",
["address", "block_number"],
unique=False,
)
op.create_index(
"ix_zksync_era_labels_address_block_timestamp",
"zksync_era_labels",
["address", "block_timestamp"],
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_block_timestamp"),
"zksync_era_labels",
["block_timestamp"],
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_transaction_hash"),
"zksync_era_labels",
["transaction_hash"],
unique=False,
)

### zksync_era_transactions ###
op.create_table(
"zksync_era_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.Column("l1_batch_number", sa.BigInteger(), nullable=True),
sa.Column("l1_batch_tx_index", sa.BigInteger(), nullable=True),
sa.ForeignKeyConstraint(
["block_number"],
["zksync_era_blocks.block_number"],
name=op.f("fk_zksync_era_transactions_block_number_zksync_era_blocks"),
ondelete="CASCADE",
),
sa.PrimaryKeyConstraint("hash", name=op.f("pk_zksync_era_transactions")),
)
op.create_index(
op.f("ix_zksync_era_transactions_block_number"),
"zksync_era_transactions",
["block_number"],
unique=False,
)
op.create_index(
op.f("ix_zksync_era_transactions_from_address"),
"zksync_era_transactions",
["from_address"],
unique=False,
)
op.create_index(
op.f("ix_zksync_era_transactions_gas"),
"zksync_era_transactions",
["gas"],
unique=False,
)
op.create_index(
op.f("ix_zksync_era_transactions_gas_price"),
"zksync_era_transactions",
["gas_price"],
unique=False,
)
op.create_index(
op.f("ix_zksync_era_transactions_hash"),
"zksync_era_transactions",
["hash"],
unique=True,
)
op.create_index(
op.f("ix_zksync_era_transactions_to_address"),
"zksync_era_transactions",
["to_address"],
unique=False,
)
op.create_index(
op.f("ix_zksync_era_transactions_value"),
"zksync_era_transactions",
["value"],
unique=False,
)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###

### zksync_era_transactions ###
op.drop_index(
op.f("ix_zksync_era_transactions_value"), table_name="zksync_era_transactions"
)
op.drop_index(
op.f("ix_zksync_era_transactions_to_address"),
table_name="zksync_era_transactions",
)
op.drop_index(
op.f("ix_zksync_era_transactions_hash"), table_name="zksync_era_transactions"
)
op.drop_index(
op.f("ix_zksync_era_transactions_gas_price"),
table_name="zksync_era_transactions",
)
op.drop_index(
op.f("ix_zksync_era_transactions_gas"), table_name="zksync_era_transactions"
)
op.drop_index(
op.f("ix_zksync_era_transactions_from_address"),
table_name="zksync_era_transactions",
)
op.drop_index(
op.f("ix_zksync_era_transactions_block_number"),
table_name="zksync_era_transactions",
)

### zksync_era_labels ###
op.drop_table("zksync_era_transactions")
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_label"), table_name="zksync_era_labels")
op.drop_index(
op.f("ix_zksync_era_labels_block_timestamp"), table_name="zksync_era_labels"
)
op.drop_index(
op.f("ix_zksync_era_labels_block_number"), table_name="zksync_era_labels"
)
op.drop_index(
"ix_zksync_era_labels_address_block_timestamp", table_name="zksync_era_labels"
)
op.drop_index(
"ix_zksync_era_labels_address_block_number", table_name="zksync_era_labels"
)
op.drop_index(op.f("ix_zksync_era_labels_address"), table_name="zksync_era_labels")
op.drop_table("zksync_era_labels")

### zksync_era_blocks ###
op.drop_index(
op.f("ix_zksync_era_blocks_timestamp"), table_name="zksync_era_blocks"
)
op.drop_index(op.f("ix_zksync_era_blocks_hash"), table_name="zksync_era_blocks")
op.drop_index(
op.f("ix_zksync_era_blocks_block_number"), table_name="zksync_era_blocks"
)
op.drop_table("zksync_era_blocks")
# ### end Alembic commands ###
Loading
Loading