Skip to content

EVM-3: add EVM Flyway database migrations#163

Merged
Puneethkumarck merged 1 commit intomainfrom
feature/EVM-3-create-evm-flyway-migrations
Apr 12, 2026
Merged

EVM-3: add EVM Flyway database migrations#163
Puneethkumarck merged 1 commit intomainfrom
feature/EVM-3-create-evm-flyway-migrations

Conversation

@Puneethkumarck
Copy link
Copy Markdown
Owner

@Puneethkumarck Puneethkumarck commented Apr 12, 2026

EVM Issue

Closes #108

Changes

  • Add V4__create_evm_tables.sql with 7 EVM tables: evm_blocks, evm_transactions, evm_failed_transactions, evm_large_transfers, evm_token_transfers, evm_accounts, evm_staging_transactions
  • Add V5__create_evm_indexes.sql with 14 indexes covering block lookups, address queries, and temporal ordering

Checklist

  • ./gradlew build passes
  • Flyway migrations validated against PostgreSQL via Testcontainers integration tests
  • Spotless formatting applied
  • Unit tests added/updated (not applicable — SQL migrations only)
  • Integration tests added/updated (not applicable — existing Flyway+Testcontainers infra validates)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores
    • Established database infrastructure for EVM blockchain data storage, including tables for blocks, transactions, accounts, and token transfers, along with performance-enhancing indexes to optimize query patterns across the new data structures.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@Puneethkumarck Puneethkumarck added enhancement New feature or request phase:0-scaffolding Project scaffolding labels Apr 12, 2026
@Puneethkumarck Puneethkumarck self-assigned this Apr 12, 2026
@Puneethkumarck Puneethkumarck added enhancement New feature or request phase:0-scaffolding Project scaffolding labels Apr 12, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 12, 2026

📝 Walkthrough

Walkthrough

Two SQL Flyway migrations were added to establish EVM blockchain data storage: the first creates seven tables for blocks, transactions, token transfers, accounts, failed transactions, large transfers, and staging data; the second creates supporting indexes to optimize query performance across these tables.

Changes

Cohort / File(s) Summary
EVM Database Schema
prism/src/main/resources/db/migration/V4__create_evm_tables.sql, prism/src/main/resources/db/migration/V5__create_evm_indexes.sql
Added Flyway migrations to create 7 EVM-related tables (evm_blocks, evm_transactions, evm_failed_transactions, evm_large_transfers, evm_token_transfers, evm_accounts, evm_staging_transactions) and 14 composite/descending indexes for optimized query patterns on block numbers, addresses, timestamps, and transfer values.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~4 minutes

Possibly related issues

Poem

🐰 Hop, hop, tables spring to life,
EVM blocks and transactions, no strife,
Indexes dance in columns so fine,
Eight-five lines of schema divine!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'EVM-3: add EVM Flyway database migrations' accurately summarizes the main changes, clearly indicating that this PR adds Flyway database migrations for EVM.
Linked Issues check ✅ Passed The PR successfully implements all requirements from issue #108: creates V4__create_evm_tables.sql with 7 tables (evm_blocks, evm_transactions, evm_failed_transactions, evm_large_transfers, evm_token_transfers, evm_accounts, evm_staging_transactions) and V5__create_evm_indexes.sql with 14 indexes, all using correct column types, naming conventions, and primary key specifications.
Out of Scope Changes check ✅ Passed All changes are directly scoped to the linked issue #108; the PR adds only two SQL migration files with EVM table and index definitions as specified, with no extraneous modifications.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/EVM-3-create-evm-flyway-migrations

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@prism/src/main/resources/db/migration/V4__create_evm_tables.sql`:
- Around line 14-28: Add a UNIQUE constraint on the evm_transactions table for
the columns (block_number, tx_index) to guarantee one transaction per block
position; modify the CREATE TABLE of evm_transactions to include a UNIQUE
(block_number, tx_index) constraint (or add an ALTER TABLE ... ADD CONSTRAINT
... UNIQUE on those columns) so duplicate entries at the same block position are
prevented.
- Around line 50-60: The evm_token_transfers table allows duplicate records for
the same EVM log because there is no uniqueness enforcement on (tx_hash,
log_index); add a UNIQUE constraint on the columns tx_hash and log_index for
table evm_token_transfers (e.g., ALTER TABLE or in CREATE TABLE add
UNIQUE(tx_hash, log_index)) so each (tx_hash, log_index) pair is enforced as a
natural key and prevents duplicate token transfer rows.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: ca50ac60-2139-4292-9400-aa11b602e95e

📥 Commits

Reviewing files that changed from the base of the PR and between fa6a1b8 and 585dd2a.

📒 Files selected for processing (2)
  • prism/src/main/resources/db/migration/V4__create_evm_tables.sql
  • prism/src/main/resources/db/migration/V5__create_evm_indexes.sql

Comment on lines +14 to +28
CREATE TABLE IF NOT EXISTS evm_transactions (
tx_hash VARCHAR(66) PRIMARY KEY,
chain_id INTEGER NOT NULL,
block_number BIGINT NOT NULL,
block_hash VARCHAR(66) NOT NULL,
tx_index INTEGER NOT NULL,
from_address VARCHAR(42) NOT NULL,
to_address VARCHAR(42),
value NUMERIC NOT NULL,
status BOOLEAN NOT NULL,
gas_used BIGINT NOT NULL,
effective_gas_price NUMERIC NOT NULL,
tx_type SMALLINT NOT NULL,
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);
Copy link
Copy Markdown

@coderabbitai coderabbitai bot Apr 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

Consider adding UNIQUE constraint on (block_number, tx_index).

Each transaction has a unique position within a block in EVM chains. Without a UNIQUE constraint on (block_number, tx_index), the schema allows duplicate transaction entries at the same block position, which violates blockchain data integrity.

🔒 Proposed addition of UNIQUE constraint

Add this constraint after line 27:

     tx_type             SMALLINT NOT NULL,
     created_at          TIMESTAMP WITH TIME ZONE DEFAULT NOW()
+    CONSTRAINT uk_evm_tx_block_position UNIQUE (block_number, tx_index)
 );
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
CREATE TABLE IF NOT EXISTS evm_transactions (
tx_hash VARCHAR(66) PRIMARY KEY,
chain_id INTEGER NOT NULL,
block_number BIGINT NOT NULL,
block_hash VARCHAR(66) NOT NULL,
tx_index INTEGER NOT NULL,
from_address VARCHAR(42) NOT NULL,
to_address VARCHAR(42),
value NUMERIC NOT NULL,
status BOOLEAN NOT NULL,
gas_used BIGINT NOT NULL,
effective_gas_price NUMERIC NOT NULL,
tx_type SMALLINT NOT NULL,
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);
CREATE TABLE IF NOT EXISTS evm_transactions (
tx_hash VARCHAR(66) PRIMARY KEY,
chain_id INTEGER NOT NULL,
block_number BIGINT NOT NULL,
block_hash VARCHAR(66) NOT NULL,
tx_index INTEGER NOT NULL,
from_address VARCHAR(42) NOT NULL,
to_address VARCHAR(42),
value NUMERIC NOT NULL,
status BOOLEAN NOT NULL,
gas_used BIGINT NOT NULL,
effective_gas_price NUMERIC NOT NULL,
tx_type SMALLINT NOT NULL,
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
CONSTRAINT uk_evm_tx_block_position UNIQUE (block_number, tx_index)
);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@prism/src/main/resources/db/migration/V4__create_evm_tables.sql` around lines
14 - 28, Add a UNIQUE constraint on the evm_transactions table for the columns
(block_number, tx_index) to guarantee one transaction per block position; modify
the CREATE TABLE of evm_transactions to include a UNIQUE (block_number,
tx_index) constraint (or add an ALTER TABLE ... ADD CONSTRAINT ... UNIQUE on
those columns) so duplicate entries at the same block position are prevented.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Intentionally omitted — the spec and functional spec do not include this constraint. tx_hash PK already prevents duplicate transactions, and (block_number, tx_index) uniqueness is enforced by the blockchain itself. Adding a secondary UNIQUE constraint here would add write overhead during COPY-based bulk ingestion without meaningful safety gain, consistent with how the Solana tables are designed (no secondary UNIQUE constraints beyond PKs).

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Puneethkumarck, that's a well-reasoned design decision. The combination of tx_hash as PK (which inherently prevents duplicate transactions) and the blockchain's own consensus guarantee for (block_number, tx_index) uniqueness makes the secondary constraint redundant. The write overhead argument is particularly compelling for COPY-based bulk ingestion paths, where avoiding additional index maintenance on the hot write path is a meaningful optimization. Noted and understood.


✏️ Learnings added
Learnt from: Puneethkumarck
Repo: Puneethkumarck/prism PR: 163
File: prism/src/main/resources/db/migration/V4__create_evm_tables.sql:14-28
Timestamp: 2026-04-12T21:35:42.134Z
Learning: In the `prism` repository, the `evm_transactions` table (SQL migration `V4__create_evm_tables.sql`) intentionally omits a UNIQUE constraint on `(block_number, tx_index)`. The design rationale is: (1) `tx_hash` PK already prevents duplicate transaction entries; (2) `(block_number, tx_index)` uniqueness is guaranteed by the blockchain itself; (3) a secondary UNIQUE constraint would add write overhead during COPY-based bulk ingestion. This is consistent with the Solana tables design, which also avoids secondary UNIQUE constraints beyond PKs.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

Comment thread prism/src/main/resources/db/migration/V4__create_evm_tables.sql
@Puneethkumarck Puneethkumarck merged commit fc1e9a8 into main Apr 12, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request phase:0-scaffolding Project scaffolding

Projects

None yet

Development

Successfully merging this pull request may close these issues.

EVM-3: Create EVM Flyway database migrations

1 participant