Skip to content

Commit

Permalink
refactor(iota-indexer): add db schema diagram in README.md (#1594)
Browse files Browse the repository at this point in the history
* refactor(iota-indexer): add db schema diagram in README.md

* refactor(iota-indexer): revert to previous formatting

* refactor(iota-indexer): add margin to diagram

* refactor(iota-indexer): make ERD diagram more concise

* refactor(iota-indexer):  describe all db schema in a separate schema.md file

* refactor(iota-indexer): remove redundant tables from schema.md

* refactor(iota-indexer): fix spacing in schema.rs

* refactor(iota-indexer): from md files with drprint

* refactor(iota-indexer): use list instead of tables in schema.md

* refactor(iota-indexer): add index names in schema.md
  • Loading branch information
sergiupopescu199 authored Aug 12, 2024
1 parent b90b83a commit 77de6db
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 0 deletions.
4 changes: 4 additions & 0 deletions crates/iota-indexer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ Iota indexer is an off-fullnode service to serve data from Iota protocol, includ
> - Nodes expose the `NameServiceConfig` API, whereas indexer instances do not.
> - Indexer instance expose the `ExtendedApi`, but nodes do not.
## Database Schema

For more in depth information check the [Database Schema](./schema.md).

## Steps to run locally

### Prerequisites
Expand Down
4 changes: 4 additions & 0 deletions crates/iota-indexer/database_schema.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
95 changes: 95 additions & 0 deletions crates/iota-indexer/schema.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# Database Schema

The Indexer pulls checkpoint data from the full node and populates the tables shown in the ERD diagram:

![Database Schema](./database_schema.svg)

> **NOTE**
>
> Since all tables are populated from checkpoint data the entities are closely related, in the `SQL` files the foreign keys are not specified, a manual study of data is needed to understand all relations.
>
> Migrations are generated by diesel cli, the basic schema can be found [schema.rs](src/schema.rs).
> For more in depth understanding of the database tables, go to [migrations](migrations) folder, in the contained `SQL` the indexes, partitions & constraints are declared.
>
> - Tables `objects_history` & `transactions` have partitions, each partition is created based on `checkpoint_sequence_number` (related form the `checkpoints` table) it goes from `0` to `MAXVALUE`
> - `__diesel_schema_migrations` table is managed by `diesel` cli when applying migrations
## Indexes

### Table `checkpoints`

| Index name | Keys |
| ------------------ | ---------------------- |
| checkpoints_epoch | epoch, sequence_number |
| checkpoints_digest | checkpoint_digest |

### Table `events`

| Index name | Keys |
| --------------------------------- | ----------------------------------------------------------------------- |
| events_package | package, tx_sequence_number, event_sequence_number |
| events_package_module | package, module, tx_sequence_number, event_sequence_number |
| events_event_type | event_type, text_pattern_ops, tx_sequence_number, event_sequence_number |
| events_checkpoint_sequence_number | checkpoint_sequence_number |

### Table `objects`

| Index name | Keys | Condition |
| ---------------------------------- | -------------------------- | --------------------------------------------------------- |
| objects_owner | owner_type, owner_id | WHERE owner_type BETWEEN 1 AND 2 AND owner_id IS NOT NULL |
| objects_coin | owner_id, coin_type | WHERE coin_type IS NOT NULL AND owner_type = 1 |
| objects_checkpoint_sequence_number | checkpoint_sequence_number | |
| objects_type | object_type | |

### Table `objects_snapshot`

| Index name | Keys | Condition |
| ------------------------------------------- | ------------------------------- | --------------------------------------------------------- |
| objects_snapshot_checkpoint_sequence_number | checkpoint_sequence_number | |
| objects_snapshot_coin | owner_id, coin_type, object_id | WHERE coin_type IS NOT NULL AND owner_type = 1 |
| objects_snapshot_type | object_type, object_id | |
| objects_snapshot_owner | owner_type, owner_id, object_id | WHERE owner_type BETWEEN 1 AND 2 AND owner_id IS NOT NULL |

### Table `objects_history`

| Index name | Keys | Condition |
| --------------------- | ------------------------------------------------ | --------------------------------------------------------- |
| objects_history_owner | checkpoint_sequence_number, owner_type, owner_id | WHERE owner_type BETWEEN 1 AND 2 AND owner_id IS NOT NULL |
| objects_history_coin | checkpoint_sequence_number, owner_id, coin_type | WHERE coin_type IS NOT NULL AND owner_type = 1 |
| objects_history_type | checkpoint_sequence_number, object_type | |

### Table `transactions`

| Index name | Keys | Condition |
| --------------------------------------- | -------------------------- | -------------------------- |
| transactions_transaction_digest | transaction_digest | |
| transactions_checkpoint_sequence_number | checkpoint_sequence_number | |
| transactions_transaction_kind | transaction_kind | WHERE transaction_kind = 1 |

### Table `tx_calls`

| Index name | Keys |
| --------------------------- | ----------------------------------------- |
| tx_calls_module | package, module, tx_sequence_number |
| tx_calls_func | package, module, func, tx_sequence_number |
| tx_calls_tx_sequence_number | tx_sequence_number |

### Table `tx_senders`

| Index name | Keys | Condition |
| ----------------------------------- | ------------------ | --------- |
| tx_senders_tx_sequence_number_index | tx_sequence_number | ASC |

### Tables `tx_recipients`

| Index name | Keys | Condition |
| -------------------------------------- | ------------------ | --------- |
| tx_recipients_tx_sequence_number_index | tx_sequence_number | ASC |

## Partitions

### Tables `transactions`, `objects_history`

| Keys | Condition |
| :------------------------: | :-------------------------------: |
| checkpoint_sequence_number | FOR VALUES FROM (0) TO (MAXVALUE) |

0 comments on commit 77de6db

Please sign in to comment.