Merge pull request #70 from deep-stack/pm-v4-schema-fixes

Remove foreign keys to hypertables and fix schema dump
This commit is contained in:
Ashwin Phatak 2022-04-26 09:55:37 +05:30 committed by GitHub
commit 96bd0b5d9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 9 additions and 214 deletions

View File

@ -1,3 +1,3 @@
FROM postgres:12-alpine
FROM timescale/timescaledb:latest-pg14
COPY ./schema.sql /docker-entrypoint-initdb.d/init.sql

View File

@ -16,8 +16,7 @@ CREATE TABLE IF NOT EXISTS eth.header_cids (
mh_key TEXT NOT NULL,
times_validated INTEGER NOT NULL DEFAULT 1,
coinbase VARCHAR(66) NOT NULL,
PRIMARY KEY (block_hash, block_number),
FOREIGN KEY (mh_key, block_number) REFERENCES public.blocks (key, block_number) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED
PRIMARY KEY (block_hash, block_number)
);
-- +goose Down

View File

@ -7,9 +7,7 @@ CREATE TABLE IF NOT EXISTS eth.uncle_cids (
cid TEXT NOT NULL,
reward NUMERIC NOT NULL,
mh_key TEXT NOT NULL,
PRIMARY KEY (block_hash, block_number),
FOREIGN KEY (header_id, block_number) REFERENCES eth.header_cids (block_hash, block_number) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
FOREIGN KEY (mh_key, block_number) REFERENCES public.blocks (key, block_number) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED
PRIMARY KEY (block_hash, block_number)
);
-- +goose Down

View File

@ -11,9 +11,7 @@ CREATE TABLE IF NOT EXISTS eth.transaction_cids (
tx_data BYTEA,
tx_type INTEGER,
value NUMERIC,
PRIMARY KEY (tx_hash, block_number),
FOREIGN KEY (header_id, block_number) REFERENCES eth.header_cids (block_hash, block_number) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
FOREIGN KEY (mh_key, block_number) REFERENCES public.blocks (key, block_number) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED
PRIMARY KEY (tx_hash, block_number)
);
-- +goose Down

View File

@ -9,9 +9,7 @@ CREATE TABLE IF NOT EXISTS eth.receipt_cids (
post_state VARCHAR(66),
post_status INTEGER,
log_root VARCHAR(66),
PRIMARY KEY (tx_id, block_number),
FOREIGN KEY (tx_id, block_number) REFERENCES eth.transaction_cids (tx_hash, block_number) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
FOREIGN KEY (leaf_mh_key, block_number) REFERENCES public.blocks (key, block_number) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED
PRIMARY KEY (tx_id, block_number)
);
-- +goose Down

View File

@ -8,9 +8,7 @@ CREATE TABLE IF NOT EXISTS eth.state_cids (
node_type INTEGER NOT NULL,
diff BOOLEAN NOT NULL DEFAULT FALSE,
mh_key TEXT NOT NULL,
PRIMARY KEY (state_path, header_id, block_number),
FOREIGN KEY (header_id, block_number) REFERENCES eth.header_cids (block_hash, block_number) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
FOREIGN KEY (mh_key, block_number) REFERENCES public.blocks (key, block_number) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED
PRIMARY KEY (state_path, header_id, block_number)
);
-- +goose Down

View File

@ -9,8 +9,6 @@ CREATE TABLE IF NOT EXISTS eth.storage_cids (
node_type INTEGER NOT NULL,
diff BOOLEAN NOT NULL DEFAULT FALSE,
mh_key TEXT NOT NULL,
FOREIGN KEY (mh_key, block_number) REFERENCES public.blocks (key, block_number) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
FOREIGN KEY (state_path, header_id, block_number) REFERENCES eth.state_cids (state_path, header_id, block_number) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
PRIMARY KEY (storage_path, state_path, header_id, block_number)
);

View File

@ -7,8 +7,7 @@ CREATE TABLE IF NOT EXISTS eth.state_accounts (
nonce BIGINT NOT NULL,
code_hash BYTEA NOT NULL,
storage_root VARCHAR(66) NOT NULL,
PRIMARY KEY (state_path, header_id, block_number),
FOREIGN KEY (state_path, header_id, block_number) REFERENCES eth.state_cids (state_path, header_id, block_number) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED
PRIMARY KEY (state_path, header_id, block_number)
);
-- +goose Down

View File

@ -5,8 +5,7 @@ CREATE TABLE IF NOT EXISTS eth.access_list_elements (
index INTEGER NOT NULL,
address VARCHAR(66),
storage_keys VARCHAR(66)[],
PRIMARY KEY (tx_id, index, block_number),
FOREIGN KEY (tx_id, block_number) REFERENCES eth.transaction_cids (tx_hash, block_number) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED
PRIMARY KEY (tx_id, index, block_number)
);
-- +goose Down

View File

@ -11,9 +11,7 @@ CREATE TABLE IF NOT EXISTS eth.log_cids (
topic2 VARCHAR(66),
topic3 VARCHAR(66),
log_data BYTEA,
PRIMARY KEY (rct_id, index, block_number),
FOREIGN KEY (rct_id, block_number) REFERENCES eth.receipt_cids (tx_id, block_number) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
FOREIGN KEY (leaf_mh_key, block_number) REFERENCES public.blocks (key, block_number) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED
PRIMARY KEY (rct_id, index, block_number)
);
-- +goose Down

View File

@ -1119,196 +1119,6 @@ CREATE TRIGGER trg_eth_transaction_cids AFTER INSERT ON eth.transaction_cids FOR
CREATE TRIGGER trg_eth_uncle_cids AFTER INSERT ON eth.uncle_cids FOR EACH ROW EXECUTE FUNCTION eth.graphql_subscription();
--
-- Name: access_list_elements ts_insert_blocker; Type: TRIGGER; Schema: eth; Owner: -
--
CREATE TRIGGER ts_insert_blocker BEFORE INSERT ON eth.access_list_elements FOR EACH ROW EXECUTE FUNCTION _timescaledb_internal.insert_blocker();
--
-- Name: header_cids ts_insert_blocker; Type: TRIGGER; Schema: eth; Owner: -
--
CREATE TRIGGER ts_insert_blocker BEFORE INSERT ON eth.header_cids FOR EACH ROW EXECUTE FUNCTION _timescaledb_internal.insert_blocker();
--
-- Name: log_cids ts_insert_blocker; Type: TRIGGER; Schema: eth; Owner: -
--
CREATE TRIGGER ts_insert_blocker BEFORE INSERT ON eth.log_cids FOR EACH ROW EXECUTE FUNCTION _timescaledb_internal.insert_blocker();
--
-- Name: receipt_cids ts_insert_blocker; Type: TRIGGER; Schema: eth; Owner: -
--
CREATE TRIGGER ts_insert_blocker BEFORE INSERT ON eth.receipt_cids FOR EACH ROW EXECUTE FUNCTION _timescaledb_internal.insert_blocker();
--
-- Name: state_accounts ts_insert_blocker; Type: TRIGGER; Schema: eth; Owner: -
--
CREATE TRIGGER ts_insert_blocker BEFORE INSERT ON eth.state_accounts FOR EACH ROW EXECUTE FUNCTION _timescaledb_internal.insert_blocker();
--
-- Name: state_cids ts_insert_blocker; Type: TRIGGER; Schema: eth; Owner: -
--
CREATE TRIGGER ts_insert_blocker BEFORE INSERT ON eth.state_cids FOR EACH ROW EXECUTE FUNCTION _timescaledb_internal.insert_blocker();
--
-- Name: storage_cids ts_insert_blocker; Type: TRIGGER; Schema: eth; Owner: -
--
CREATE TRIGGER ts_insert_blocker BEFORE INSERT ON eth.storage_cids FOR EACH ROW EXECUTE FUNCTION _timescaledb_internal.insert_blocker();
--
-- Name: transaction_cids ts_insert_blocker; Type: TRIGGER; Schema: eth; Owner: -
--
CREATE TRIGGER ts_insert_blocker BEFORE INSERT ON eth.transaction_cids FOR EACH ROW EXECUTE FUNCTION _timescaledb_internal.insert_blocker();
--
-- Name: uncle_cids ts_insert_blocker; Type: TRIGGER; Schema: eth; Owner: -
--
CREATE TRIGGER ts_insert_blocker BEFORE INSERT ON eth.uncle_cids FOR EACH ROW EXECUTE FUNCTION _timescaledb_internal.insert_blocker();
--
-- Name: blocks ts_insert_blocker; Type: TRIGGER; Schema: public; Owner: -
--
CREATE TRIGGER ts_insert_blocker BEFORE INSERT ON public.blocks FOR EACH ROW EXECUTE FUNCTION _timescaledb_internal.insert_blocker();
--
-- Name: access_list_elements access_list_elements_tx_id_block_number_fkey; Type: FK CONSTRAINT; Schema: eth; Owner: -
--
ALTER TABLE ONLY eth.access_list_elements
ADD CONSTRAINT access_list_elements_tx_id_block_number_fkey FOREIGN KEY (tx_id, block_number) REFERENCES eth.transaction_cids(tx_hash, block_number) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;
--
-- Name: header_cids header_cids_mh_key_block_number_fkey; Type: FK CONSTRAINT; Schema: eth; Owner: -
--
ALTER TABLE ONLY eth.header_cids
ADD CONSTRAINT header_cids_mh_key_block_number_fkey FOREIGN KEY (mh_key, block_number) REFERENCES public.blocks(key, block_number) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;
--
-- Name: log_cids log_cids_leaf_mh_key_block_number_fkey; Type: FK CONSTRAINT; Schema: eth; Owner: -
--
ALTER TABLE ONLY eth.log_cids
ADD CONSTRAINT log_cids_leaf_mh_key_block_number_fkey FOREIGN KEY (leaf_mh_key, block_number) REFERENCES public.blocks(key, block_number) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;
--
-- Name: log_cids log_cids_rct_id_block_number_fkey; Type: FK CONSTRAINT; Schema: eth; Owner: -
--
ALTER TABLE ONLY eth.log_cids
ADD CONSTRAINT log_cids_rct_id_block_number_fkey FOREIGN KEY (rct_id, block_number) REFERENCES eth.receipt_cids(tx_id, block_number) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;
--
-- Name: receipt_cids receipt_cids_leaf_mh_key_block_number_fkey; Type: FK CONSTRAINT; Schema: eth; Owner: -
--
ALTER TABLE ONLY eth.receipt_cids
ADD CONSTRAINT receipt_cids_leaf_mh_key_block_number_fkey FOREIGN KEY (leaf_mh_key, block_number) REFERENCES public.blocks(key, block_number) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;
--
-- Name: receipt_cids receipt_cids_tx_id_block_number_fkey; Type: FK CONSTRAINT; Schema: eth; Owner: -
--
ALTER TABLE ONLY eth.receipt_cids
ADD CONSTRAINT receipt_cids_tx_id_block_number_fkey FOREIGN KEY (tx_id, block_number) REFERENCES eth.transaction_cids(tx_hash, block_number) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;
--
-- Name: state_accounts state_accounts_state_path_header_id_block_number_fkey; Type: FK CONSTRAINT; Schema: eth; Owner: -
--
ALTER TABLE ONLY eth.state_accounts
ADD CONSTRAINT state_accounts_state_path_header_id_block_number_fkey FOREIGN KEY (state_path, header_id, block_number) REFERENCES eth.state_cids(state_path, header_id, block_number) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;
--
-- Name: state_cids state_cids_header_id_block_number_fkey; Type: FK CONSTRAINT; Schema: eth; Owner: -
--
ALTER TABLE ONLY eth.state_cids
ADD CONSTRAINT state_cids_header_id_block_number_fkey FOREIGN KEY (header_id, block_number) REFERENCES eth.header_cids(block_hash, block_number) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;
--
-- Name: state_cids state_cids_mh_key_block_number_fkey; Type: FK CONSTRAINT; Schema: eth; Owner: -
--
ALTER TABLE ONLY eth.state_cids
ADD CONSTRAINT state_cids_mh_key_block_number_fkey FOREIGN KEY (mh_key, block_number) REFERENCES public.blocks(key, block_number) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;
--
-- Name: storage_cids storage_cids_mh_key_block_number_fkey; Type: FK CONSTRAINT; Schema: eth; Owner: -
--
ALTER TABLE ONLY eth.storage_cids
ADD CONSTRAINT storage_cids_mh_key_block_number_fkey FOREIGN KEY (mh_key, block_number) REFERENCES public.blocks(key, block_number) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;
--
-- Name: storage_cids storage_cids_state_path_header_id_block_number_fkey; Type: FK CONSTRAINT; Schema: eth; Owner: -
--
ALTER TABLE ONLY eth.storage_cids
ADD CONSTRAINT storage_cids_state_path_header_id_block_number_fkey FOREIGN KEY (state_path, header_id, block_number) REFERENCES eth.state_cids(state_path, header_id, block_number) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;
--
-- Name: transaction_cids transaction_cids_header_id_block_number_fkey; Type: FK CONSTRAINT; Schema: eth; Owner: -
--
ALTER TABLE ONLY eth.transaction_cids
ADD CONSTRAINT transaction_cids_header_id_block_number_fkey FOREIGN KEY (header_id, block_number) REFERENCES eth.header_cids(block_hash, block_number) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;
--
-- Name: transaction_cids transaction_cids_mh_key_block_number_fkey; Type: FK CONSTRAINT; Schema: eth; Owner: -
--
ALTER TABLE ONLY eth.transaction_cids
ADD CONSTRAINT transaction_cids_mh_key_block_number_fkey FOREIGN KEY (mh_key, block_number) REFERENCES public.blocks(key, block_number) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;
--
-- Name: uncle_cids uncle_cids_header_id_block_number_fkey; Type: FK CONSTRAINT; Schema: eth; Owner: -
--
ALTER TABLE ONLY eth.uncle_cids
ADD CONSTRAINT uncle_cids_header_id_block_number_fkey FOREIGN KEY (header_id, block_number) REFERENCES eth.header_cids(block_hash, block_number) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;
--
-- Name: uncle_cids uncle_cids_mh_key_block_number_fkey; Type: FK CONSTRAINT; Schema: eth; Owner: -
--
ALTER TABLE ONLY eth.uncle_cids
ADD CONSTRAINT uncle_cids_mh_key_block_number_fkey FOREIGN KEY (mh_key, block_number) REFERENCES public.blocks(key, block_number) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;
--
-- PostgreSQL database dump complete
--