diff --git a/indexer/postgres/base_sql.go b/indexer/postgres/base_sql.go index 81e1ac704242..32eb38f364c0 100644 --- a/indexer/postgres/base_sql.go +++ b/indexer/postgres/base_sql.go @@ -5,4 +5,29 @@ const BaseSQL = ` CREATE OR REPLACE FUNCTION nanos_to_timestamptz(nanos bigint) RETURNS timestamptz AS $$ SELECT to_timestamp(nanos / 1000000000) + (nanos / 1000000000) * INTERVAL '1 microsecond' $$ LANGUAGE SQL IMMUTABLE; + +CREATE TABLE IF NOT EXISTS block +( + number BIGINT NOT NULL PRIMARY KEY, + header JSONB NULL +); + +CREATE TABLE IF NOT EXISTS tx +( + id BIGSERIAL PRIMARY KEY, + block_number BIGINT NOT NULL REFERENCES block (number), + index_in_block BIGINT NOT NULL, + data JSONB NOT NULL +); + +CREATE TABLE IF NOT EXISTS event +( + id BIGSERIAL PRIMARY KEY, + block_number BIGINT NOT NULL REFERENCES block (number), + tx_id BIGINT NULL REFERENCES tx (id), + msg_index BIGINT NULL, + event_index BIGINT NULL, + type TEXT NOT NULL, + data JSONB NOT NULL +); `