diff --git a/db/batch_process_migrations/00004_create_eth_header_cids_table.sql b/db/batch_process_migrations/00004_create_eth_header_cids_table.sql index f54c834..f280c90 100644 --- a/db/batch_process_migrations/00004_create_eth_header_cids_table.sql +++ b/db/batch_process_migrations/00004_create_eth_header_cids_table.sql @@ -1,6 +1,6 @@ -- +goose Up CREATE TABLE eth.header_cids ( - block_hash VARCHAR(66) NOT NULL, + block_hash VARCHAR(66) PRIMARY KEY, block_number BIGINT NOT NULL, parent_hash VARCHAR(66) NOT NULL, cid TEXT NOT NULL, diff --git a/db/batch_process_migrations/00005_create_eth_uncle_cids_table.sql b/db/batch_process_migrations/00005_create_eth_uncle_cids_table.sql index 434b594..5d4ca8a 100644 --- a/db/batch_process_migrations/00005_create_eth_uncle_cids_table.sql +++ b/db/batch_process_migrations/00005_create_eth_uncle_cids_table.sql @@ -1,6 +1,6 @@ -- +goose Up CREATE TABLE eth.uncle_cids ( - block_hash VARCHAR(66) NOT NULL, + block_hash VARCHAR(66) PRIMARY KEY, header_id VARCHAR(66) NOT NULL, parent_hash VARCHAR(66) NOT NULL, cid TEXT NOT NULL, diff --git a/db/batch_process_migrations/00006_create_eth_transaction_cids_table.sql b/db/batch_process_migrations/00006_create_eth_transaction_cids_table.sql index 3edf232..5a83ed0 100644 --- a/db/batch_process_migrations/00006_create_eth_transaction_cids_table.sql +++ b/db/batch_process_migrations/00006_create_eth_transaction_cids_table.sql @@ -1,6 +1,6 @@ -- +goose Up CREATE TABLE eth.transaction_cids ( - tx_hash VARCHAR(66) NOT NULL, + tx_hash VARCHAR(66) PRIMARY KEY, header_id VARCHAR(66) NOT NULL, index INTEGER NOT NULL, cid TEXT NOT NULL, diff --git a/db/batch_process_migrations/00007_create_eth_receipt_cids_table.sql b/db/batch_process_migrations/00007_create_eth_receipt_cids_table.sql index 84f1d1c..fed5ea1 100644 --- a/db/batch_process_migrations/00007_create_eth_receipt_cids_table.sql +++ b/db/batch_process_migrations/00007_create_eth_receipt_cids_table.sql @@ -1,6 +1,6 @@ -- +goose Up CREATE TABLE eth.receipt_cids ( - tx_id VARCHAR(66) NOT NULL, + tx_id VARCHAR(66) PRIMARY KEY, leaf_cid TEXT NOT NULL, leaf_mh_key TEXT NOT NULL, contract VARCHAR(66), diff --git a/db/batch_process_migrations/00008_create_eth_state_cids_table.sql b/db/batch_process_migrations/00008_create_eth_state_cids_table.sql index 8417bd5..72c919c 100644 --- a/db/batch_process_migrations/00008_create_eth_state_cids_table.sql +++ b/db/batch_process_migrations/00008_create_eth_state_cids_table.sql @@ -6,7 +6,8 @@ CREATE TABLE eth.state_cids ( mh_key TEXT NOT NULL, state_path BYTEA NOT NULL, node_type INTEGER NOT NULL, - diff BOOLEAN NOT NULL DEFAULT FALSE + diff BOOLEAN NOT NULL DEFAULT FALSE, + PRIMARY KEY (header_id, state_path) ); -- +goose Down diff --git a/db/batch_process_migrations/00009_create_eth_storage_cids_table.sql b/db/batch_process_migrations/00009_create_eth_storage_cids_table.sql index dbe60ab..d07cfe7 100644 --- a/db/batch_process_migrations/00009_create_eth_storage_cids_table.sql +++ b/db/batch_process_migrations/00009_create_eth_storage_cids_table.sql @@ -7,7 +7,8 @@ CREATE TABLE eth.storage_cids ( mh_key TEXT NOT NULL, storage_path BYTEA NOT NULL, node_type INTEGER NOT NULL, - diff BOOLEAN NOT NULL DEFAULT FALSE + diff BOOLEAN NOT NULL DEFAULT FALSE, + PRIMARY KEY (header_id, state_path, storage_path) ); -- +goose Down diff --git a/db/batch_process_migrations/00010_create_eth_state_accouts_table.sql b/db/batch_process_migrations/00010_create_eth_state_accouts_table.sql index c508b83..e103795 100644 --- a/db/batch_process_migrations/00010_create_eth_state_accouts_table.sql +++ b/db/batch_process_migrations/00010_create_eth_state_accouts_table.sql @@ -5,7 +5,8 @@ CREATE TABLE eth.state_accounts ( balance NUMERIC NOT NULL, nonce INTEGER NOT NULL, code_hash BYTEA NOT NULL, - storage_root VARCHAR(66) NOT NULL + storage_root VARCHAR(66) NOT NULL, + PRIMARY KEY (header_id, state_path) ); -- +goose Down diff --git a/db/batch_process_migrations/00011_create_eth_access_list_elements_table.sql b/db/batch_process_migrations/00011_create_eth_access_list_elements_table.sql index c5cf02d..da1fcf0 100644 --- a/db/batch_process_migrations/00011_create_eth_access_list_elements_table.sql +++ b/db/batch_process_migrations/00011_create_eth_access_list_elements_table.sql @@ -3,7 +3,8 @@ CREATE TABLE eth.access_list_element ( tx_id VARCHAR(66) NOT NULL, index INTEGER NOT NULL, address VARCHAR(66), - storage_keys VARCHAR(66)[] + storage_keys VARCHAR(66)[], + PRIMARY KEY (tx_id, index) ); -- +goose Down diff --git a/db/batch_process_migrations/00012_create_eth_log_cids_table.sql b/db/batch_process_migrations/00012_create_eth_log_cids_table.sql index bf567bd..d0911ed 100644 --- a/db/batch_process_migrations/00012_create_eth_log_cids_table.sql +++ b/db/batch_process_migrations/00012_create_eth_log_cids_table.sql @@ -9,7 +9,8 @@ CREATE TABLE eth.log_cids ( topic0 VARCHAR(66), topic1 VARCHAR(66), topic2 VARCHAR(66), - topic3 VARCHAR(66) + topic3 VARCHAR(66), + PRIMARY KEY (rct_id, index) ); -- +goose Down diff --git a/db/migrations/00016_create_stored_functions.sql b/db/migrations/00015_create_stored_functions.sql similarity index 100% rename from db/migrations/00016_create_stored_functions.sql rename to db/migrations/00015_create_stored_functions.sql diff --git a/db/migrations/00015_potgraphile_triggers.sql b/db/migrations/00015_potgraphile_triggers.sql deleted file mode 100644 index 3470533..0000000 --- a/db/migrations/00015_potgraphile_triggers.sql +++ /dev/null @@ -1,69 +0,0 @@ --- +goose Up --- +goose StatementBegin -CREATE FUNCTION eth.graphql_subscription() returns TRIGGER as $$ -declare - table_name text = TG_ARGV[0]; - attribute text = TG_ARGV[1]; - id text; -begin - execute 'select $1.' || quote_ident(attribute) - using new - into id; - perform pg_notify('postgraphile:' || table_name, - json_build_object( - '__node__', json_build_array( - table_name, - id - ) - )::text - ); - return new; -end; -$$ language plpgsql; --- +goose StatementEnd - -CREATE TRIGGER header_cids_ai - after INSERT ON eth.header_cids - for each row - execute procedure eth.graphql_subscription('header_cids', 'id'); - -CREATE TRIGGER receipt_cids_ai - after INSERT ON eth.receipt_cids - for each row - execute procedure eth.graphql_subscription('receipt_cids', 'id'); - -CREATE TRIGGER state_accounts_ai - after INSERT ON eth.state_accounts - for each row - execute procedure eth.graphql_subscription('state_accounts', 'id'); - -CREATE TRIGGER state_cids_ai - after INSERT ON eth.state_cids - for each row - execute procedure eth.graphql_subscription('state_cids', 'id'); - -CREATE TRIGGER storage_cids_ai - after INSERT ON eth.storage_cids - for each row - execute procedure eth.graphql_subscription('storage_cids', 'id'); - -CREATE TRIGGER transaction_cids_ai - after INSERT ON eth.transaction_cids - for each row - execute procedure eth.graphql_subscription('transaction_cids', 'id'); - -CREATE TRIGGER uncle_cids_ai - after INSERT ON eth.uncle_cids - for each row - execute procedure eth.graphql_subscription('uncle_cids', 'id'); - --- +goose Down -DROP TRIGGER uncle_cids_ai ON eth.uncle_cids; -DROP TRIGGER transaction_cids_ai ON eth.transaction_cids; -DROP TRIGGER storage_cids_ai ON eth.storage_cids; -DROP TRIGGER state_cids_ai ON eth.state_cids; -DROP TRIGGER state_accounts_ai ON eth.state_accounts; -DROP TRIGGER receipt_cids_ai ON eth.receipt_cids; -DROP TRIGGER header_cids_ai ON eth.header_cids; - -DROP FUNCTION eth.graphql_subscription();