From 9b6f61e3d0236f7d6f33a9da50d6c007f007e064 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Mon, 29 Jul 2024 11:54:10 +0200 Subject: [PATCH] feat(indexer/postgres): block, tx and event schemas (#21078) --- indexer/postgres/base_sql.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) 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 +); `