Remove extraneous migration formatting

This commit is contained in:
Rob Mulholand 2019-08-26 22:11:28 -05:00
parent 666ea1c325
commit 222252f89a
17 changed files with 150 additions and 167 deletions

View File

@ -1,22 +1,21 @@
-- +goose Up -- +goose Up
CREATE TABLE public.blocks CREATE TABLE public.blocks (
( id SERIAL PRIMARY KEY,
id SERIAL PRIMARY KEY, difficulty BIGINT,
difficulty BIGINT, extra_data VARCHAR,
extra_data VARCHAR, gas_limit BIGINT,
gas_limit BIGINT, gas_used BIGINT,
gas_used BIGINT, hash VARCHAR(66),
hash VARCHAR(66), miner VARCHAR(42),
miner VARCHAR(42), nonce VARCHAR(20),
nonce VARCHAR(20), "number" BIGINT,
"number" BIGINT, parent_hash VARCHAR(66),
parent_hash VARCHAR(66), reward NUMERIC,
reward NUMERIC, uncles_reward NUMERIC,
uncles_reward NUMERIC, "size" VARCHAR,
"size" VARCHAR, "time" BIGINT,
"time" BIGINT, is_final BOOLEAN,
is_final BOOLEAN, uncle_hash VARCHAR(66)
uncle_hash VARCHAR(66)
); );

View File

@ -1,18 +1,17 @@
-- +goose Up -- +goose Up
CREATE TABLE full_sync_transactions CREATE TABLE full_sync_transactions (
( id SERIAL PRIMARY KEY,
id SERIAL PRIMARY KEY, block_id INTEGER NOT NULL REFERENCES blocks(id) ON DELETE CASCADE,
block_id INTEGER NOT NULL REFERENCES blocks (id) ON DELETE CASCADE, gas_limit NUMERIC,
gas_limit NUMERIC, gas_price NUMERIC,
gas_price NUMERIC, hash VARCHAR(66),
hash VARCHAR(66), input_data BYTEA,
input_data BYTEA, nonce NUMERIC,
nonce NUMERIC, raw BYTEA,
raw BYTEA, tx_from VARCHAR(66),
tx_from VARCHAR(66), tx_index INTEGER,
tx_index INTEGER, tx_to VARCHAR(66),
tx_to VARCHAR(66), "value" NUMERIC
"value" NUMERIC
); );
-- +goose Down -- +goose Down

View File

@ -1,9 +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_abi json, contract_abi json,
contract_hash VARCHAR(66) UNIQUE contract_hash VARCHAR(66) UNIQUE
); );
-- +goose Down -- +goose Down

View File

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

View File

@ -1,11 +1,11 @@
-- +goose Up -- +goose Up
ALTER TABLE blocks 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; ON DELETE CASCADE;
-- +goose Down -- +goose Down
ALTER TABLE blocks ALTER TABLE blocks
DROP COLUMN node_id; DROP COLUMN node_id;

View File

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

View File

@ -1,5 +1,5 @@
-- +goose Up -- +goose Up
CREATE INDEX tx_to_index ON full_sync_transactions (tx_to); CREATE INDEX tx_to_index ON full_sync_transactions(tx_to);
-- +goose Down -- +goose Down
DROP INDEX tx_to_index; DROP INDEX tx_to_index;

View File

@ -1,5 +1,5 @@
-- +goose Up -- +goose Up
CREATE INDEX tx_from_index ON full_sync_transactions (tx_from); CREATE INDEX tx_from_index ON full_sync_transactions(tx_from);
-- +goose Down -- +goose Down
DROP INDEX tx_from_index; DROP INDEX tx_from_index;

View File

@ -1,16 +1,15 @@
-- +goose Up -- +goose Up
CREATE TABLE log_filters CREATE TABLE log_filters (
( id SERIAL,
id SERIAL, name VARCHAR NOT NULL CHECK (name <> ''),
name VARCHAR NOT NULL CHECK (name <> ''), from_block BIGINT CHECK (from_block >= 0),
from_block BIGINT CHECK (from_block >= 0), to_block BIGINT CHECK (from_block >= 0),
to_block BIGINT CHECK (from_block >= 0), address VARCHAR(66),
address VARCHAR(66), topic0 VARCHAR(66),
topic0 VARCHAR(66), topic1 VARCHAR(66),
topic1 VARCHAR(66), topic2 VARCHAR(66),
topic2 VARCHAR(66), topic3 VARCHAR(66),
topic3 VARCHAR(66), CONSTRAINT name_uc UNIQUE (name)
CONSTRAINT name_uc UNIQUE (name)
); );
-- +goose Down -- +goose Down

View File

@ -1,14 +1,14 @@
-- +goose Up -- +goose Up
ALTER TABLE log_filters ALTER TABLE log_filters
DROP CONSTRAINT log_filters_from_block_check1; DROP CONSTRAINT log_filters_from_block_check1;
ALTER TABLE log_filters ALTER TABLE log_filters
ADD CONSTRAINT log_filters_to_block_check CHECK (to_block >= 0); ADD CONSTRAINT log_filters_to_block_check CHECK (to_block >= 0);
-- +goose Down -- +goose Down
ALTER TABLE log_filters ALTER TABLE log_filters
DROP CONSTRAINT log_filters_to_block_check; DROP CONSTRAINT log_filters_to_block_check;
ALTER TABLE log_filters ALTER TABLE log_filters
ADD CONSTRAINT log_filters_from_block_check1 CHECK (to_block >= 0); ADD CONSTRAINT log_filters_from_block_check1 CHECK (to_block >= 0);

View File

@ -1,52 +1,43 @@
-- +goose Up -- +goose Up
ALTER TABLE public.nodes ALTER TABLE public.nodes RENAME TO eth_nodes;
RENAME TO eth_nodes;
ALTER TABLE public.eth_nodes RENAME COLUMN node_id TO eth_node_id;
ALTER TABLE public.eth_nodes DROP CONSTRAINT node_uc;
ALTER TABLE public.eth_nodes ALTER TABLE public.eth_nodes
RENAME COLUMN node_id TO eth_node_id; ADD CONSTRAINT eth_node_uc UNIQUE (genesis_block, network_id, eth_node_id);
ALTER TABLE public.eth_nodes ALTER TABLE public.blocks RENAME COLUMN node_id TO eth_node_id;
DROP CONSTRAINT node_uc;
ALTER TABLE public.eth_nodes
ADD CONSTRAINT eth_node_uc UNIQUE (genesis_block, network_id, eth_node_id);
ALTER TABLE public.blocks DROP CONSTRAINT node_id_block_number_uc;
ALTER TABLE public.blocks ALTER TABLE public.blocks
RENAME COLUMN node_id TO eth_node_id; ADD CONSTRAINT eth_node_id_block_number_uc UNIQUE (number, eth_node_id);
ALTER TABLE public.blocks DROP CONSTRAINT node_fk;
ALTER TABLE public.blocks ALTER TABLE public.blocks
DROP CONSTRAINT node_id_block_number_uc; ADD CONSTRAINT node_fk
ALTER TABLE public.blocks FOREIGN KEY (eth_node_id) REFERENCES eth_nodes (id) ON DELETE CASCADE;
ADD CONSTRAINT eth_node_id_block_number_uc UNIQUE (number, eth_node_id);
ALTER TABLE public.blocks
DROP CONSTRAINT node_fk;
ALTER TABLE public.blocks
ADD CONSTRAINT node_fk
FOREIGN KEY (eth_node_id) REFERENCES eth_nodes (id) ON DELETE CASCADE;
-- +goose Down -- +goose Down
ALTER TABLE public.eth_nodes ALTER TABLE public.eth_nodes
RENAME TO nodes; RENAME TO nodes;
ALTER TABLE public.nodes ALTER TABLE public.nodes
RENAME COLUMN eth_node_id TO node_id; RENAME COLUMN eth_node_id TO node_id;
ALTER TABLE public.nodes ALTER TABLE public.nodes
DROP CONSTRAINT eth_node_uc; DROP CONSTRAINT eth_node_uc;
ALTER TABLE public.nodes ALTER TABLE public.nodes
ADD CONSTRAINT node_uc UNIQUE (genesis_block, network_id, node_id); ADD CONSTRAINT node_uc UNIQUE (genesis_block, network_id, node_id);
ALTER TABLE public.blocks ALTER TABLE public.blocks RENAME COLUMN eth_node_id TO node_id;
RENAME COLUMN eth_node_id TO node_id;
ALTER TABLE public.blocks DROP CONSTRAINT eth_node_id_block_number_uc;
ALTER TABLE public.blocks ALTER TABLE public.blocks
DROP CONSTRAINT eth_node_id_block_number_uc; ADD CONSTRAINT node_id_block_number_uc UNIQUE (number, node_id);
ALTER TABLE public.blocks
ADD CONSTRAINT node_id_block_number_uc UNIQUE (number, node_id);
ALTER TABLE public.blocks DROP CONSTRAINT node_fk;
ALTER TABLE public.blocks ALTER TABLE public.blocks
DROP CONSTRAINT node_fk; ADD CONSTRAINT node_fk
ALTER TABLE public.blocks FOREIGN KEY (node_id) REFERENCES nodes (id) ON DELETE CASCADE;
ADD CONSTRAINT node_fk
FOREIGN KEY (node_id) REFERENCES nodes (id) ON DELETE CASCADE;

View File

@ -1,44 +1,44 @@
-- +goose Up -- +goose Up
ALTER TABLE full_sync_receipts ALTER TABLE full_sync_receipts
ADD COLUMN block_id INT; ADD COLUMN block_id INT;
UPDATE full_sync_receipts UPDATE full_sync_receipts
SET block_id = ( SET block_id = (
SELECT block_id FROM full_sync_transactions WHERE full_sync_transactions.id = full_sync_receipts.transaction_id SELECT block_id FROM full_sync_transactions WHERE full_sync_transactions.id = full_sync_receipts.transaction_id
); );
ALTER TABLE full_sync_receipts ALTER TABLE full_sync_receipts
ALTER COLUMN block_id SET NOT NULL; ALTER COLUMN block_id SET NOT NULL;
ALTER TABLE full_sync_receipts ALTER TABLE full_sync_receipts
ADD CONSTRAINT blocks_fk ADD CONSTRAINT blocks_fk
FOREIGN KEY (block_id) FOREIGN KEY (block_id)
REFERENCES blocks (id) REFERENCES blocks (id)
ON DELETE CASCADE; ON DELETE CASCADE;
ALTER TABLE full_sync_receipts ALTER TABLE full_sync_receipts
DROP COLUMN transaction_id; DROP COLUMN transaction_id;
-- +goose Down -- +goose Down
ALTER TABLE full_sync_receipts ALTER TABLE full_sync_receipts
ADD COLUMN transaction_id INT; ADD COLUMN transaction_id INT;
CREATE INDEX transaction_id_index ON full_sync_receipts (transaction_id); CREATE INDEX transaction_id_index ON full_sync_receipts (transaction_id);
UPDATE full_sync_receipts UPDATE full_sync_receipts
SET transaction_id = ( SET transaction_id = (
SELECT id FROM full_sync_transactions WHERE full_sync_transactions.hash = full_sync_receipts.tx_hash SELECT id FROM full_sync_transactions WHERE full_sync_transactions.hash = full_sync_receipts.tx_hash
); );
ALTER TABLE full_sync_receipts ALTER TABLE full_sync_receipts
ALTER COLUMN transaction_id SET NOT NULL; ALTER COLUMN transaction_id SET NOT NULL;
ALTER TABLE full_sync_receipts ALTER TABLE full_sync_receipts
ADD CONSTRAINT transaction_fk ADD CONSTRAINT transaction_fk
FOREIGN KEY (transaction_id) FOREIGN KEY (transaction_id)
REFERENCES full_sync_transactions (id) REFERENCES full_sync_transactions (id)
ON DELETE CASCADE; ON DELETE CASCADE;
ALTER TABLE full_sync_receipts ALTER TABLE full_sync_receipts
DROP COLUMN block_id; DROP COLUMN block_id;

View File

@ -1,16 +1,16 @@
-- +goose Up -- +goose Up
ALTER TABLE blocks ALTER TABLE blocks
ADD COLUMN eth_node_fingerprint VARCHAR(128); ADD COLUMN eth_node_fingerprint VARCHAR(128);
UPDATE blocks UPDATE blocks
SET eth_node_fingerprint = ( SET eth_node_fingerprint = (
SELECT eth_node_id FROM eth_nodes WHERE eth_nodes.id = blocks.eth_node_id SELECT eth_node_id FROM eth_nodes WHERE eth_nodes.id = blocks.eth_node_id
); );
ALTER TABLE blocks ALTER TABLE blocks
ALTER COLUMN eth_node_fingerprint SET NOT NULL; ALTER COLUMN eth_node_fingerprint SET NOT NULL;
-- +goose Down -- +goose Down
ALTER TABLE blocks ALTER TABLE blocks
DROP COLUMN eth_node_fingerprint; DROP COLUMN eth_node_fingerprint;

View File

@ -1,13 +1,12 @@
-- +goose Up -- +goose Up
CREATE TABLE public.headers CREATE TABLE public.headers (
( id SERIAL PRIMARY KEY,
id SERIAL PRIMARY KEY, hash VARCHAR(66),
hash VARCHAR(66), block_number BIGINT,
block_number BIGINT, raw JSONB,
raw JSONB, block_timestamp NUMERIC,
block_timestamp NUMERIC, eth_node_id INTEGER NOT NULL REFERENCES eth_nodes (id) ON DELETE CASCADE,
eth_node_id INTEGER NOT NULL REFERENCES eth_nodes (id) ON DELETE CASCADE, eth_node_fingerprint VARCHAR(128)
eth_node_fingerprint VARCHAR(128)
); );
-- Index is removed when table is -- Index is removed when table is

View File

@ -1,13 +1,12 @@
-- +goose Up -- +goose Up
CREATE TABLE public.queued_storage CREATE TABLE public.queued_storage (
( id SERIAL PRIMARY KEY,
id SERIAL PRIMARY KEY, block_height BIGINT,
block_height BIGINT, block_hash BYTEA,
block_hash BYTEA, contract BYTEA,
contract BYTEA, storage_key BYTEA,
storage_key BYTEA, storage_value BYTEA,
storage_value BYTEA, UNIQUE (block_height, block_hash, contract, storage_key, storage_value)
UNIQUE (block_height, block_hash, contract, storage_key, storage_value)
); );
-- +goose Down -- +goose Down

View File

@ -1,19 +1,18 @@
-- +goose Up -- +goose Up
CREATE TABLE header_sync_transactions CREATE TABLE header_sync_transactions (
( id SERIAL PRIMARY KEY,
id SERIAL PRIMARY KEY, header_id INTEGER NOT NULL REFERENCES headers(id) ON DELETE CASCADE,
header_id INTEGER NOT NULL REFERENCES headers (id) ON DELETE CASCADE, hash VARCHAR(66),
hash VARCHAR(66), gas_limit NUMERIC,
gas_limit NUMERIC, gas_price NUMERIC,
gas_price NUMERIC, input_data BYTEA,
input_data BYTEA, nonce NUMERIC,
nonce NUMERIC, raw BYTEA,
raw BYTEA, tx_from VARCHAR(44),
tx_from VARCHAR(44), tx_index INTEGER,
tx_index INTEGER, tx_to VARCHAR(44),
tx_to VARCHAR(44), "value" NUMERIC,
"value" NUMERIC, UNIQUE (header_id, hash)
UNIQUE (header_id, hash)
); );
-- +goose Down -- +goose Down

View File

@ -1,16 +1,15 @@
-- +goose Up -- +goose Up
CREATE TABLE public.uncles CREATE TABLE public.uncles (
( id SERIAL PRIMARY KEY,
id SERIAL PRIMARY KEY, hash VARCHAR(66) NOT NULL,
hash VARCHAR(66) NOT NULL, block_id INTEGER NOT NULL REFERENCES blocks (id) ON DELETE CASCADE,
block_id INTEGER NOT NULL REFERENCES blocks (id) ON DELETE CASCADE, reward NUMERIC NOT NULL,
reward NUMERIC NOT NULL, miner VARCHAR(42) NOT NULL,
miner VARCHAR(42) NOT NULL, raw JSONB,
raw JSONB, block_timestamp NUMERIC,
block_timestamp NUMERIC, eth_node_id INTEGER NOT NULL REFERENCES eth_nodes (id) ON DELETE CASCADE,
eth_node_id INTEGER NOT NULL REFERENCES eth_nodes (id) ON DELETE CASCADE, eth_node_fingerprint VARCHAR(128),
eth_node_fingerprint VARCHAR(128), UNIQUE (block_id, hash)
UNIQUE (block_id, hash)
); );
-- +goose Down -- +goose Down