diff --git a/db/migrations/00017_create_db_version_table.sql b/db/migrations/00017_create_db_version_table.sql new file mode 100644 index 0000000..2cf57e9 --- /dev/null +++ b/db/migrations/00017_create_db_version_table.sql @@ -0,0 +1,9 @@ +-- +goose Up +CREATE TABLE IF NOT EXISTS public.db_version ( + singleton BOOLEAN NOT NULL DEFAULT TRUE UNIQUE CHECK (singleton), + version TEXT NOT NULL, + tstamp TIMESTAMP WITHOUT TIME ZONE DEFAULT NOW() +); + +-- +goose Down +DROP TABLE public.db_version; diff --git a/db/migrations/00018_update_db_version.sql b/db/migrations/00018_update_db_version.sql new file mode 100644 index 0000000..116acd9 --- /dev/null +++ b/db/migrations/00018_update_db_version.sql @@ -0,0 +1,6 @@ +-- +goose Up +INSERT INTO public.db_version (singleton, version) VALUES (true, 'v0.3.2') +ON CONFLICT (singleton) DO UPDATE SET (version, tstamp) = ('v0.3.2', NOW()); + +-- +goose Down +DELETE FROM public.db_version WHERE version = 'v0.3.2'; diff --git a/db/post_batch_processing_migrations/00014_make_tables_logged.sql b/db/post_batch_processing_migrations/00016_make_tables_logged.sql similarity index 100% rename from db/post_batch_processing_migrations/00014_make_tables_logged.sql rename to db/post_batch_processing_migrations/00016_make_tables_logged.sql diff --git a/db/post_batch_processing_migrations/00015_create_pk_constraints.sql b/db/post_batch_processing_migrations/00017_create_pk_constraints.sql similarity index 100% rename from db/post_batch_processing_migrations/00015_create_pk_constraints.sql rename to db/post_batch_processing_migrations/00017_create_pk_constraints.sql diff --git a/db/post_batch_processing_migrations/00016_create_fk_relations.sql b/db/post_batch_processing_migrations/00018_create_fk_relations.sql similarity index 100% rename from db/post_batch_processing_migrations/00016_create_fk_relations.sql rename to db/post_batch_processing_migrations/00018_create_fk_relations.sql diff --git a/db/post_batch_processing_migrations/00017_create_postgraphile_comments.sql b/db/post_batch_processing_migrations/00019_create_postgraphile_comments.sql similarity index 100% rename from db/post_batch_processing_migrations/00017_create_postgraphile_comments.sql rename to db/post_batch_processing_migrations/00019_create_postgraphile_comments.sql diff --git a/db/post_batch_processing_migrations/00018_create_cid_indexes.sql b/db/post_batch_processing_migrations/00020_create_cid_indexes.sql similarity index 100% rename from db/post_batch_processing_migrations/00018_create_cid_indexes.sql rename to db/post_batch_processing_migrations/00020_create_cid_indexes.sql diff --git a/db/post_batch_processing_migrations/00019_create_stored_functions.sql b/db/post_batch_processing_migrations/00021_create_stored_functions.sql similarity index 100% rename from db/post_batch_processing_migrations/00019_create_stored_functions.sql rename to db/post_batch_processing_migrations/00021_create_stored_functions.sql diff --git a/db/post_batch_processing_migrations/00020_create_postgraphile_triggers.sql b/db/post_batch_processing_migrations/00022_create_postgraphile_triggers.sql similarity index 100% rename from db/post_batch_processing_migrations/00020_create_postgraphile_triggers.sql rename to db/post_batch_processing_migrations/00022_create_postgraphile_triggers.sql diff --git a/db/pre_batch_processing_migrations/00014_create_eth_db_version_table.sql b/db/pre_batch_processing_migrations/00014_create_eth_db_version_table.sql new file mode 100644 index 0000000..2cf57e9 --- /dev/null +++ b/db/pre_batch_processing_migrations/00014_create_eth_db_version_table.sql @@ -0,0 +1,9 @@ +-- +goose Up +CREATE TABLE IF NOT EXISTS public.db_version ( + singleton BOOLEAN NOT NULL DEFAULT TRUE UNIQUE CHECK (singleton), + version TEXT NOT NULL, + tstamp TIMESTAMP WITHOUT TIME ZONE DEFAULT NOW() +); + +-- +goose Down +DROP TABLE public.db_version; diff --git a/db/pre_batch_processing_migrations/00015_update_db_version.sql b/db/pre_batch_processing_migrations/00015_update_db_version.sql new file mode 100644 index 0000000..116acd9 --- /dev/null +++ b/db/pre_batch_processing_migrations/00015_update_db_version.sql @@ -0,0 +1,6 @@ +-- +goose Up +INSERT INTO public.db_version (singleton, version) VALUES (true, 'v0.3.2') +ON CONFLICT (singleton) DO UPDATE SET (version, tstamp) = ('v0.3.2', NOW()); + +-- +goose Down +DELETE FROM public.db_version WHERE version = 'v0.3.2'; diff --git a/schema.sql b/schema.sql index ed67184..df83153 100644 --- a/schema.sql +++ b/schema.sql @@ -2,8 +2,8 @@ -- PostgreSQL database dump -- --- Dumped from database version 10.12 --- Dumped by pg_dump version 14.1 +-- Dumped from database version 14beta3 +-- Dumped by pg_dump version 14beta3 SET statement_timeout = 0; SET lock_timeout = 0; @@ -25,6 +25,8 @@ CREATE SCHEMA eth; SET default_tablespace = ''; +SET default_table_access_method = heap; + -- -- Name: header_cids; Type: TABLE; Schema: eth; Owner: - -- @@ -410,6 +412,18 @@ CREATE TABLE public.blocks ( ); +-- +-- Name: db_version; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.db_version ( + singleton boolean DEFAULT true NOT NULL, + version text NOT NULL, + tstamp timestamp without time zone DEFAULT now(), + CONSTRAINT db_version_singleton_check CHECK (singleton) +); + + -- -- Name: goose_db_version; Type: TABLE; Schema: public; Owner: - -- @@ -556,6 +570,14 @@ ALTER TABLE ONLY public.blocks ADD CONSTRAINT blocks_pkey PRIMARY KEY (key); +-- +-- Name: db_version db_version_singleton_key; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.db_version + ADD CONSTRAINT db_version_singleton_key UNIQUE (singleton); + + -- -- Name: goose_db_version goose_db_version_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -835,63 +857,63 @@ CREATE INDEX uncle_header_id_index ON eth.uncle_cids USING btree (header_id); -- Name: access_list_elements trg_eth_access_list_elements; Type: TRIGGER; Schema: eth; Owner: - -- -CREATE TRIGGER trg_eth_access_list_elements AFTER INSERT ON eth.access_list_elements FOR EACH ROW EXECUTE PROCEDURE eth.graphql_subscription(); +CREATE TRIGGER trg_eth_access_list_elements AFTER INSERT ON eth.access_list_elements FOR EACH ROW EXECUTE FUNCTION eth.graphql_subscription(); -- -- Name: header_cids trg_eth_header_cids; Type: TRIGGER; Schema: eth; Owner: - -- -CREATE TRIGGER trg_eth_header_cids AFTER INSERT ON eth.header_cids FOR EACH ROW EXECUTE PROCEDURE eth.graphql_subscription(); +CREATE TRIGGER trg_eth_header_cids AFTER INSERT ON eth.header_cids FOR EACH ROW EXECUTE FUNCTION eth.graphql_subscription(); -- -- Name: log_cids trg_eth_log_cids; Type: TRIGGER; Schema: eth; Owner: - -- -CREATE TRIGGER trg_eth_log_cids AFTER INSERT ON eth.log_cids FOR EACH ROW EXECUTE PROCEDURE eth.graphql_subscription(); +CREATE TRIGGER trg_eth_log_cids AFTER INSERT ON eth.log_cids FOR EACH ROW EXECUTE FUNCTION eth.graphql_subscription(); -- -- Name: receipt_cids trg_eth_receipt_cids; Type: TRIGGER; Schema: eth; Owner: - -- -CREATE TRIGGER trg_eth_receipt_cids AFTER INSERT ON eth.receipt_cids FOR EACH ROW EXECUTE PROCEDURE eth.graphql_subscription(); +CREATE TRIGGER trg_eth_receipt_cids AFTER INSERT ON eth.receipt_cids FOR EACH ROW EXECUTE FUNCTION eth.graphql_subscription(); -- -- Name: state_accounts trg_eth_state_accounts; Type: TRIGGER; Schema: eth; Owner: - -- -CREATE TRIGGER trg_eth_state_accounts AFTER INSERT ON eth.state_accounts FOR EACH ROW EXECUTE PROCEDURE eth.graphql_subscription(); +CREATE TRIGGER trg_eth_state_accounts AFTER INSERT ON eth.state_accounts FOR EACH ROW EXECUTE FUNCTION eth.graphql_subscription(); -- -- Name: state_cids trg_eth_state_cids; Type: TRIGGER; Schema: eth; Owner: - -- -CREATE TRIGGER trg_eth_state_cids AFTER INSERT ON eth.state_cids FOR EACH ROW EXECUTE PROCEDURE eth.graphql_subscription(); +CREATE TRIGGER trg_eth_state_cids AFTER INSERT ON eth.state_cids FOR EACH ROW EXECUTE FUNCTION eth.graphql_subscription(); -- -- Name: storage_cids trg_eth_storage_cids; Type: TRIGGER; Schema: eth; Owner: - -- -CREATE TRIGGER trg_eth_storage_cids AFTER INSERT ON eth.storage_cids FOR EACH ROW EXECUTE PROCEDURE eth.graphql_subscription(); +CREATE TRIGGER trg_eth_storage_cids AFTER INSERT ON eth.storage_cids FOR EACH ROW EXECUTE FUNCTION eth.graphql_subscription(); -- -- Name: transaction_cids trg_eth_transaction_cids; Type: TRIGGER; Schema: eth; Owner: - -- -CREATE TRIGGER trg_eth_transaction_cids AFTER INSERT ON eth.transaction_cids FOR EACH ROW EXECUTE PROCEDURE eth.graphql_subscription(); +CREATE TRIGGER trg_eth_transaction_cids AFTER INSERT ON eth.transaction_cids FOR EACH ROW EXECUTE FUNCTION eth.graphql_subscription(); -- -- Name: uncle_cids trg_eth_uncle_cids; Type: TRIGGER; Schema: eth; Owner: - -- -CREATE TRIGGER trg_eth_uncle_cids AFTER INSERT ON eth.uncle_cids FOR EACH ROW EXECUTE PROCEDURE eth.graphql_subscription(); +CREATE TRIGGER trg_eth_uncle_cids AFTER INSERT ON eth.uncle_cids FOR EACH ROW EXECUTE FUNCTION eth.graphql_subscription(); -- @@ -951,11 +973,11 @@ ALTER TABLE ONLY eth.receipt_cids -- --- Name: state_accounts state_accounts_header_id_fkey; Type: FK CONSTRAINT; Schema: eth; Owner: - +-- Name: state_accounts state_accounts_header_id_state_path_fkey; Type: FK CONSTRAINT; Schema: eth; Owner: - -- ALTER TABLE ONLY eth.state_accounts - ADD CONSTRAINT state_accounts_header_id_fkey FOREIGN KEY (header_id, state_path) REFERENCES eth.state_cids(header_id, state_path) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; + ADD CONSTRAINT state_accounts_header_id_state_path_fkey FOREIGN KEY (header_id, state_path) REFERENCES eth.state_cids(header_id, state_path) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; -- @@ -975,11 +997,11 @@ ALTER TABLE ONLY eth.state_cids -- --- Name: storage_cids storage_cids_header_id_fkey; Type: FK CONSTRAINT; Schema: eth; Owner: - +-- Name: storage_cids storage_cids_header_id_state_path_fkey; Type: FK CONSTRAINT; Schema: eth; Owner: - -- ALTER TABLE ONLY eth.storage_cids - ADD CONSTRAINT storage_cids_header_id_fkey FOREIGN KEY (header_id, state_path) REFERENCES eth.state_cids(header_id, state_path) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; + ADD CONSTRAINT storage_cids_header_id_state_path_fkey FOREIGN KEY (header_id, state_path) REFERENCES eth.state_cids(header_id, state_path) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; -- diff --git a/vulcanize_db.png b/vulcanize_db.png index 0e691a2..35ee8a6 100644 Binary files a/vulcanize_db.png and b/vulcanize_db.png differ diff --git a/vulcanize_db.uml b/vulcanize_db.uml index b710cfa..65094e7 100644 --- a/vulcanize_db.uml +++ b/vulcanize_db.uml @@ -3,145 +3,146 @@ DATABASE 407978cb-39e6-453c-b9b7-c4183a4e26ef - 407978cb-39e6-453c-b9b7-c4183a4e26ef.TABLE:vulcanize_test.eth.header_cids - 407978cb-39e6-453c-b9b7-c4183a4e26ef.TABLE:vulcanize_test.eth.receipt_cids - 407978cb-39e6-453c-b9b7-c4183a4e26ef.TABLE:vulcanize_test.public.nodes - 407978cb-39e6-453c-b9b7-c4183a4e26ef.TABLE:vulcanize_test.eth.state_accounts - 407978cb-39e6-453c-b9b7-c4183a4e26ef.TABLE:vulcanize_test.eth.uncle_cids - 407978cb-39e6-453c-b9b7-c4183a4e26ef.TABLE:vulcanize_test.public.blocks - 407978cb-39e6-453c-b9b7-c4183a4e26ef.TABLE:vulcanize_test.eth.transaction_cids - 407978cb-39e6-453c-b9b7-c4183a4e26ef.TABLE:vulcanize_test.eth.access_list_elements - 407978cb-39e6-453c-b9b7-c4183a4e26ef.TABLE:vulcanize_test.eth.state_cids - 407978cb-39e6-453c-b9b7-c4183a4e26ef.TABLE:vulcanize_test.eth.log_cids - 407978cb-39e6-453c-b9b7-c4183a4e26ef.TABLE:vulcanize_test.public.goose_db_version - 407978cb-39e6-453c-b9b7-c4183a4e26ef.TABLE:vulcanize_test.eth.storage_cids + 407978cb-39e6-453c-b9b7-c4183a4e26ef.TABLE:vulcanize_test.eth.header_cids + 407978cb-39e6-453c-b9b7-c4183a4e26ef.TABLE:vulcanize_test.eth.receipt_cids + 407978cb-39e6-453c-b9b7-c4183a4e26ef.TABLE:vulcanize_test.eth.state_accounts + 407978cb-39e6-453c-b9b7-c4183a4e26ef.TABLE:vulcanize_test.public.nodes + 407978cb-39e6-453c-b9b7-c4183a4e26ef.TABLE:vulcanize_test.eth.uncle_cids + 407978cb-39e6-453c-b9b7-c4183a4e26ef.TABLE:vulcanize_test.public.blocks + 407978cb-39e6-453c-b9b7-c4183a4e26ef.TABLE:vulcanize_test.eth.transaction_cids + 407978cb-39e6-453c-b9b7-c4183a4e26ef.TABLE:vulcanize_test.eth.access_list_elements + 407978cb-39e6-453c-b9b7-c4183a4e26ef.TABLE:vulcanize_test.eth.state_cids + 407978cb-39e6-453c-b9b7-c4183a4e26ef.TABLE:vulcanize_test.public.db_version + 407978cb-39e6-453c-b9b7-c4183a4e26ef.TABLE:vulcanize_test.eth.log_cids + 407978cb-39e6-453c-b9b7-c4183a4e26ef.TABLE:vulcanize_test.public.goose_db_version + 407978cb-39e6-453c-b9b7-c4183a4e26ef.TABLE:vulcanize_test.eth.storage_cids - - + + - - + + - - - - - - + + + + + + - - + + - - - - - - + + + + + + - - - - - - - - - - - - + + + + + + + + + + + + - - + + - - - - - - - - - - - - + + + + + + + + + + + + - - + + - - + + - - + + - - - - + + + + - - - - - - + + + + + + - - - - - - + + + + + + - + Columns