Merge pull request #48 from vulcanize/consolidate-migrations

Consolidate migrations
This commit is contained in:
Rob Mulholand 2019-03-28 14:26:51 -05:00 committed by GitHub
commit 48f6114791
48 changed files with 103 additions and 409 deletions

View File

@ -1,9 +1,23 @@
-- +goose Up -- +goose Up
CREATE TABLE public.blocks CREATE TABLE public.blocks (
( id SERIAL PRIMARY KEY,
block_number BIGINT difficulty BIGINT,
extra_data VARCHAR,
gaslimit BIGINT,
gasused BIGINT,
hash VARCHAR(66),
miner VARCHAR(42),
nonce VARCHAR(20),
"number" BIGINT,
parenthash VARCHAR(66),
reward DOUBLE PRECISION,
uncles_reward DOUBLE PRECISION,
"size" VARCHAR,
"time" BIGINT,
is_final BOOLEAN,
uncle_hash VARCHAR(66)
); );
-- +goose Down -- +goose Down
DROP TABLE public.blocks; DROP TABLE public.blocks;

View File

@ -1,13 +0,0 @@
-- +goose Up
ALTER TABLE blocks
ADD COLUMN block_gaslimit DOUBLE PRECISION,
ADD COLUMN block_gasused DOUBLE PRECISION,
ADD COLUMN block_time DOUBLE PRECISION;
-- +goose Down
ALTER TABLE blocks
DROP COLUMN block_gaslimit,
DROP COLUMN block_gasused,
DROP COLUMN block_time;

View File

@ -0,0 +1,16 @@
-- +goose Up
CREATE TABLE transactions (
id SERIAL PRIMARY KEY,
block_id INTEGER NOT NULL REFERENCES blocks(id) ON DELETE CASCADE,
input_data VARCHAR,
tx_from VARCHAR(66),
gaslimit NUMERIC,
gasprice NUMERIC,
hash VARCHAR(66),
nonce NUMERIC,
tx_to VARCHAR(66),
"value" NUMERIC
);
-- +goose Down
DROP TABLE transactions;

View File

@ -0,0 +1,6 @@
-- +goose Up
CREATE INDEX number_index ON blocks (number);
-- +goose Down
DROP INDEX number_index;

View File

@ -1,14 +0,0 @@
-- +goose Up
CREATE TABLE transactions
(
id SERIAL PRIMARY KEY,
tx_hash VARCHAR(66),
tx_nonce NUMERIC,
tx_to varchar(66),
tx_gaslimit NUMERIC,
tx_gasprice NUMERIC,
tx_value NUMERIC
);
-- +goose Down
DROP TABLE transactions;

View File

@ -1,5 +0,0 @@
-- +goose Up
ALTER TABLE blocks ADD COLUMN id SERIAL PRIMARY KEY;
-- +goose Down
ALTER TABLE blocks DROP id;

View File

@ -1,8 +1,9 @@
-- +goose Up -- +goose Up
CREATE TABLE watched_contracts CREATE TABLE watched_contracts
( (
contract_id SERIAL PRIMARY KEY, contract_id SERIAL PRIMARY KEY,
contract_hash VARCHAR(66) contract_abi json,
contract_hash VARCHAR(66) UNIQUE
); );
-- +goose Down -- +goose Down

View File

@ -1,11 +0,0 @@
-- +goose Up
ALTER TABLE transactions
ADD COLUMN block_id INTEGER NOT NULL,
ADD CONSTRAINT fk_test
FOREIGN KEY (block_id)
REFERENCES blocks (id);
-- +goose Down
ALTER TABLE transactions
DROP COLUMN block_id;

View File

@ -0,0 +1,12 @@
-- +goose Up
CREATE TABLE nodes (
id SERIAL PRIMARY KEY,
client_name VARCHAR,
genesis_block VARCHAR(66),
network_id NUMERIC,
node_id VARCHAR(128),
CONSTRAINT node_uc UNIQUE (genesis_block, network_id, node_id)
);
-- +goose Down
DROP TABLE nodes;

View File

@ -1,6 +0,0 @@
-- +goose Up
CREATE INDEX block_number_index ON blocks (block_number);
-- +goose Down
DROP INDEX block_number_index;

View File

@ -3,7 +3,8 @@ ALTER TABLE blocks
ADD COLUMN node_id INTEGER NOT NULL, ADD COLUMN node_id INTEGER NOT NULL,
ADD CONSTRAINT node_fk ADD CONSTRAINT node_fk
FOREIGN KEY (node_id) FOREIGN KEY (node_id)
REFERENCES nodes (id); REFERENCES nodes (id)
ON DELETE CASCADE;
-- +goose Down -- +goose Down
ALTER TABLE blocks ALTER TABLE blocks

View File

@ -1,18 +0,0 @@
-- +goose Up
ALTER TABLE blocks
ADD COLUMN block_difficulty BIGINT,
ADD COLUMN block_hash VARCHAR(66),
ADD COLUMN block_nonce VARCHAR(20),
ADD COLUMN block_parenthash VARCHAR(66),
ADD COLUMN block_size BIGINT,
ADD COLUMN uncle_hash VARCHAR(66);
-- +goose Down
ALTER TABLE blocks
Drop COLUMN block_difficulty,
Drop COLUMN block_hash,
drop COLUMN block_nonce,
drop COLUMN block_parenthash,
drop COLUMN block_size,
drop COLUMN uncle_hash;

View File

@ -1,6 +1,6 @@
-- +goose Up -- +goose Up
ALTER TABLE blocks ALTER TABLE blocks
ADD CONSTRAINT node_id_block_number_uc UNIQUE (block_number, node_id); ADD CONSTRAINT node_id_block_number_uc UNIQUE (number, node_id);
-- +goose Down -- +goose Down
ALTER TABLE blocks ALTER TABLE blocks

View File

@ -1,8 +0,0 @@
-- +goose Up
ALTER TABLE transactions
ADD COLUMN tx_from VARCHAR(66);
-- +goose Down
ALTER TABLE transactions
DROP COLUMN tx_from;

View File

@ -1,7 +0,0 @@
-- +goose Up
ALTER TABLE watched_contracts
ADD COLUMN contract_abi json;
-- +goose Down
ALTER TABLE watched_contracts
DROP COLUMN contract_abi;

View File

@ -1,10 +0,0 @@
-- +goose Up
CREATE TABLE nodes (
id SERIAL PRIMARY KEY,
genesis_block VARCHAR(66),
network_id NUMERIC,
CONSTRAINT node_uc UNIQUE (genesis_block, network_id)
);
-- +goose Down
DROP TABLE nodes;

View File

@ -1,8 +0,0 @@
-- +goose Up
ALTER TABLE watched_contracts
ADD CONSTRAINT contract_hash_uc UNIQUE (contract_hash);
-- +goose Down
ALTER TABLE watched_contracts
DROP CONSTRAINT contract_hash_uc;

View File

@ -1,19 +0,0 @@
-- +goose Up
ALTER TABLE transactions
DROP CONSTRAINT fk_test;
ALTER TABLE transactions
ADD CONSTRAINT blocks_fk
FOREIGN KEY (block_id)
REFERENCES blocks (id)
ON DELETE CASCADE;
-- +goose Down
ALTER TABLE transactions
DROP CONSTRAINT blocks_fk;
ALTER TABLE transactions
ADD CONSTRAINT fk_test
FOREIGN KEY (block_id)
REFERENCES blocks (id);

View File

@ -1,18 +0,0 @@
-- +goose Up
ALTER TABLE blocks
DROP CONSTRAINT node_fk;
ALTER TABLE blocks
ADD CONSTRAINT node_fk
FOREIGN KEY (node_id)
REFERENCES nodes (id)
ON DELETE CASCADE;
-- +goose Down
ALTER TABLE blocks
DROP CONSTRAINT node_fk;
ALTER TABLE blocks
ADD CONSTRAINT node_fk
FOREIGN KEY (node_id)
REFERENCES nodes (id);

View File

@ -1,7 +0,0 @@
-- +goose Up
ALTER TABLE blocks
ADD COLUMN is_final BOOLEAN;
-- +goose Down
ALTER TABLE blocks
DROP COLUMN is_final;

View File

@ -1,7 +0,0 @@
-- +goose Up
ALTER TABLE blocks
ADD COLUMN block_miner VARCHAR(42);
-- +goose Down
ALTER TABLE blocks
DROP COLUMN block_miner;

View File

@ -1,7 +0,0 @@
-- +goose Up
ALTER TABLE blocks
ADD COLUMN block_extra_data VARCHAR;
-- +goose Down
ALTER TABLE blocks
DROP COLUMN block_extra_data;

View File

@ -1,10 +0,0 @@
-- +goose Up
ALTER TABLE blocks
ADD COLUMN block_reward NUMERIC,
ADD COLUMN block_uncles_reward NUMERIC;
-- +goose Down
ALTER TABLE blocks
DROP COLUMN block_reward,
DROP COLUMN block_uncles_reward;

View File

@ -1,7 +0,0 @@
-- +goose Up
ALTER TABLE transactions
ADD COLUMN tx_input_data VARCHAR;
-- +goose Down
ALTER TABLE transactions
DROP COLUMN tx_input_data;

View File

@ -1,9 +0,0 @@
-- +goose Up
ALTER TABLE nodes
ADD COLUMN node_id VARCHAR(128),
ADD COLUMN client_name VARCHAR;
-- +goose Down
ALTER TABLE nodes
DROP COLUMN node_id,
DROP COLUMN client_name;

View File

@ -1,14 +0,0 @@
-- +goose Up
ALTER TABLE nodes
DROP CONSTRAINT node_uc;
ALTER TABLE nodes
ADD CONSTRAINT node_uc UNIQUE (genesis_block, network_id, node_id);
-- +goose Down
ALTER TABLE nodes
DROP CONSTRAINT node_uc;
ALTER TABLE nodes
ADD CONSTRAINT node_uc UNIQUE (genesis_block, network_id);

View File

@ -1,32 +0,0 @@
-- +goose Up
ALTER TABLE blocks
ALTER COLUMN block_gaslimit TYPE BIGINT USING block_gaslimit :: BIGINT;
ALTER TABLE blocks
ALTER COLUMN block_gasused TYPE BIGINT USING block_gasused :: BIGINT;
ALTER TABLE blocks
ALTER COLUMN block_time TYPE BIGINT USING block_time :: BIGINT;
ALTER TABLE blocks
ALTER COLUMN block_reward TYPE DOUBLE PRECISION USING block_time :: DOUBLE PRECISION;
ALTER TABLE blocks
ALTER COLUMN block_uncles_reward TYPE DOUBLE PRECISION USING block_time :: DOUBLE PRECISION;
-- +goose Down
ALTER TABLE blocks
ALTER COLUMN block_gaslimit TYPE DOUBLE PRECISION USING block_gaslimit :: DOUBLE PRECISION;
ALTER TABLE blocks
ALTER COLUMN block_gasused TYPE DOUBLE PRECISION USING block_gasused :: DOUBLE PRECISION;
ALTER TABLE blocks
ALTER COLUMN block_time TYPE DOUBLE PRECISION USING block_time :: DOUBLE PRECISION;
ALTER TABLE blocks
ALTER COLUMN block_reward TYPE NUMERIC USING block_time :: NUMERIC;
ALTER TABLE blocks
ALTER COLUMN block_uncles_reward TYPE NUMERIC USING block_time :: NUMERIC;

View File

@ -1,80 +0,0 @@
-- +goose Up
ALTER TABLE blocks
RENAME COLUMN block_number TO number;
ALTER TABLE blocks
RENAME COLUMN block_gaslimit TO gaslimit;
ALTER TABLE blocks
RENAME COLUMN block_gasused TO gasused;
ALTER TABLE blocks
RENAME COLUMN block_time TO time;
ALTER TABLE blocks
RENAME COLUMN block_difficulty TO difficulty;
ALTER TABLE blocks
RENAME COLUMN block_hash TO hash;
ALTER TABLE blocks
RENAME COLUMN block_nonce TO nonce;
ALTER TABLE blocks
RENAME COLUMN block_parenthash TO parenthash;
ALTER TABLE blocks
RENAME COLUMN block_size TO size;
ALTER TABLE blocks
RENAME COLUMN block_miner TO miner;
ALTER TABLE blocks
RENAME COLUMN block_extra_data TO extra_data;
ALTER TABLE blocks
RENAME COLUMN block_reward TO reward;
ALTER TABLE blocks
RENAME COLUMN block_uncles_reward TO uncles_reward;
-- +goose Down
ALTER TABLE blocks
RENAME COLUMN number TO block_number;
ALTER TABLE blocks
RENAME COLUMN gaslimit TO block_gaslimit;
ALTER TABLE blocks
RENAME COLUMN gasused TO block_gasused;
ALTER TABLE blocks
RENAME COLUMN TIME TO block_time;
ALTER TABLE blocks
RENAME COLUMN difficulty TO block_difficulty;
ALTER TABLE blocks
RENAME COLUMN HASH TO block_hash;
ALTER TABLE blocks
RENAME COLUMN nonce TO block_nonce;
ALTER TABLE blocks
RENAME COLUMN parenthash TO block_parenthash;
ALTER TABLE blocks
RENAME COLUMN size TO block_size;
ALTER TABLE blocks
RENAME COLUMN miner TO block_miner;
ALTER TABLE blocks
RENAME COLUMN extra_data TO block_extra_data;
ALTER TABLE blocks
RENAME COLUMN reward TO block_reward;
ALTER TABLE blocks
RENAME COLUMN uncles_reward TO block_uncles_reward;

View File

@ -1,38 +0,0 @@
-- +goose Up
ALTER TABLE transactions
RENAME COLUMN tx_hash TO hash;
ALTER TABLE transactions
RENAME COLUMN tx_nonce TO nonce;
ALTER TABLE transactions
RENAME COLUMN tx_gaslimit TO gaslimit;
ALTER TABLE transactions
RENAME COLUMN tx_gasprice TO gasprice;
ALTER TABLE transactions
RENAME COLUMN tx_value TO value;
ALTER TABLE transactions
RENAME COLUMN tx_input_data TO input_data;
-- +goose Down
ALTER TABLE transactions
RENAME COLUMN hash TO tx_hash;
ALTER TABLE transactions
RENAME COLUMN nonce TO tx_nonce;
ALTER TABLE transactions
RENAME COLUMN gaslimit TO tx_gaslimit;
ALTER TABLE transactions
RENAME COLUMN gasprice TO tx_gasprice;
ALTER TABLE transactions
RENAME COLUMN value TO tx_value;
ALTER TABLE transactions
RENAME COLUMN input_data TO tx_input_data;

View File

@ -1,8 +0,0 @@
-- +goose Up
ALTER TABLE blocks
ALTER COLUMN size TYPE VARCHAR USING size::VARCHAR;
-- +goose Down
ALTER TABLE blocks
ALTER COLUMN size TYPE BIGINT USING size::BIGINT;

View File

@ -67,23 +67,23 @@ CREATE VIEW public.block_stats AS
-- --
CREATE TABLE public.blocks ( CREATE TABLE public.blocks (
number bigint,
gaslimit bigint,
gasused bigint,
"time" bigint,
id integer NOT NULL, id integer NOT NULL,
difficulty bigint, difficulty bigint,
hash character varying(66),
nonce character varying(20),
parenthash character varying(66),
size character varying,
uncle_hash character varying(66),
eth_node_id integer NOT NULL,
is_final boolean,
miner character varying(42),
extra_data character varying, extra_data character varying,
gaslimit bigint,
gasused bigint,
hash character varying(66),
miner character varying(42),
nonce character varying(20),
number bigint,
parenthash character varying(66),
reward double precision, reward double precision,
uncles_reward double precision, uncles_reward double precision,
size character varying,
"time" bigint,
is_final boolean,
uncle_hash character varying(66),
eth_node_id integer NOT NULL,
eth_node_fingerprint character varying(128) NOT NULL eth_node_fingerprint character varying(128) NOT NULL
); );
@ -144,10 +144,10 @@ ALTER SEQUENCE public.checked_headers_id_seq OWNED BY public.checked_headers.id;
CREATE TABLE public.eth_nodes ( CREATE TABLE public.eth_nodes (
id integer NOT NULL, id integer NOT NULL,
client_name character varying,
genesis_block character varying(66), genesis_block character varying(66),
network_id numeric, network_id numeric,
eth_node_id character varying(128), eth_node_id character varying(128)
client_name character varying
); );
@ -374,15 +374,15 @@ ALTER SEQUENCE public.receipts_id_seq OWNED BY public.receipts.id;
CREATE TABLE public.transactions ( CREATE TABLE public.transactions (
id integer NOT NULL, id integer NOT NULL,
block_id integer NOT NULL,
input_data character varying,
tx_from character varying(66),
gaslimit numeric,
gasprice numeric,
hash character varying(66), hash character varying(66),
nonce numeric, nonce numeric,
tx_to character varying(66), tx_to character varying(66),
gaslimit numeric, value numeric
gasprice numeric,
value numeric,
block_id integer NOT NULL,
tx_from character varying(66),
input_data character varying
); );
@ -412,8 +412,8 @@ ALTER SEQUENCE public.transactions_id_seq OWNED BY public.transactions.id;
CREATE TABLE public.watched_contracts ( CREATE TABLE public.watched_contracts (
contract_id integer NOT NULL, contract_id integer NOT NULL,
contract_hash character varying(66), contract_abi json,
contract_abi json contract_hash character varying(66)
); );
@ -561,14 +561,6 @@ ALTER TABLE ONLY public.checked_headers
ADD CONSTRAINT checked_headers_pkey PRIMARY KEY (id); ADD CONSTRAINT checked_headers_pkey PRIMARY KEY (id);
--
-- Name: watched_contracts contract_hash_uc; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.watched_contracts
ADD CONSTRAINT contract_hash_uc UNIQUE (contract_hash);
-- --
-- Name: blocks eth_node_id_block_number_uc; Type: CONSTRAINT; Schema: public; Owner: - -- Name: blocks eth_node_id_block_number_uc; Type: CONSTRAINT; Schema: public; Owner: -
-- --
@ -649,6 +641,14 @@ ALTER TABLE ONLY public.transactions
ADD CONSTRAINT transactions_pkey PRIMARY KEY (id); ADD CONSTRAINT transactions_pkey PRIMARY KEY (id);
--
-- Name: watched_contracts watched_contracts_contract_hash_key; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.watched_contracts
ADD CONSTRAINT watched_contracts_contract_hash_key UNIQUE (contract_hash);
-- --
-- Name: watched_contracts watched_contracts_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- Name: watched_contracts watched_contracts_pkey; Type: CONSTRAINT; Schema: public; Owner: -
-- --
@ -664,13 +664,6 @@ ALTER TABLE ONLY public.watched_contracts
CREATE INDEX block_id_index ON public.transactions USING btree (block_id); CREATE INDEX block_id_index ON public.transactions USING btree (block_id);
--
-- Name: block_number_index; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX block_number_index ON public.blocks USING btree (number);
-- --
-- Name: headers_block_number; Type: INDEX; Schema: public; Owner: - -- Name: headers_block_number; Type: INDEX; Schema: public; Owner: -
-- --
@ -685,6 +678,13 @@ CREATE INDEX headers_block_number ON public.headers USING btree (block_number);
CREATE INDEX node_id_index ON public.blocks USING btree (eth_node_id); CREATE INDEX node_id_index ON public.blocks USING btree (eth_node_id);
--
-- Name: number_index; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX number_index ON public.blocks USING btree (number);
-- --
-- Name: tx_from_index; Type: INDEX; Schema: public; Owner: - -- Name: tx_from_index; Type: INDEX; Schema: public; Owner: -
-- --
@ -699,14 +699,6 @@ CREATE INDEX tx_from_index ON public.transactions USING btree (tx_from);
CREATE INDEX tx_to_index ON public.transactions USING btree (tx_to); CREATE INDEX tx_to_index ON public.transactions USING btree (tx_to);
--
-- Name: transactions blocks_fk; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.transactions
ADD CONSTRAINT blocks_fk FOREIGN KEY (block_id) REFERENCES public.blocks(id) ON DELETE CASCADE;
-- --
-- Name: receipts blocks_fk; Type: FK CONSTRAINT; Schema: public; Owner: - -- Name: receipts blocks_fk; Type: FK CONSTRAINT; Schema: public; Owner: -
-- --
@ -747,6 +739,14 @@ ALTER TABLE ONLY public.logs
ADD CONSTRAINT receipts_fk FOREIGN KEY (receipt_id) REFERENCES public.receipts(id) ON DELETE CASCADE; ADD CONSTRAINT receipts_fk FOREIGN KEY (receipt_id) REFERENCES public.receipts(id) ON DELETE CASCADE;
--
-- Name: transactions transactions_block_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.transactions
ADD CONSTRAINT transactions_block_id_fkey FOREIGN KEY (block_id) REFERENCES public.blocks(id) ON DELETE CASCADE;
-- --
-- PostgreSQL database dump complete -- PostgreSQL database dump complete
-- --