From 81791f74d2dad0428524b626b8c31949050fe624 Mon Sep 17 00:00:00 2001 From: Paul Weidner Date: Tue, 30 Jan 2024 02:39:19 -0800 Subject: [PATCH] chore: remove old sql migrations (#58) --- sql/README.md | 12 ----- sql/V1_10__class_issuers.sql | 28 ---------- sql/V1_11__class_issuers_indexes.sql | 5 -- sql/V1_12__votes.sql | 24 --------- sql/V1_1__fix_msg_attr.sql | 9 ---- sql/V1_2__add_retirements_table.sql | 27 ---------- sql/V1_3__add_msg_event_attr_type_idx.sql | 3 -- sql/V1_4__retirements_owner_idx.sql | 1 - sql/V1_5__add_proposals_table.sql | 37 -------------- sql/V1_6__add_tx_hash.sql | 2 - sql/V1_7__index_group_policy_address.sql | 1 - sql/V1_8__index_proposal_id.sql | 1 - sql/V1_9__all_ecocredit_txes.sql | 19 ------- sql/V1__init.sql | 62 ----------------------- sql/run_all_migrations.sh | 18 ------- 15 files changed, 249 deletions(-) delete mode 100644 sql/README.md delete mode 100644 sql/V1_10__class_issuers.sql delete mode 100644 sql/V1_11__class_issuers_indexes.sql delete mode 100644 sql/V1_12__votes.sql delete mode 100644 sql/V1_1__fix_msg_attr.sql delete mode 100644 sql/V1_2__add_retirements_table.sql delete mode 100644 sql/V1_3__add_msg_event_attr_type_idx.sql delete mode 100644 sql/V1_4__retirements_owner_idx.sql delete mode 100644 sql/V1_5__add_proposals_table.sql delete mode 100644 sql/V1_6__add_tx_hash.sql delete mode 100644 sql/V1_7__index_group_policy_address.sql delete mode 100644 sql/V1_8__index_proposal_id.sql delete mode 100644 sql/V1_9__all_ecocredit_txes.sql delete mode 100644 sql/V1__init.sql delete mode 100755 sql/run_all_migrations.sh diff --git a/sql/README.md b/sql/README.md deleted file mode 100644 index 57f0f27..0000000 --- a/sql/README.md +++ /dev/null @@ -1,12 +0,0 @@ -## Running these migrations - -You must set the `DATABASE_URL` environment variable and then run the following command, e.g.: - -``` -$ cd sql -$ DATABASE_URL=postgres://postgres:postgres@localhost:5432/indexer ./run_all_migrations.sh -``` - -## Adding migrations - -Each time you add a new migration to the `sql` folder, add it to the end of the `run_all_migrations.sh` script. diff --git a/sql/V1_10__class_issuers.sql b/sql/V1_10__class_issuers.sql deleted file mode 100644 index 8831904..0000000 --- a/sql/V1_10__class_issuers.sql +++ /dev/null @@ -1,28 +0,0 @@ -CREATE TABLE IF NOT EXISTS - class_issuers ( - TYPE TEXT NOT NULL, - block_height BIGINT NOT NULL, - tx_idx SMALLINT NOT NULL, - msg_idx SMALLINT NOT NULL, - chain_num SMALLINT NOT NULL, - TIMESTAMP timestamptz, - tx_hash TEXT NOT NULL, - class_id TEXT NOT NULL, - issuer TEXT NOT NULL, - latest BOOLEAN NOT NULL DEFAULT TRUE, - PRIMARY KEY ( - chain_num, - block_height, - tx_idx, - msg_idx, - class_id, - issuer - ), - FOREIGN KEY ( - chain_num, - block_height, - tx_idx, - msg_idx, - TYPE - ) REFERENCES msg_event - ); diff --git a/sql/V1_11__class_issuers_indexes.sql b/sql/V1_11__class_issuers_indexes.sql deleted file mode 100644 index b62d061..0000000 --- a/sql/V1_11__class_issuers_indexes.sql +++ /dev/null @@ -1,5 +0,0 @@ -CREATE INDEX IF NOT EXISTS class_issuers_issuer_idx ON class_issuers (issuer); - -CREATE INDEX IF NOT EXISTS class_issuers_credit_class_id_idx ON class_issuers (class_id); - -CREATE INDEX IF NOT EXISTS class_issuers_latest_idx ON class_issuers (latest); diff --git a/sql/V1_12__votes.sql b/sql/V1_12__votes.sql deleted file mode 100644 index 72ea4ba..0000000 --- a/sql/V1_12__votes.sql +++ /dev/null @@ -1,24 +0,0 @@ -CREATE TABLE - IF NOT EXISTS votes ( - type TEXT NOT NULL, - block_height BIGINT NOT NULL, - tx_idx SMALLINT NOT NULL, - msg_idx SMALLINT NOT NULL, - chain_num SMALLINT NOT NULL, - timestamp timestamptz, - tx_hash TEXT NOT NULL, - proposal_id BIGINT NOT NULL, - voter TEXT NOT NULL, - option TEXT NOT NULL, - metadata TEXT NOT NULL, - submit_time timestamptz NOT NULL, - PRIMARY KEY (chain_num, block_height, tx_idx, msg_idx), - FOREIGN KEY (chain_num, block_height, tx_idx, msg_idx, type) REFERENCES msg_event - ); - -CREATE INDEX IF NOT EXISTS votes_proposal_id_chain_num_idx ON votes (proposal_id, chain_num); - -ALTER TABLE IF EXISTS votes -DROP CONSTRAINT votes_chain_num_proposal_id_voter_ux; - -ALTER TABLE IF EXISTS votes ADD CONSTRAINT votes_chain_num_proposal_id_voter_ux UNIQUE (chain_num, proposal_id, voter); diff --git a/sql/V1_1__fix_msg_attr.sql b/sql/V1_1__fix_msg_attr.sql deleted file mode 100644 index acb0346..0000000 --- a/sql/V1_1__fix_msg_attr.sql +++ /dev/null @@ -1,9 +0,0 @@ -ALTER TABLE msg_event_attr ADD COLUMN value_hash bytea; - -CREATE EXTENSION IF NOT EXISTS pgcrypto; - -UPDATE msg_event_attr SET value_hash = digest(value, 'sha256') WHERE TRUE; - -ALTER TABLE msg_event_attr DROP CONSTRAINT msg_event_attr_pkey; - -ALTER TABLE msg_event_attr ADD PRIMARY KEY (chain_num, block_height, tx_idx, msg_idx, type, key, value_hash); \ No newline at end of file diff --git a/sql/V1_2__add_retirements_table.sql b/sql/V1_2__add_retirements_table.sql deleted file mode 100644 index 2635a05..0000000 --- a/sql/V1_2__add_retirements_table.sql +++ /dev/null @@ -1,27 +0,0 @@ -CREATE TABLE IF NOT EXISTS - retirements ( - TYPE TEXT NOT NULL, - amount TEXT NOT NULL, - batch_denom TEXT NOT NULL, - jurisdiction TEXT NOT NULL, - OWNER TEXT NOT NULL, - reason TEXT NOT NULL, - TIMESTAMP timestamptz, - block_height BIGINT NOT NULL, - chain_num SMALLINT NOT NULL, - tx_idx SMALLINT NOT NULL, - msg_idx SMALLINT NOT NULL, - PRIMARY KEY ( - chain_num, - block_height, - tx_idx, - msg_idx - ), - FOREIGN KEY ( - chain_num, - block_height, - tx_idx, - msg_idx, - TYPE - ) REFERENCES msg_event - ); diff --git a/sql/V1_3__add_msg_event_attr_type_idx.sql b/sql/V1_3__add_msg_event_attr_type_idx.sql deleted file mode 100644 index a4aa9a4..0000000 --- a/sql/V1_3__add_msg_event_attr_type_idx.sql +++ /dev/null @@ -1,3 +0,0 @@ -CREATE INDEX IF NOT EXISTS msg_event_attr_type_idx ON msg_event_attr ( - TYPE -); diff --git a/sql/V1_4__retirements_owner_idx.sql b/sql/V1_4__retirements_owner_idx.sql deleted file mode 100644 index 4641dd8..0000000 --- a/sql/V1_4__retirements_owner_idx.sql +++ /dev/null @@ -1 +0,0 @@ -CREATE INDEX IF NOT EXISTS retirements_owner_idx ON retirements (OWNER); diff --git a/sql/V1_5__add_proposals_table.sql b/sql/V1_5__add_proposals_table.sql deleted file mode 100644 index 79b3f17..0000000 --- a/sql/V1_5__add_proposals_table.sql +++ /dev/null @@ -1,37 +0,0 @@ -CREATE TABLE IF NOT EXISTS - proposals ( - TYPE TEXT NOT NULL, - block_height BIGINT NOT NULL, - tx_idx SMALLINT NOT NULL, - msg_idx SMALLINT NOT NULL, - chain_num SMALLINT NOT NULL, - TIMESTAMP timestamptz, - tx_hash TEXT NOT NULL, - - proposal_id BIGINT NOT NULL, - status TEXT NOT NULL, - group_policy_address TEXT NOT NULL, - metadata TEXT NOT NULL, - proposers TEXT[] NOT NULL, - submit_time timestamptz, - group_version BIGINT NOT NULL, - group_policy_version BIGINT NOT NULL, - final_tally_result JSONB NOT NULL, - voting_period_end timestamptz NOT NULL, - executor_result TEXT NOT NULL, - messages JSONB NOT NULL, - - PRIMARY KEY ( - chain_num, - block_height, - tx_idx, - msg_idx - ), - FOREIGN KEY ( - chain_num, - block_height, - tx_idx, - msg_idx, - TYPE - ) REFERENCES msg_event - ); diff --git a/sql/V1_6__add_tx_hash.sql b/sql/V1_6__add_tx_hash.sql deleted file mode 100644 index fa3c02e..0000000 --- a/sql/V1_6__add_tx_hash.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE retirements -ADD COLUMN IF NOT EXISTS tx_hash TEXT NOT NULL; diff --git a/sql/V1_7__index_group_policy_address.sql b/sql/V1_7__index_group_policy_address.sql deleted file mode 100644 index e3064b2..0000000 --- a/sql/V1_7__index_group_policy_address.sql +++ /dev/null @@ -1 +0,0 @@ -CREATE INDEX IF NOT EXISTS proposals_group_policy_address_idx ON proposals (group_policy_address); diff --git a/sql/V1_8__index_proposal_id.sql b/sql/V1_8__index_proposal_id.sql deleted file mode 100644 index 984be29..0000000 --- a/sql/V1_8__index_proposal_id.sql +++ /dev/null @@ -1 +0,0 @@ -CREATE INDEX IF NOT EXISTS proposals_proposal_id_idx ON proposals (proposal_id); diff --git a/sql/V1_9__all_ecocredit_txes.sql b/sql/V1_9__all_ecocredit_txes.sql deleted file mode 100644 index 9d1316f..0000000 --- a/sql/V1_9__all_ecocredit_txes.sql +++ /dev/null @@ -1,19 +0,0 @@ -DROP INDEX IF EXISTS tx_data_tx_response_code_idx; - -CREATE INDEX IF NOT EXISTS tx_data_tx_response_code_idx ON tx USING BTREE ((DATA -> 'tx_response' -> 'code')); - -CREATE INDEX IF NOT EXISTS msg_event_type_idx ON msg_event ( - TYPE -); - -DROP FUNCTION IF EXISTS all_ecocredit_txes; - -CREATE FUNCTION all_ecocredit_txes () RETURNS SETOF tx AS $$ - select tx.* - from tx - natural join msg_event as me - where - data ->'tx_response'->'code' = '0' - and me.type like 'regen.ecocredit.%' - order by tx.block_height desc -$$ LANGUAGE SQL STABLE; diff --git a/sql/V1__init.sql b/sql/V1__init.sql deleted file mode 100644 index 70d07e4..0000000 --- a/sql/V1__init.sql +++ /dev/null @@ -1,62 +0,0 @@ -CREATE TABLE chain -( - num smallserial primary key, - chain_id text not null unique -); - -CREATE TABLE block -( - chain_num smallint not null references chain, - height BIGINT not null, - data jsonb not null, - time timestamptz not null, - primary key (chain_num, height) -); - -CREATE TABLE tx -( - chain_num smallint not null, - block_height bigint not null, - tx_idx smallint not null, - hash bytea unique not null, - data jsonb not null, - primary key (chain_num, block_height, tx_idx), - foreign key (chain_num, block_height) references block -); - -CREATE TABLE msg -( - chain_num smallint not null, - block_height bigint not null, - tx_idx smallint not null, - msg_idx smallint not null, - data jsonb not null, - primary key (chain_num, block_height, tx_idx, msg_idx), - foreign key (chain_num, block_height, tx_idx) references tx -); - -CREATE INDEX ON msg USING GIN ((data -> '@type')); - -CREATE TABLE msg_event -( - chain_num smallint not null, - block_height bigint not null, - tx_idx smallint not null, - msg_idx smallint not null, - type TEXT not null, - primary key (chain_num, block_height, tx_idx, msg_idx, type), - foreign key (chain_num, block_height, tx_idx, msg_idx) references msg -); - -CREATE TABLE msg_event_attr -( - chain_num smallint not null, - block_height bigint not null, - tx_idx smallint not null, - msg_idx smallint not null, - type TEXT not null, - key text not null, - value text not null, - primary key (chain_num, block_height, tx_idx, msg_idx, type, key, value), - foreign key (chain_num, block_height, tx_idx, msg_idx) references msg -); \ No newline at end of file diff --git a/sql/run_all_migrations.sh b/sql/run_all_migrations.sh deleted file mode 100755 index ab9d2a5..0000000 --- a/sql/run_all_migrations.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env bash -set -o errexit -set -o pipefail -set -o nounset -set -o xtrace -psql -c "\i V1__init.sql" $DATABASE_URL -psql -c "\i V1_1__fix_msg_attr.sql" $DATABASE_URL -psql -c "\i V1_2__add_retirements_table.sql" $DATABASE_URL -psql -c "\i V1_3__add_msg_event_attr_type_idx.sql" $DATABASE_URL -psql -c "\i V1_4__retirements_owner_idx.sql" $DATABASE_URL -psql -c "\i V1_5__add_proposals_table.sql" $DATABASE_URL -psql -c "\i V1_6__add_tx_hash.sql" $DATABASE_URL -psql -c "\i V1_7__index_group_policy_address.sql" $DATABASE_URL -psql -c "\i V1_8__index_proposal_id.sql" $DATABASE_URL -psql -c "\i V1_9__all_ecocredit_txes.sql" $DATABASE_URL -psql -c "\i V1_10__class_issuers.sql" $DATABASE_URL -psql -c "\i V1_11__class_issuers_indexes.sql" $DATABASE_URL -psql -c "\i V1_12__votes.sql" $DATABASE_URL