Skip to content

feat(db): update indexes and add nbtc_withdrawal#55

Merged
robert-zaremba merged 4 commits intomasterfrom
robert/scheme
Aug 8, 2025
Merged

feat(db): update indexes and add nbtc_withdrawal#55
robert-zaremba merged 4 commits intomasterfrom
robert/scheme

Conversation

@robert-zaremba
Copy link
Contributor

@robert-zaremba robert-zaremba commented Aug 7, 2025

Description

  • removed unncecessary indexes
  • added timestamp to indexes when relevant
  • added withdraw table.

Summary by Sourcery

Refine the BTC indexer schema by cleaning up obsolete indexes, enhancing existing indexes with timestamps, and introducing the nbtc_withdrawal table to support withdrawal tracking.

New Features:

  • Add nbtc_withdrawal table to track nBTC withdrawal transactions from SUI to BTC

Enhancements:

  • Remove redundant indexes (e.g., processed_blocks_height) from nbtc_txs and processed_blocks tables
  • Augment nbtc_txs_sui_recipient index with created_at timestamp for more efficient queries

Signed-off-by: Robert Zaremba <robert@zaremba.ch>
@robert-zaremba robert-zaremba self-assigned this Aug 7, 2025
Copilot AI review requested due to automatic review settings August 7, 2025 16:43
@robert-zaremba robert-zaremba requested a review from a team as a code owner August 7, 2025 16:43
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Aug 7, 2025

Reviewer's Guide

This PR refactors existing database indexes by removing redundant single-column indexes and introducing timestamp-inclusive composite indexes, and introduces a new nbtc_withdrawal table to track nBTC withdrawal transactions.

Entity relationship diagram for updated nBTC tables

erDiagram
    nbtc_txs {
        TEXT tx_id PK
        TEXT sui_recipient
        INTEGER status
        INTEGER created_at
        INTEGER updated_at
    }
    nbtc_withdrawal {
        TEXT sui_tx_id PK
        TEXT sender
        INTEGER amount
        TEXT recipient
        TEXT note
        INTEGER sent_at
        TEXT btc_tx_id
        INTEGER status
    }
    processed_blocks {
        INTEGER height PK
        INTEGER processed_at
    }
    %% Relationships (if any) are not explicit in schema, so not shown
Loading

Class diagram for new nbtc_withdrawal table

classDiagram
    class nbtc_withdrawal {
        +TEXT sui_tx_id
        +TEXT sender
        +INTEGER amount
        +TEXT recipient
        +TEXT note
        +INTEGER sent_at
        +TEXT btc_tx_id
        +INTEGER status
    }
Loading

Class diagram for updated nbtc_txs indexes

classDiagram
    class nbtc_txs {
        +TEXT tx_id
        +TEXT sui_recipient
        +INTEGER status
        +INTEGER created_at
        +INTEGER updated_at
        <<INDEX>> status
        <<INDEX>> sui_recipient, created_at
    }
Loading

Class diagram for updated processed_blocks indexes

classDiagram
    class processed_blocks {
        +INTEGER height
        +INTEGER processed_at
        <<INDEX REMOVED>> height
    }
Loading

File-Level Changes

Change Details Files
Refactor existing indexes to include timestamps and remove redundancies
  • Dropped processed_blocks(height) index
  • Removed single-column nbtc_txs(sui_recipient) index
  • Added composite index on nbtc_txs(sui_recipient, created_at)
packages/btcindexer/db/migrations/0001_initial_schema.sql
Add nbtc_withdrawal table for tracking withdrawal lifecycle
  • Defined nbtc_withdrawal schema with sui_tx_id, sender, amount, recipient, note, sent_at, btc_tx_id, status
  • Created composite index on (sender, recipient, sent_at)
  • Documented status codes for withdrawal stages
packages/btcindexer/db/migrations/0001_initial_schema.sql

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors database indexes and adds support for nBTC withdrawals. The changes optimize index structure by adding timestamp-based sorting and remove unnecessary indexes.

  • Optimizes existing indexes by adding timestamp columns for better query performance
  • Adds a new nbtc_withdrawal table to track withdrawal transactions from SUI to Bitcoin
  • Removes two redundant indexes on processed blocks and updates the recipient index structure

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @robert-zaremba - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Signed-off-by: Robert Zaremba <robert@zaremba.ch>
Copy link
Contributor

@sczembor sczembor left a comment

Choose a reason for hiding this comment

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

pre-approve

Signed-off-by: Robert Zaremba <robert@zaremba.ch>
@robert-zaremba robert-zaremba merged commit 677df84 into master Aug 8, 2025
10 checks passed
@robert-zaremba robert-zaremba deleted the robert/scheme branch August 8, 2025 10:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants