diff --git a/crates/iota-indexer/migrations/00000000000000_diesel_initial_setup/down.sql b/crates/iota-indexer/migrations/00000000000000_diesel_initial_setup/down.sql index a9f52609119..20c4718ff34 100644 --- a/crates/iota-indexer/migrations/00000000000000_diesel_initial_setup/down.sql +++ b/crates/iota-indexer/migrations/00000000000000_diesel_initial_setup/down.sql @@ -1,6 +1,46 @@ --- This file was automatically created by Diesel to setup helper functions --- and other internal bookkeeping. This file is safe to edit, any future --- changes will be added to existing projects as new migrations. +-- This file should undo anything in `up.sql` +-- Diesel DROP FUNCTION IF EXISTS diesel_manage_updated_at(_tbl regclass); DROP FUNCTION IF EXISTS diesel_set_updated_at(); + +-- Events +DROP TABLE IF EXISTS events; + +-- Objects +DROP TABLE IF EXISTS objects; +DROP TABLE IF EXISTS objects_history; +DROP TABLE IF EXISTS objects_snapshot; + +-- Transactions +DROP TABLE IF EXISTS transactions; + +-- Checkpoints +DROP TABLE IF EXISTS checkpoints; + +-- Epochs +DROP TABLE IF EXISTS epochs; + +-- Packages +DROP TABLE IF EXISTS packages; + +-- Tx Recipients +DROP TABLE IF EXISTS tx_recipients; + +-- Tx Senders +DROP TABLE IF EXISTS tx_senders; + +-- Tx Input Objects +DROP TABLE IF EXISTS tx_input_objects; + +-- Tx Changed Objects +DROP TABLE IF EXISTS tx_changed_objects; + +-- Tx calls +DROP TABLE IF EXISTS tx_calls; + +-- Display +DROP TABLE IF EXISTS display; + +DROP FUNCTION IF EXISTS query_cost(TEXT); +DROP PROCEDURE IF EXISTS advance_partition; \ No newline at end of file diff --git a/crates/iota-indexer/migrations/00000000000000_diesel_initial_setup/up.sql b/crates/iota-indexer/migrations/00000000000000_diesel_initial_setup/up.sql index d68895b1a7b..52f993a668d 100644 --- a/crates/iota-indexer/migrations/00000000000000_diesel_initial_setup/up.sql +++ b/crates/iota-indexer/migrations/00000000000000_diesel_initial_setup/up.sql @@ -1,21 +1,4 @@ --- This file was automatically created by Diesel to setup helper functions --- and other internal bookkeeping. This file is safe to edit, any future --- changes will be added to existing projects as new migrations. - - - - --- Sets up a trigger for the given table to automatically set a column called --- `updated_at` whenever the row is modified (unless `updated_at` was included --- in the modified columns) --- --- # Example --- --- ```sql --- CREATE TABLE users (id SERIAL PRIMARY KEY, updated_at TIMESTAMP NOT NULL DEFAULT NOW()); --- --- SELECT diesel_manage_updated_at('users'); --- ``` +-- Diesel CREATE OR REPLACE FUNCTION diesel_manage_updated_at(_tbl regclass) RETURNS VOID AS $$ BEGIN EXECUTE format('CREATE TRIGGER set_updated_at BEFORE UPDATE ON %s @@ -34,3 +17,304 @@ BEGIN RETURN NEW; END; $$ LANGUAGE plpgsql; + +-- Events +CREATE TABLE events +( + tx_sequence_number BIGINT NOT NULL, + event_sequence_number BIGINT NOT NULL, + transaction_digest bytea NOT NULL, + checkpoint_sequence_number bigint NOT NULL, + -- array of IotaAddress in bytes. All signers of the transaction. + senders bytea[] NOT NULL, + -- bytes of the entry package ID + package bytea NOT NULL, + -- entry module name + module text NOT NULL, + -- StructTag in Display format + event_type text NOT NULL, + timestamp_ms BIGINT NOT NULL, + -- bcs of the Event contents (Event.contents) + bcs BYTEA NOT NULL, + PRIMARY KEY(tx_sequence_number, event_sequence_number) +); + +CREATE INDEX events_package ON events (package, tx_sequence_number, event_sequence_number); +CREATE INDEX events_package_module ON events (package, module, tx_sequence_number, event_sequence_number); +CREATE INDEX events_event_type ON events (event_type text_pattern_ops, tx_sequence_number, event_sequence_number); +CREATE INDEX events_checkpoint_sequence_number ON events (checkpoint_sequence_number); + +-- Objects +CREATE TABLE objects ( + object_id bytea PRIMARY KEY, + object_version bigint NOT NULL, + object_digest bytea NOT NULL, + checkpoint_sequence_number bigint NOT NULL, + -- Immutable/Address/Object/Shared, see types.rs + owner_type smallint NOT NULL, + -- bytes of IotaAddress/ObjectID of the owner ID. + -- Non-null for objects with an owner: Addresso or Objects + owner_id bytea, + -- Object type + object_type text, + -- bcs serialized Object + serialized_object bytea NOT NULL, + -- Non-null when the object is a coin. + -- e.g. `0x2::iota::IOTA` + coin_type text, + -- Non-null when the object is a coin. + coin_balance bigint, + -- DynamicField/DynamicObject, see types.rs + -- Non-null when the object is a dynamic field + df_kind smallint, + -- bcs serialized DynamicFieldName + -- Non-null when the object is a dynamic field + df_name bytea, + -- object_type in DynamicFieldInfo. + df_object_type text, + -- object_id in DynamicFieldInfo. + df_object_id bytea +); + +-- OwnerType: 1: Address, 2: Object, see types.rs +CREATE INDEX objects_owner ON objects (owner_type, owner_id) WHERE owner_type BETWEEN 1 AND 2 AND owner_id IS NOT NULL; +CREATE INDEX objects_coin ON objects (owner_id, coin_type) WHERE coin_type IS NOT NULL AND owner_type = 1; +CREATE INDEX objects_checkpoint_sequence_number ON objects (checkpoint_sequence_number); +CREATE INDEX objects_type ON objects (object_type); + +-- Objects History +-- +-- similar to objects table, except that +-- 1. the primary key to store multiple object versions and partitions by checkpoint_sequence_number +-- 2. allow null values in some columns for deleted / wrapped objects +-- 3. object_status to mark the status of the object, which is either Active or WrappedOrDeleted +CREATE TABLE objects_history ( + object_id bytea NOT NULL, + object_version bigint NOT NULL, + object_status smallint NOT NULL, + object_digest bytea, + checkpoint_sequence_number bigint NOT NULL, + owner_type smallint, + owner_id bytea, + object_type text, + serialized_object bytea, + coin_type text, + coin_balance bigint, + df_kind smallint, + df_name bytea, + df_object_type text, + df_object_id bytea, + CONSTRAINT objects_history_pk PRIMARY KEY (checkpoint_sequence_number, object_id, object_version) +) PARTITION BY RANGE (checkpoint_sequence_number); +CREATE INDEX objects_history_owner ON objects_history (checkpoint_sequence_number, owner_type, owner_id) WHERE owner_type BETWEEN 1 AND 2 AND owner_id IS NOT NULL; +CREATE INDEX objects_history_coin ON objects_history (checkpoint_sequence_number, owner_id, coin_type) WHERE coin_type IS NOT NULL AND owner_type = 1; +CREATE INDEX objects_history_type ON objects_history (checkpoint_sequence_number, object_type); +-- init with first partition of the history table +CREATE TABLE objects_history_partition_0 PARTITION OF objects_history FOR VALUES FROM (0) TO (MAXVALUE); + +-- Objects Snapshot +-- +-- snapshot table by folding objects_history table until certain checkpoint, +-- effectively the snapshot of objects at the same checkpoint, +-- except that it also includes deleted or wrapped objects with the corresponding object_status. +CREATE TABLE objects_snapshot ( + object_id bytea PRIMARY KEY, + object_version bigint NOT NULL, + object_status smallint NOT NULL, + object_digest bytea, + checkpoint_sequence_number bigint NOT NULL, + owner_type smallint, + owner_id bytea, + object_type text, + serialized_object bytea, + coin_type text, + coin_balance bigint, + df_kind smallint, + df_name bytea, + df_object_type text, + df_object_id bytea +); +CREATE INDEX objects_snapshot_checkpoint_sequence_number ON objects_snapshot (checkpoint_sequence_number); +CREATE INDEX objects_snapshot_owner ON objects_snapshot (owner_type, owner_id, object_id) WHERE owner_type BETWEEN 1 AND 2 AND owner_id IS NOT NULL; +CREATE INDEX objects_snapshot_coin ON objects_snapshot (owner_id, coin_type, object_id) WHERE coin_type IS NOT NULL AND owner_type = 1; +CREATE INDEX objects_snapshot_type ON objects_snapshot (object_type, object_id); + +-- Transactions +CREATE TABLE transactions ( + tx_sequence_number BIGINT NOT NULL, + transaction_digest bytea NOT NULL, + -- bcs serialized SenderSignedData bytes + raw_transaction bytea NOT NULL, + -- bcs serialized TransactionEffects bytes + raw_effects bytea NOT NULL, + checkpoint_sequence_number BIGINT NOT NULL, + timestamp_ms BIGINT NOT NULL, + -- array of bcs serialized IndexedObjectChange bytes + object_changes bytea[] NOT NULL, + -- array of bcs serialized BalanceChange bytes + balance_changes bytea[] NOT NULL, + -- array of bcs serialized StoredEvent bytes + events bytea[] NOT NULL, + -- SystemTransaction/ProgrammableTransaction. See types.rs + transaction_kind smallint NOT NULL, + -- number of successful commands in this transaction, bound by number of command + -- in a programmaable transaction. + success_command_count smallint NOT NULL, + CONSTRAINT transactions_pkey PRIMARY KEY (tx_sequence_number, checkpoint_sequence_number) +) PARTITION BY RANGE (checkpoint_sequence_number); + +CREATE TABLE transactions_partition_0 PARTITION OF transactions FOR VALUES FROM (0) TO (MAXVALUE); +CREATE INDEX transactions_transaction_digest ON transactions (transaction_digest); +CREATE INDEX transactions_checkpoint_sequence_number ON transactions (checkpoint_sequence_number); +-- only create index for system transactions (0). See types.rs +CREATE INDEX transactions_transaction_kind ON transactions (transaction_kind) WHERE transaction_kind = 0; + +-- Checkpoints +CREATE TABLE checkpoints +( + sequence_number bigint PRIMARY KEY, + checkpoint_digest bytea NOT NULL, + epoch bigint NOT NULL, + -- total transactions in the network at the end of this checkpoint (including itself) + network_total_transactions bigint NOT NULL, + previous_checkpoint_digest bytea, + -- if this checkpoitn is the last checkpoint of an epoch + end_of_epoch boolean NOT NULL, + -- array of TranscationDigest in bytes included in this checkpoint + tx_digests bytea[] NOT NULL, + timestamp_ms BIGINT NOT NULL, + total_gas_cost BIGINT NOT NULL, + computation_cost BIGINT NOT NULL, + storage_cost BIGINT NOT NULL, + storage_rebate BIGINT NOT NULL, + non_refundable_storage_fee BIGINT NOT NULL, + -- bcs serialized Vec bytes + checkpoint_commitments bytea NOT NULL, + -- bcs serialized AggregateAuthoritySignature bytes + validator_signature bytea NOT NULL, + -- bcs serialzied EndOfEpochData bytes, if the checkpoint marks end of an epoch + end_of_epoch_data bytea +); + +CREATE INDEX checkpoints_epoch ON checkpoints (epoch, sequence_number); +CREATE INDEX checkpoints_digest ON checkpoints USING HASH (checkpoint_digest); + +-- Epochs +CREATE TABLE epochs +( + epoch BIGINT PRIMARY KEY, + first_checkpoint_id BIGINT NOT NULL, + epoch_start_timestamp BIGINT NOT NULL, + reference_gas_price BIGINT NOT NULL, + protocol_version BIGINT NOT NULL, + total_stake BIGINT NOT NULL, + storage_fund_balance BIGINT NOT NULL, + system_state bytea NOT NULL, + -- The following fields are nullable because they are filled in + -- only at the end of an epoch. + epoch_total_transactions BIGINT, + last_checkpoint_id BIGINT, + epoch_end_timestamp BIGINT, + -- The following fields are from SystemEpochInfoEvent emitted + -- **after** advancing to the next epoch + storage_charge BIGINT, + storage_rebate BIGINT, + total_gas_fees BIGINT, + total_stake_rewards_distributed BIGINT, + -- bcs serialized Vec bytes, found in last CheckpointSummary + -- of the epoch + epoch_commitments bytea, + burnt_tokens_amount BIGINT, + minted_tokens_amount BIGINT +); + +-- Packages +CREATE TABLE packages +( + package_id bytea PRIMARY KEY, + -- bcs serialized MovePackage + move_package bytea NOT NULL +); + +-- Tx Recipients +CREATE TABLE tx_recipients ( + tx_sequence_number BIGINT NOT NULL, + -- IotaAddress in bytes. + recipient BYTEA NOT NULL, + PRIMARY KEY(recipient, tx_sequence_number) +); +CREATE INDEX tx_recipients_tx_sequence_number_index ON tx_recipients (tx_sequence_number ASC); + +-- Tx Senders +CREATE TABLE tx_senders ( + tx_sequence_number BIGINT NOT NULL, + -- IotaAddress in bytes. + sender BYTEA NOT NULL, + PRIMARY KEY(sender, tx_sequence_number) +); +CREATE INDEX tx_senders_tx_sequence_number_index ON tx_senders (tx_sequence_number ASC); + +-- Tx Input Objects +CREATE TABLE tx_input_objects ( + tx_sequence_number BIGINT NOT NULL, + -- Object ID in bytes. + object_id BYTEA NOT NULL, + PRIMARY KEY(object_id, tx_sequence_number) +); + +-- Tx changed Objects +CREATE TABLE tx_changed_objects ( + tx_sequence_number BIGINT NOT NULL, + -- Object Id in bytes. + object_id BYTEA NOT NULL, + PRIMARY KEY(object_id, tx_sequence_number) +); + +-- Tx Calls +CREATE TABLE tx_calls ( + tx_sequence_number BIGINT NOT NULL, + package BYTEA NOT NULL, + module TEXT NOT NULL, + func TEXT NOT NULL, + -- 1. Using Primary Key as a unique index. + -- 2. Diesel does not like tables with no primary key. + PRIMARY KEY(package, tx_sequence_number) +); + +CREATE INDEX tx_calls_module ON tx_calls (package, module, tx_sequence_number); +CREATE INDEX tx_calls_func ON tx_calls (package, module, func, tx_sequence_number); +CREATE INDEX tx_calls_tx_sequence_number ON tx_calls (tx_sequence_number); + +-- Display +CREATE TABLE display +( + object_type text PRIMARY KEY, + id BYTEA NOT NULL, + version SMALLINT NOT NULL, + bcs BYTEA NOT NULL +); + +CREATE OR REPLACE FUNCTION query_cost( + query_in text, + cost OUT float8 + ) RETURNS float8 AS +$$DECLARE + p json; +BEGIN + /* get execution plan in JSON */ + EXECUTE 'EXPLAIN (FORMAT JSON) ' || query_in INTO p; + /* extract total cost */ + SELECT p->0->'Plan'->>'Total Cost' + INTO cost; + RETURN; +END;$$ LANGUAGE plpgsql STRICT; + +CREATE OR REPLACE PROCEDURE advance_partition(table_name TEXT, last_epoch BIGINT, new_epoch BIGINT, last_epoch_start_cp BIGINT, new_epoch_start_cp BIGINT) +LANGUAGE plpgsql +AS $$ +BEGIN + EXECUTE format('ALTER TABLE %I DETACH PARTITION %I_partition_%s', table_name, table_name, last_epoch); + EXECUTE format('ALTER TABLE %I ATTACH PARTITION %I_partition_%s FOR VALUES FROM (%L) TO (%L)', table_name, table_name, last_epoch, last_epoch_start_cp, new_epoch_start_cp); + EXECUTE format('CREATE TABLE IF NOT EXISTS %I_partition_%s PARTITION OF %I FOR VALUES FROM (%L) TO (MAXVALUE)', table_name, new_epoch, table_name, new_epoch_start_cp); +END; +$$; \ No newline at end of file diff --git a/crates/iota-indexer/migrations/2023-08-19-044020_events/down.sql b/crates/iota-indexer/migrations/2023-08-19-044020_events/down.sql deleted file mode 100644 index 6cd33fe82b3..00000000000 --- a/crates/iota-indexer/migrations/2023-08-19-044020_events/down.sql +++ /dev/null @@ -1,2 +0,0 @@ --- This file should undo anything in `up.sql` -DROP TABLE IF EXISTS events; diff --git a/crates/iota-indexer/migrations/2023-08-19-044020_events/up.sql b/crates/iota-indexer/migrations/2023-08-19-044020_events/up.sql deleted file mode 100644 index f450b1d5fdd..00000000000 --- a/crates/iota-indexer/migrations/2023-08-19-044020_events/up.sql +++ /dev/null @@ -1,24 +0,0 @@ -CREATE TABLE events -( - tx_sequence_number BIGINT NOT NULL, - event_sequence_number BIGINT NOT NULL, - transaction_digest bytea NOT NULL, - checkpoint_sequence_number bigint NOT NULL, - -- array of IotaAddress in bytes. All signers of the transaction. - senders bytea[] NOT NULL, - -- bytes of the entry package ID - package bytea NOT NULL, - -- entry module name - module text NOT NULL, - -- StructTag in Display format - event_type text NOT NULL, - timestamp_ms BIGINT NOT NULL, - -- bcs of the Event contents (Event.contents) - bcs BYTEA NOT NULL, - PRIMARY KEY(tx_sequence_number, event_sequence_number) -); - -CREATE INDEX events_package ON events (package, tx_sequence_number, event_sequence_number); -CREATE INDEX events_package_module ON events (package, module, tx_sequence_number, event_sequence_number); -CREATE INDEX events_event_type ON events (event_type text_pattern_ops, tx_sequence_number, event_sequence_number); -CREATE INDEX events_checkpoint_sequence_number ON events (checkpoint_sequence_number); diff --git a/crates/iota-indexer/migrations/2023-08-19-044023_objects/down.sql b/crates/iota-indexer/migrations/2023-08-19-044023_objects/down.sql deleted file mode 100644 index edea7960b79..00000000000 --- a/crates/iota-indexer/migrations/2023-08-19-044023_objects/down.sql +++ /dev/null @@ -1,3 +0,0 @@ -DROP TABLE IF EXISTS objects; -DROP TABLE IF EXISTS objects_history; -DROP TABLE IF EXISTS objects_snapshot; diff --git a/crates/iota-indexer/migrations/2023-08-19-044023_objects/up.sql b/crates/iota-indexer/migrations/2023-08-19-044023_objects/up.sql deleted file mode 100644 index 1e59528ae6e..00000000000 --- a/crates/iota-indexer/migrations/2023-08-19-044023_objects/up.sql +++ /dev/null @@ -1,89 +0,0 @@ -CREATE TABLE objects ( - object_id bytea PRIMARY KEY, - object_version bigint NOT NULL, - object_digest bytea NOT NULL, - checkpoint_sequence_number bigint NOT NULL, - -- Immutable/Address/Object/Shared, see types.rs - owner_type smallint NOT NULL, - -- bytes of IotaAddress/ObjectID of the owner ID. - -- Non-null for objects with an owner: Addresso or Objects - owner_id bytea, - -- Object type - object_type text, - -- bcs serialized Object - serialized_object bytea NOT NULL, - -- Non-null when the object is a coin. - -- e.g. `0x2::iota::IOTA` - coin_type text, - -- Non-null when the object is a coin. - coin_balance bigint, - -- DynamicField/DynamicObject, see types.rs - -- Non-null when the object is a dynamic field - df_kind smallint, - -- bcs serialized DynamicFieldName - -- Non-null when the object is a dynamic field - df_name bytea, - -- object_type in DynamicFieldInfo. - df_object_type text, - -- object_id in DynamicFieldInfo. - df_object_id bytea -); - --- OwnerType: 1: Address, 2: Object, see types.rs -CREATE INDEX objects_owner ON objects (owner_type, owner_id) WHERE owner_type BETWEEN 1 AND 2 AND owner_id IS NOT NULL; -CREATE INDEX objects_coin ON objects (owner_id, coin_type) WHERE coin_type IS NOT NULL AND owner_type = 1; -CREATE INDEX objects_checkpoint_sequence_number ON objects (checkpoint_sequence_number); -CREATE INDEX objects_type ON objects (object_type); - --- similar to objects table, except that --- 1. the primary key to store multiple object versions and partitions by checkpoint_sequence_number --- 2. allow null values in some columns for deleted / wrapped objects --- 3. object_status to mark the status of the object, which is either Active or WrappedOrDeleted -CREATE TABLE objects_history ( - object_id bytea NOT NULL, - object_version bigint NOT NULL, - object_status smallint NOT NULL, - object_digest bytea, - checkpoint_sequence_number bigint NOT NULL, - owner_type smallint, - owner_id bytea, - object_type text, - serialized_object bytea, - coin_type text, - coin_balance bigint, - df_kind smallint, - df_name bytea, - df_object_type text, - df_object_id bytea, - CONSTRAINT objects_history_pk PRIMARY KEY (checkpoint_sequence_number, object_id, object_version) -) PARTITION BY RANGE (checkpoint_sequence_number); -CREATE INDEX objects_history_owner ON objects_history (checkpoint_sequence_number, owner_type, owner_id) WHERE owner_type BETWEEN 1 AND 2 AND owner_id IS NOT NULL; -CREATE INDEX objects_history_coin ON objects_history (checkpoint_sequence_number, owner_id, coin_type) WHERE coin_type IS NOT NULL AND owner_type = 1; -CREATE INDEX objects_history_type ON objects_history (checkpoint_sequence_number, object_type); --- init with first partition of the history table -CREATE TABLE objects_history_partition_0 PARTITION OF objects_history FOR VALUES FROM (0) TO (MAXVALUE); - --- snapshot table by folding objects_history table until certain checkpoint, --- effectively the snapshot of objects at the same checkpoint, --- except that it also includes deleted or wrapped objects with the corresponding object_status. -CREATE TABLE objects_snapshot ( - object_id bytea PRIMARY KEY, - object_version bigint NOT NULL, - object_status smallint NOT NULL, - object_digest bytea, - checkpoint_sequence_number bigint NOT NULL, - owner_type smallint, - owner_id bytea, - object_type text, - serialized_object bytea, - coin_type text, - coin_balance bigint, - df_kind smallint, - df_name bytea, - df_object_type text, - df_object_id bytea -); -CREATE INDEX objects_snapshot_checkpoint_sequence_number ON objects_snapshot (checkpoint_sequence_number); -CREATE INDEX objects_snapshot_owner ON objects_snapshot (owner_type, owner_id, object_id) WHERE owner_type BETWEEN 1 AND 2 AND owner_id IS NOT NULL; -CREATE INDEX objects_snapshot_coin ON objects_snapshot (owner_id, coin_type, object_id) WHERE coin_type IS NOT NULL AND owner_type = 1; -CREATE INDEX objects_snapshot_type ON objects_snapshot (object_type, object_id); diff --git a/crates/iota-indexer/migrations/2023-08-19-044026_transactions/down.sql b/crates/iota-indexer/migrations/2023-08-19-044026_transactions/down.sql deleted file mode 100644 index e5850457f92..00000000000 --- a/crates/iota-indexer/migrations/2023-08-19-044026_transactions/down.sql +++ /dev/null @@ -1,2 +0,0 @@ --- This file should undo anything in `up.sql` -DROP TABLE IF EXISTS transactions; diff --git a/crates/iota-indexer/migrations/2023-08-19-044026_transactions/up.sql b/crates/iota-indexer/migrations/2023-08-19-044026_transactions/up.sql deleted file mode 100644 index ba9b6e32594..00000000000 --- a/crates/iota-indexer/migrations/2023-08-19-044026_transactions/up.sql +++ /dev/null @@ -1,28 +0,0 @@ -CREATE TABLE transactions ( - tx_sequence_number BIGINT NOT NULL, - transaction_digest bytea NOT NULL, - -- bcs serialized SenderSignedData bytes - raw_transaction bytea NOT NULL, - -- bcs serialized TransactionEffects bytes - raw_effects bytea NOT NULL, - checkpoint_sequence_number BIGINT NOT NULL, - timestamp_ms BIGINT NOT NULL, - -- array of bcs serialized IndexedObjectChange bytes - object_changes bytea[] NOT NULL, - -- array of bcs serialized BalanceChange bytes - balance_changes bytea[] NOT NULL, - -- array of bcs serialized StoredEvent bytes - events bytea[] NOT NULL, - -- SystemTransaction/ProgrammableTransaction. See types.rs - transaction_kind smallint NOT NULL, - -- number of successful commands in this transaction, bound by number of command - -- in a programmaable transaction. - success_command_count smallint NOT NULL, - CONSTRAINT transactions_pkey PRIMARY KEY (tx_sequence_number, checkpoint_sequence_number) -) PARTITION BY RANGE (checkpoint_sequence_number); - -CREATE TABLE transactions_partition_0 PARTITION OF transactions FOR VALUES FROM (0) TO (MAXVALUE); -CREATE INDEX transactions_transaction_digest ON transactions (transaction_digest); -CREATE INDEX transactions_checkpoint_sequence_number ON transactions (checkpoint_sequence_number); --- only create index for system transactions (0). See types.rs -CREATE INDEX transactions_transaction_kind ON transactions (transaction_kind) WHERE transaction_kind = 0; diff --git a/crates/iota-indexer/migrations/2023-08-19-044044_checkpoints/down.sql b/crates/iota-indexer/migrations/2023-08-19-044044_checkpoints/down.sql deleted file mode 100644 index 48573ae779c..00000000000 --- a/crates/iota-indexer/migrations/2023-08-19-044044_checkpoints/down.sql +++ /dev/null @@ -1,2 +0,0 @@ --- This file should undo anything in `up.sql` -DROP TABLE IF EXISTS checkpoints; diff --git a/crates/iota-indexer/migrations/2023-08-19-044044_checkpoints/up.sql b/crates/iota-indexer/migrations/2023-08-19-044044_checkpoints/up.sql deleted file mode 100644 index 8de09a7ff88..00000000000 --- a/crates/iota-indexer/migrations/2023-08-19-044044_checkpoints/up.sql +++ /dev/null @@ -1,28 +0,0 @@ -CREATE TABLE checkpoints -( - sequence_number bigint PRIMARY KEY, - checkpoint_digest bytea NOT NULL, - epoch bigint NOT NULL, - -- total transactions in the network at the end of this checkpoint (including itself) - network_total_transactions bigint NOT NULL, - previous_checkpoint_digest bytea, - -- if this checkpoitn is the last checkpoint of an epoch - end_of_epoch boolean NOT NULL, - -- array of TranscationDigest in bytes included in this checkpoint - tx_digests bytea[] NOT NULL, - timestamp_ms BIGINT NOT NULL, - total_gas_cost BIGINT NOT NULL, - computation_cost BIGINT NOT NULL, - storage_cost BIGINT NOT NULL, - storage_rebate BIGINT NOT NULL, - non_refundable_storage_fee BIGINT NOT NULL, - -- bcs serialized Vec bytes - checkpoint_commitments bytea NOT NULL, - -- bcs serialized AggregateAuthoritySignature bytes - validator_signature bytea NOT NULL, - -- bcs serialzied EndOfEpochData bytes, if the checkpoint marks end of an epoch - end_of_epoch_data bytea -); - -CREATE INDEX checkpoints_epoch ON checkpoints (epoch, sequence_number); -CREATE INDEX checkpoints_digest ON checkpoints USING HASH (checkpoint_digest); diff --git a/crates/iota-indexer/migrations/2023-08-19-044052_epochs/down.sql b/crates/iota-indexer/migrations/2023-08-19-044052_epochs/down.sql deleted file mode 100644 index ddb05ac2ebe..00000000000 --- a/crates/iota-indexer/migrations/2023-08-19-044052_epochs/down.sql +++ /dev/null @@ -1,2 +0,0 @@ --- This file should undo anything in `up.sql` -DROP TABLE IF EXISTS epochs; diff --git a/crates/iota-indexer/migrations/2023-08-19-044052_epochs/up.sql b/crates/iota-indexer/migrations/2023-08-19-044052_epochs/up.sql deleted file mode 100644 index 4a0a17289cc..00000000000 --- a/crates/iota-indexer/migrations/2023-08-19-044052_epochs/up.sql +++ /dev/null @@ -1,28 +0,0 @@ -CREATE TABLE epochs -( - epoch BIGINT PRIMARY KEY, - first_checkpoint_id BIGINT NOT NULL, - epoch_start_timestamp BIGINT NOT NULL, - reference_gas_price BIGINT NOT NULL, - protocol_version BIGINT NOT NULL, - total_stake BIGINT NOT NULL, - storage_fund_balance BIGINT NOT NULL, - system_state bytea NOT NULL, - -- The following fields are nullable because they are filled in - -- only at the end of an epoch. - epoch_total_transactions BIGINT, - last_checkpoint_id BIGINT, - epoch_end_timestamp BIGINT, - -- The following fields are from SystemEpochInfoEvent emitted - -- **after** advancing to the next epoch - storage_fund_reinvestment BIGINT, - storage_charge BIGINT, - storage_rebate BIGINT, - stake_subsidy_amount BIGINT, - total_gas_fees BIGINT, - total_stake_rewards_distributed BIGINT, - leftover_storage_fund_inflow BIGINT, - -- bcs serialized Vec bytes, found in last CheckpointSummary - -- of the epoch - epoch_commitments bytea -); diff --git a/crates/iota-indexer/migrations/2023-08-19-060729_packages/down.sql b/crates/iota-indexer/migrations/2023-08-19-060729_packages/down.sql deleted file mode 100644 index 6b473dc06f4..00000000000 --- a/crates/iota-indexer/migrations/2023-08-19-060729_packages/down.sql +++ /dev/null @@ -1,2 +0,0 @@ --- This file should undo anything in `up.sql` -DROP TABLE IF EXISTS packages; diff --git a/crates/iota-indexer/migrations/2023-08-19-060729_packages/up.sql b/crates/iota-indexer/migrations/2023-08-19-060729_packages/up.sql deleted file mode 100644 index a95489af4dc..00000000000 --- a/crates/iota-indexer/migrations/2023-08-19-060729_packages/up.sql +++ /dev/null @@ -1,6 +0,0 @@ -CREATE TABLE packages -( - package_id bytea PRIMARY KEY, - -- bcs serialized MovePackage - move_package bytea NOT NULL -); diff --git a/crates/iota-indexer/migrations/2023-10-06-204335_tx_recipients/down.sql b/crates/iota-indexer/migrations/2023-10-06-204335_tx_recipients/down.sql deleted file mode 100644 index 921131a3d65..00000000000 --- a/crates/iota-indexer/migrations/2023-10-06-204335_tx_recipients/down.sql +++ /dev/null @@ -1,2 +0,0 @@ --- This file should undo anything in `up.sql` -DROP TABLE IF EXISTS tx_recipients; diff --git a/crates/iota-indexer/migrations/2023-10-06-204335_tx_recipients/up.sql b/crates/iota-indexer/migrations/2023-10-06-204335_tx_recipients/up.sql deleted file mode 100644 index 2382e3a47c3..00000000000 --- a/crates/iota-indexer/migrations/2023-10-06-204335_tx_recipients/up.sql +++ /dev/null @@ -1,8 +0,0 @@ --- Your SQL goes here -CREATE TABLE tx_recipients ( - tx_sequence_number BIGINT NOT NULL, - -- IotaAddress in bytes. - recipient BYTEA NOT NULL, - PRIMARY KEY(recipient, tx_sequence_number) -); -CREATE INDEX tx_recipients_tx_sequence_number_index ON tx_recipients (tx_sequence_number ASC); diff --git a/crates/iota-indexer/migrations/2023-10-06-204340_tx_senders/down.sql b/crates/iota-indexer/migrations/2023-10-06-204340_tx_senders/down.sql deleted file mode 100644 index 6ba56c061da..00000000000 --- a/crates/iota-indexer/migrations/2023-10-06-204340_tx_senders/down.sql +++ /dev/null @@ -1,2 +0,0 @@ --- This file should undo anything in `up.sql` -DROP TABLE IF EXISTS tx_senders; diff --git a/crates/iota-indexer/migrations/2023-10-06-204340_tx_senders/up.sql b/crates/iota-indexer/migrations/2023-10-06-204340_tx_senders/up.sql deleted file mode 100644 index db140812a55..00000000000 --- a/crates/iota-indexer/migrations/2023-10-06-204340_tx_senders/up.sql +++ /dev/null @@ -1,8 +0,0 @@ --- Your SQL goes here -CREATE TABLE tx_senders ( - tx_sequence_number BIGINT NOT NULL, - -- IotaAddress in bytes. - sender BYTEA NOT NULL, - PRIMARY KEY(sender, tx_sequence_number) -); -CREATE INDEX tx_senders_tx_sequence_number_index ON tx_senders (tx_sequence_number ASC); diff --git a/crates/iota-indexer/migrations/2023-10-06-204348_tx_input_objects/down.sql b/crates/iota-indexer/migrations/2023-10-06-204348_tx_input_objects/down.sql deleted file mode 100644 index 3baa45adc7e..00000000000 --- a/crates/iota-indexer/migrations/2023-10-06-204348_tx_input_objects/down.sql +++ /dev/null @@ -1,2 +0,0 @@ --- This file should undo anything in `up.sql` -DROP TABLE IF EXISTS tx_input_objects; diff --git a/crates/iota-indexer/migrations/2023-10-06-204348_tx_input_objects/up.sql b/crates/iota-indexer/migrations/2023-10-06-204348_tx_input_objects/up.sql deleted file mode 100644 index 5abab6afa12..00000000000 --- a/crates/iota-indexer/migrations/2023-10-06-204348_tx_input_objects/up.sql +++ /dev/null @@ -1,7 +0,0 @@ --- Your SQL goes here -CREATE TABLE tx_input_objects ( - tx_sequence_number BIGINT NOT NULL, - -- Object ID in bytes. - object_id BYTEA NOT NULL, - PRIMARY KEY(object_id, tx_sequence_number) -); diff --git a/crates/iota-indexer/migrations/2023-10-06-204352_tx_changed_objects/down.sql b/crates/iota-indexer/migrations/2023-10-06-204352_tx_changed_objects/down.sql deleted file mode 100644 index 5634bb220c0..00000000000 --- a/crates/iota-indexer/migrations/2023-10-06-204352_tx_changed_objects/down.sql +++ /dev/null @@ -1,2 +0,0 @@ --- This file should undo anything in `up.sql` -DROP TABLE IF EXISTS tx_changed_objects; diff --git a/crates/iota-indexer/migrations/2023-10-06-204352_tx_changed_objects/up.sql b/crates/iota-indexer/migrations/2023-10-06-204352_tx_changed_objects/up.sql deleted file mode 100644 index 33b3faffe16..00000000000 --- a/crates/iota-indexer/migrations/2023-10-06-204352_tx_changed_objects/up.sql +++ /dev/null @@ -1,7 +0,0 @@ --- Your SQL goes here -CREATE TABLE tx_changed_objects ( - tx_sequence_number BIGINT NOT NULL, - -- Object Id in bytes. - object_id BYTEA NOT NULL, - PRIMARY KEY(object_id, tx_sequence_number) -); diff --git a/crates/iota-indexer/migrations/2023-10-06-204400_tx_calls/down.sql b/crates/iota-indexer/migrations/2023-10-06-204400_tx_calls/down.sql deleted file mode 100644 index fd9e3de4187..00000000000 --- a/crates/iota-indexer/migrations/2023-10-06-204400_tx_calls/down.sql +++ /dev/null @@ -1,2 +0,0 @@ --- This file should undo anything in `up.sql` -DROP TABLE IF EXISTS tx_calls; diff --git a/crates/iota-indexer/migrations/2023-10-06-204400_tx_calls/up.sql b/crates/iota-indexer/migrations/2023-10-06-204400_tx_calls/up.sql deleted file mode 100644 index e1204b09c9a..00000000000 --- a/crates/iota-indexer/migrations/2023-10-06-204400_tx_calls/up.sql +++ /dev/null @@ -1,14 +0,0 @@ --- Your SQL goes here -CREATE TABLE tx_calls ( - tx_sequence_number BIGINT NOT NULL, - package BYTEA NOT NULL, - module TEXT NOT NULL, - func TEXT NOT NULL, - -- 1. Using Primary Key as a unique index. - -- 2. Diesel does not like tables with no primary key. - PRIMARY KEY(package, tx_sequence_number) -); - -CREATE INDEX tx_calls_module ON tx_calls (package, module, tx_sequence_number); -CREATE INDEX tx_calls_func ON tx_calls (package, module, func, tx_sequence_number); -CREATE INDEX tx_calls_tx_sequence_number ON tx_calls (tx_sequence_number); diff --git a/crates/iota-indexer/migrations/2023-10-07-160139_display/down.sql b/crates/iota-indexer/migrations/2023-10-07-160139_display/down.sql deleted file mode 100644 index f73e497c406..00000000000 --- a/crates/iota-indexer/migrations/2023-10-07-160139_display/down.sql +++ /dev/null @@ -1,2 +0,0 @@ --- This file should undo anything in `up.sql` -DROP TABLE IF EXISTS display; diff --git a/crates/iota-indexer/migrations/2023-10-07-160139_display/up.sql b/crates/iota-indexer/migrations/2023-10-07-160139_display/up.sql deleted file mode 100644 index 1ef9f37bc54..00000000000 --- a/crates/iota-indexer/migrations/2023-10-07-160139_display/up.sql +++ /dev/null @@ -1,8 +0,0 @@ --- Your SQL goes here -CREATE TABLE display -( - object_type text PRIMARY KEY, - id BYTEA NOT NULL, - version SMALLINT NOT NULL, - bcs BYTEA NOT NULL -); diff --git a/crates/iota-indexer/migrations/2023-10-24-160139_query_cost_function/down.sql b/crates/iota-indexer/migrations/2023-10-24-160139_query_cost_function/down.sql deleted file mode 100644 index 742f7001fc5..00000000000 --- a/crates/iota-indexer/migrations/2023-10-24-160139_query_cost_function/down.sql +++ /dev/null @@ -1,2 +0,0 @@ --- This file should undo anything in `up.sql` -DROP FUNCTION IF EXISTS query_cost(TEXT); diff --git a/crates/iota-indexer/migrations/2023-10-24-160139_query_cost_function/up.sql b/crates/iota-indexer/migrations/2023-10-24-160139_query_cost_function/up.sql deleted file mode 100644 index 7296c688baa..00000000000 --- a/crates/iota-indexer/migrations/2023-10-24-160139_query_cost_function/up.sql +++ /dev/null @@ -1,15 +0,0 @@ --- Your SQL goes here -CREATE OR REPLACE FUNCTION query_cost( - query_in text, - cost OUT float8 - ) RETURNS float8 AS -$$DECLARE - p json; -BEGIN - /* get execution plan in JSON */ - EXECUTE 'EXPLAIN (FORMAT JSON) ' || query_in INTO p; - /* extract total cost */ - SELECT p->0->'Plan'->>'Total Cost' - INTO cost; - RETURN; -END;$$ LANGUAGE plpgsql STRICT; diff --git a/crates/iota-indexer/migrations/2023-11-29-193859_advance_partition/down.sql b/crates/iota-indexer/migrations/2023-11-29-193859_advance_partition/down.sql deleted file mode 100644 index 1693f3892a5..00000000000 --- a/crates/iota-indexer/migrations/2023-11-29-193859_advance_partition/down.sql +++ /dev/null @@ -1 +0,0 @@ -DROP PROCEDURE IF EXISTS advance_partition; diff --git a/crates/iota-indexer/migrations/2023-11-29-193859_advance_partition/up.sql b/crates/iota-indexer/migrations/2023-11-29-193859_advance_partition/up.sql deleted file mode 100644 index 57c22f88581..00000000000 --- a/crates/iota-indexer/migrations/2023-11-29-193859_advance_partition/up.sql +++ /dev/null @@ -1,9 +0,0 @@ -CREATE OR REPLACE PROCEDURE advance_partition(table_name TEXT, last_epoch BIGINT, new_epoch BIGINT, last_epoch_start_cp BIGINT, new_epoch_start_cp BIGINT) -LANGUAGE plpgsql -AS $$ -BEGIN - EXECUTE format('ALTER TABLE %I DETACH PARTITION %I_partition_%s', table_name, table_name, last_epoch); - EXECUTE format('ALTER TABLE %I ATTACH PARTITION %I_partition_%s FOR VALUES FROM (%L) TO (%L)', table_name, table_name, last_epoch, last_epoch_start_cp, new_epoch_start_cp); - EXECUTE format('CREATE TABLE IF NOT EXISTS %I_partition_%s PARTITION OF %I FOR VALUES FROM (%L) TO (MAXVALUE)', table_name, new_epoch, table_name, new_epoch_start_cp); -END; -$$; diff --git a/crates/iota-indexer/migrations/2024-07-11-144921_minting_burning_tokens_info/down.sql b/crates/iota-indexer/migrations/2024-07-11-144921_minting_burning_tokens_info/down.sql deleted file mode 100644 index 5137f1e9cd3..00000000000 --- a/crates/iota-indexer/migrations/2024-07-11-144921_minting_burning_tokens_info/down.sql +++ /dev/null @@ -1,6 +0,0 @@ -ALTER TABLE epochs -DROP COLUMN burnt_tokens_amount, -DROP COLUMN minted_tokens_amount; - -ALTER TABLE epochs -RENAME COLUMN burnt_leftover_amount TO leftover_storage_fund_inflow; \ No newline at end of file diff --git a/crates/iota-indexer/migrations/2024-07-11-144921_minting_burning_tokens_info/up.sql b/crates/iota-indexer/migrations/2024-07-11-144921_minting_burning_tokens_info/up.sql deleted file mode 100644 index f6df74a5ee3..00000000000 --- a/crates/iota-indexer/migrations/2024-07-11-144921_minting_burning_tokens_info/up.sql +++ /dev/null @@ -1,6 +0,0 @@ -ALTER TABLE epochs -ADD COLUMN burnt_tokens_amount BIGINT, -ADD COLUMN minted_tokens_amount BIGINT; - -ALTER TABLE epochs -RENAME COLUMN leftover_storage_fund_inflow TO burnt_leftover_amount; \ No newline at end of file diff --git a/crates/iota-indexer/migrations/2024-07-16-092139_remove_stake_subsidy_amount/down.sql b/crates/iota-indexer/migrations/2024-07-16-092139_remove_stake_subsidy_amount/down.sql deleted file mode 100644 index 94f7229f3b8..00000000000 --- a/crates/iota-indexer/migrations/2024-07-16-092139_remove_stake_subsidy_amount/down.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE epochs -ADD COLUMN stake_subsidy_amount BIGINT; diff --git a/crates/iota-indexer/migrations/2024-07-16-092139_remove_stake_subsidy_amount/up.sql b/crates/iota-indexer/migrations/2024-07-16-092139_remove_stake_subsidy_amount/up.sql deleted file mode 100644 index 8a6cf370e46..00000000000 --- a/crates/iota-indexer/migrations/2024-07-16-092139_remove_stake_subsidy_amount/up.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE epochs -DROP COLUMN stake_subsidy_amount; diff --git a/crates/iota-indexer/migrations/2024-07-23-075345_remove_reinvestment/down.sql b/crates/iota-indexer/migrations/2024-07-23-075345_remove_reinvestment/down.sql deleted file mode 100644 index 7eac15bd645..00000000000 --- a/crates/iota-indexer/migrations/2024-07-23-075345_remove_reinvestment/down.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE epochs ADD COLUMN storage_fund_reinvestment BIGINT; diff --git a/crates/iota-indexer/migrations/2024-07-23-075345_remove_reinvestment/up.sql b/crates/iota-indexer/migrations/2024-07-23-075345_remove_reinvestment/up.sql deleted file mode 100644 index b48369d9054..00000000000 --- a/crates/iota-indexer/migrations/2024-07-23-075345_remove_reinvestment/up.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE epochs DROP COLUMN storage_fund_reinvestment; diff --git a/crates/iota-indexer/migrations/2024-08-05-100929_remove_burnt_leftover_amount/down.sql b/crates/iota-indexer/migrations/2024-08-05-100929_remove_burnt_leftover_amount/down.sql deleted file mode 100644 index 9f0fd7af31e..00000000000 --- a/crates/iota-indexer/migrations/2024-08-05-100929_remove_burnt_leftover_amount/down.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE epochs -ADD COLUMN burnt_leftover_amount BIGINT; \ No newline at end of file diff --git a/crates/iota-indexer/migrations/2024-08-05-100929_remove_burnt_leftover_amount/up.sql b/crates/iota-indexer/migrations/2024-08-05-100929_remove_burnt_leftover_amount/up.sql deleted file mode 100644 index fccb9dcbb1d..00000000000 --- a/crates/iota-indexer/migrations/2024-08-05-100929_remove_burnt_leftover_amount/up.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE epochs -DROP COLUMN burnt_leftover_amount; \ No newline at end of file