-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 8a1f6b3
Showing
24 changed files
with
1,628 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
name: Docker Compose Build | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
build: | ||
name: Run docker build | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Get the version | ||
id: vars | ||
run: echo ::set-output name=sha::$(echo ${GITHUB_SHA:0:7}) | ||
- name: Run docker build | ||
run: make docker-build | ||
- name: Tag docker image | ||
run: docker tag vulcanize/statediff-migrations docker.pkg.github.com/vulcanize/statediff-migrations/statediff-migrations:${{steps.vars.outputs.sha}} | ||
- name: Docker Login | ||
run: echo ${{ secrets.GITHUB_TOKEN }} | docker login https://docker.pkg.github.com -u vulcanize --password-stdin | ||
- name: Docker Push | ||
run: docker push docker.pkg.github.com/vulcanize/statediff-migrations/statediff-migrations:${{steps.vars.outputs.sha}} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
name: Docker Build | ||
|
||
on: [pull_request] | ||
|
||
jobs: | ||
build: | ||
name: Run docker build | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Run docker build | ||
run: make docker-build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
name: Publish Docker image | ||
on: | ||
release: | ||
types: [published] | ||
jobs: | ||
push_to_registries: | ||
name: Push Docker image to Docker Hub | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Get the version | ||
id: vars | ||
run: | | ||
echo ::set-output name=sha::$(echo ${GITHUB_SHA:0:7}) | ||
echo ::set-output name=tag::$(echo ${GITHUB_REF#refs/tags/}) | ||
- name: Docker Login to Github Registry | ||
run: echo ${{ secrets.GITHUB_TOKEN }} | docker login https://docker.pkg.github.com -u vulcanize --password-stdin | ||
- name: Docker Pull | ||
run: docker pull docker.pkg.github.com/vulcanize/statediff-migrations/statediff-migrations:${{steps.vars.outputs.sha}} | ||
- name: Docker Login to Docker Registry | ||
run: echo ${{ secrets.VULCANIZEJENKINS_PAT }} | docker login -u vulcanizejenkins --password-stdin | ||
- name: Tag docker image | ||
run: docker tag docker.pkg.github.com/vulcanize/statediff-migrations/statediff-migrations:${{steps.vars.outputs.sha}} vulcanize/statediff-migrations:${{steps.vars.outputs.tag}} | ||
- name: Docker Push to Docker Hub | ||
run: docker push vulcanize/statediff-migrations:${{steps.vars.outputs.tag}} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
FROM golang:1.13-alpine as builder | ||
|
||
RUN apk --update --no-cache add make git g++ linux-headers | ||
# DEBUG | ||
RUN apk add busybox-extras | ||
|
||
ADD . /go/src/github.com/vulcanize/statediff-migrations | ||
|
||
# Build migration tool | ||
WORKDIR / | ||
RUN go get -u -d github.com/pressly/goose/cmd/goose | ||
WORKDIR /go/src/github.com/pressly/goose/cmd/goose | ||
RUN GCO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags '-extldflags "-static"' -tags='no_mysql no_sqlite' -o goose . | ||
|
||
# app container | ||
FROM alpine | ||
|
||
WORKDIR /app | ||
|
||
COPY --from=builder /go/src/github.com/vulcanize/statediff-migrations/startup_script.sh . | ||
|
||
COPY --from=builder /go/src/github.com/pressly/goose/cmd/goose/goose goose | ||
COPY --from=builder /go/src/github.com/vulcanize/statediff-migrations/db/migrations migrations/vulcanizedb | ||
|
||
|
||
ENTRYPOINT ["/app/startup_script.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
## Build docker image | ||
.PHONY: docker-build | ||
docker-build: | ||
docker build -t vulcanize/statediff-migrations -f Dockerfile . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
-- +goose Up | ||
CREATE TABLE IF NOT EXISTS public.blocks ( | ||
key TEXT UNIQUE NOT NULL, | ||
data BYTEA NOT NULL | ||
); | ||
|
||
-- +goose Down | ||
DROP TABLE public.blocks; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
-- +goose Up | ||
CREATE TABLE nodes ( | ||
id SERIAL PRIMARY KEY, | ||
client_name VARCHAR, | ||
genesis_block VARCHAR(66), | ||
network_id VARCHAR, | ||
node_id VARCHAR(128), | ||
CONSTRAINT node_uc UNIQUE (genesis_block, network_id, node_id) | ||
); | ||
|
||
-- +goose Down | ||
DROP TABLE nodes; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
-- +goose Up | ||
CREATE SCHEMA eth; | ||
|
||
-- +goose Down | ||
DROP SCHEMA eth; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
-- +goose Up | ||
CREATE TABLE eth.header_cids ( | ||
id SERIAL PRIMARY KEY, | ||
block_number BIGINT NOT NULL, | ||
block_hash VARCHAR(66) NOT NULL, | ||
parent_hash VARCHAR(66) NOT NULL, | ||
cid TEXT NOT NULL, | ||
mh_key TEXT NOT NULL REFERENCES public.blocks (key) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, | ||
td NUMERIC NOT NULL, | ||
node_id INTEGER NOT NULL REFERENCES nodes (id) ON DELETE CASCADE, | ||
reward NUMERIC NOT NULL, | ||
state_root VARCHAR(66) NOT NULL, | ||
tx_root VARCHAR(66) NOT NULL, | ||
receipt_root VARCHAR(66) NOT NULL, | ||
uncle_root VARCHAR(66) NOT NULL, | ||
bloom BYTEA NOT NULL, | ||
timestamp NUMERIC NOT NULL, | ||
times_validated INTEGER NOT NULL DEFAULT 1, | ||
UNIQUE (block_number, block_hash) | ||
); | ||
|
||
-- +goose Down | ||
DROP TABLE eth.header_cids; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
-- +goose Up | ||
CREATE TABLE eth.uncle_cids ( | ||
id SERIAL PRIMARY KEY, | ||
header_id INTEGER NOT NULL REFERENCES eth.header_cids (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, | ||
block_hash VARCHAR(66) NOT NULL, | ||
parent_hash VARCHAR(66) NOT NULL, | ||
cid TEXT NOT NULL, | ||
mh_key TEXT NOT NULL REFERENCES public.blocks (key) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, | ||
reward NUMERIC NOT NULL, | ||
UNIQUE (header_id, block_hash) | ||
); | ||
|
||
-- +goose Down | ||
DROP TABLE eth.uncle_cids; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
-- +goose Up | ||
CREATE TABLE eth.transaction_cids ( | ||
id SERIAL PRIMARY KEY, | ||
header_id INTEGER NOT NULL REFERENCES eth.header_cids (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, | ||
tx_hash VARCHAR(66) NOT NULL, | ||
index INTEGER NOT NULL, | ||
cid TEXT NOT NULL, | ||
mh_key TEXT NOT NULL REFERENCES public.blocks (key) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, | ||
dst VARCHAR(66) NOT NULL, | ||
src VARCHAR(66) NOT NULL, | ||
deployment BOOL NOT NULL, | ||
tx_data BYTEA, | ||
UNIQUE (header_id, tx_hash) | ||
); | ||
|
||
-- +goose Down | ||
DROP TABLE eth.transaction_cids; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
-- +goose Up | ||
CREATE TABLE eth.receipt_cids ( | ||
id SERIAL PRIMARY KEY, | ||
tx_id INTEGER NOT NULL REFERENCES eth.transaction_cids (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, | ||
cid TEXT NOT NULL, | ||
mh_key TEXT NOT NULL REFERENCES public.blocks (key) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, | ||
contract VARCHAR(66), | ||
contract_hash VARCHAR(66), | ||
topic0s VARCHAR(66)[], | ||
topic1s VARCHAR(66)[], | ||
topic2s VARCHAR(66)[], | ||
topic3s VARCHAR(66)[], | ||
log_contracts VARCHAR(66)[], | ||
UNIQUE (tx_id) | ||
); | ||
|
||
-- +goose Down | ||
DROP TABLE eth.receipt_cids; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
-- +goose Up | ||
CREATE TABLE eth.state_cids ( | ||
id SERIAL PRIMARY KEY, | ||
header_id INTEGER NOT NULL REFERENCES eth.header_cids (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, | ||
state_leaf_key VARCHAR(66), | ||
cid TEXT NOT NULL, | ||
mh_key TEXT NOT NULL REFERENCES public.blocks (key) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, | ||
state_path BYTEA, | ||
node_type INTEGER NOT NULL, | ||
diff BOOLEAN NOT NULL DEFAULT FALSE, | ||
UNIQUE (header_id, state_path) | ||
); | ||
|
||
-- +goose Down | ||
DROP TABLE eth.state_cids; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
-- +goose Up | ||
CREATE TABLE eth.storage_cids ( | ||
id SERIAL PRIMARY KEY, | ||
state_id INTEGER NOT NULL REFERENCES eth.state_cids (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, | ||
storage_leaf_key VARCHAR(66), | ||
cid TEXT NOT NULL, | ||
mh_key TEXT NOT NULL REFERENCES public.blocks (key) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, | ||
storage_path BYTEA, | ||
node_type INTEGER NOT NULL, | ||
diff BOOLEAN NOT NULL DEFAULT FALSE, | ||
UNIQUE (state_id, storage_path) | ||
); | ||
|
||
-- +goose Down | ||
DROP TABLE eth.storage_cids; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
-- +goose Up | ||
CREATE TABLE eth.state_accounts ( | ||
id SERIAL PRIMARY KEY, | ||
state_id INTEGER NOT NULL REFERENCES eth.state_cids (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, | ||
balance NUMERIC NOT NULL, | ||
nonce INTEGER NOT NULL, | ||
code_hash BYTEA NOT NULL, | ||
storage_root VARCHAR(66) NOT NULL, | ||
UNIQUE (state_id) | ||
); | ||
|
||
-- +goose Down | ||
DROP TABLE eth.state_accounts; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
-- +goose Up | ||
COMMENT ON TABLE public.nodes IS E'@name NodeInfo'; | ||
COMMENT ON TABLE eth.transaction_cids IS E'@name EthTransactionCids'; | ||
COMMENT ON TABLE eth.header_cids IS E'@name EthHeaderCids'; | ||
COMMENT ON COLUMN public.nodes.node_id IS E'@name ChainNodeID'; | ||
COMMENT ON COLUMN eth.header_cids.node_id IS E'@name EthNodeID'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
-- +goose Up | ||
ALTER TABLE public.nodes | ||
ADD COLUMN chain_id INTEGER DEFAULT 1; | ||
|
||
ALTER TABLE public.nodes | ||
DROP CONSTRAINT node_uc; | ||
|
||
ALTER TABLE public.nodes | ||
ADD CONSTRAINT node_uc | ||
UNIQUE (genesis_block, network_id, node_id, chain_id); | ||
|
||
-- +goose Down | ||
ALTER TABLE public.nodes | ||
DROP CONSTRAINT node_uc; | ||
|
||
ALTER TABLE public.nodes | ||
ADD CONSTRAINT node_uc | ||
UNIQUE (genesis_block, network_id, node_id); | ||
|
||
ALTER TABLE public.nodes | ||
DROP COLUMN chain_id; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
-- +goose Up | ||
-- +goose StatementBegin | ||
CREATE FUNCTION eth.graphql_subscription() returns TRIGGER as $$ | ||
declare | ||
table_name text = TG_ARGV[0]; | ||
attribute text = TG_ARGV[1]; | ||
id text; | ||
begin | ||
execute 'select $1.' || quote_ident(attribute) | ||
using new | ||
into id; | ||
perform pg_notify('postgraphile:' || table_name, | ||
json_build_object( | ||
'__node__', json_build_array( | ||
table_name, | ||
id | ||
) | ||
)::text | ||
); | ||
return new; | ||
end; | ||
$$ language plpgsql; | ||
-- +goose StatementEnd | ||
|
||
CREATE TRIGGER header_cids_ai | ||
after INSERT ON eth.header_cids | ||
for each row | ||
execute procedure eth.graphql_subscription('header_cids', 'id'); | ||
|
||
CREATE TRIGGER receipt_cids_ai | ||
after INSERT ON eth.receipt_cids | ||
for each row | ||
execute procedure eth.graphql_subscription('receipt_cids', 'id'); | ||
|
||
CREATE TRIGGER state_accounts_ai | ||
after INSERT ON eth.state_accounts | ||
for each row | ||
execute procedure eth.graphql_subscription('state_accounts', 'id'); | ||
|
||
CREATE TRIGGER state_cids_ai | ||
after INSERT ON eth.state_cids | ||
for each row | ||
execute procedure eth.graphql_subscription('state_cids', 'id'); | ||
|
||
CREATE TRIGGER storage_cids_ai | ||
after INSERT ON eth.storage_cids | ||
for each row | ||
execute procedure eth.graphql_subscription('storage_cids', 'id'); | ||
|
||
CREATE TRIGGER transaction_cids_ai | ||
after INSERT ON eth.transaction_cids | ||
for each row | ||
execute procedure eth.graphql_subscription('transaction_cids', 'id'); | ||
|
||
CREATE TRIGGER uncle_cids_ai | ||
after INSERT ON eth.uncle_cids | ||
for each row | ||
execute procedure eth.graphql_subscription('uncle_cids', 'id'); | ||
|
||
-- +goose Down | ||
DROP TRIGGER uncle_cids_ai ON eth.uncle_cids; | ||
DROP TRIGGER transaction_cids_ai ON eth.transaction_cids; | ||
DROP TRIGGER storage_cids_ai ON eth.storage_cids; | ||
DROP TRIGGER state_cids_ai ON eth.state_cids; | ||
DROP TRIGGER state_accounts_ai ON eth.state_accounts; | ||
DROP TRIGGER receipt_cids_ai ON eth.receipt_cids; | ||
DROP TRIGGER header_cids_ai ON eth.header_cids; | ||
|
||
DROP FUNCTION eth.graphql_subscription(); |
Oops, something went wrong.