Skip to content

Commit

Permalink
Merge pull request #37 from vulcanize/version_table
Browse files Browse the repository at this point in the history
singleton table for internally recording the database schema version
  • Loading branch information
i-norden authored Dec 29, 2021
2 parents 762bc36 + e2f261c commit 0e865ad
Show file tree
Hide file tree
Showing 14 changed files with 147 additions and 94 deletions.
9 changes: 9 additions & 0 deletions db/migrations/00017_create_db_version_table.sql
Original file line number Diff line number Diff line change
@@ -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;
6 changes: 6 additions & 0 deletions db/migrations/00018_update_db_version.sql
Original file line number Diff line number Diff line change
@@ -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';
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
@@ -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';
52 changes: 37 additions & 15 deletions schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,6 +25,8 @@ CREATE SCHEMA eth;

SET default_tablespace = '';

SET default_table_access_method = heap;

--
-- Name: header_cids; Type: TABLE; Schema: eth; Owner: -
--
Expand Down Expand Up @@ -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: -
--
Expand Down Expand Up @@ -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: -
--
Expand Down Expand Up @@ -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();


--
Expand Down Expand Up @@ -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;


--
Expand All @@ -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;


--
Expand Down
Binary file modified vulcanize_db.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 0e865ad

Please sign in to comment.