diff --git a/create_schema.sh b/create_schema.sh index 569b725..b05e3c7 100755 --- a/create_schema.sh +++ b/create_schema.sh @@ -23,7 +23,7 @@ done ON_CLUSTER_DIRECTIVE="" ENGINE_TYPE="ReplacingMergeTree()" if [ -n "$CLUSTER_NAME" ]; then - ON_CLUSTER_DIRECTIVE="ON CLUSTER $CLUSTER_NAME" + ON_CLUSTER_DIRECTIVE="ON CLUSTER \"$CLUSTER_NAME\"" ENGINE_TYPE="ReplicatedReplacingMergeTree('/clickhouse/tables/{uuid}/{shard}', '{replica}')" fi diff --git a/schema.sql b/schema.sql index 0d68df4..7354ab1 100644 --- a/schema.sql +++ b/schema.sql @@ -353,6 +353,49 @@ SELECT contract, timestamp AS updated_at_timestamp FROM supply_change_events; +-- Table to store token transfers primarily indexed by the 'contract' field -- +CREATE TABLE IF NOT EXISTS transfers_contract ON CLUSTER "antelope" +( + trx_id String, + action_index UInt32, + + contract String, + symcode String, + + from String, + to String, + quantity String, + memo String, + + precision UInt32, + amount Int64, + value Float64, + + block_num UInt64, + timestamp DateTime +) + ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/{uuid}/{shard}', '{replica}') + PRIMARY KEY (contract, symcode, trx_id, action_index) + ORDER BY (contract, symcode, trx_id, action_index); + +CREATE MATERIALIZED VIEW transfers_contract_mv ON CLUSTER "antelope" + TO transfers_contract +AS +SELECT trx_id, + action_index, + contract, + symcode, + from, + to, + quantity, + memo, + precision, + amount, + value, + block_num, + timestamp +FROM transfer_events; + -- Table to store token transfers primarily indexed by the 'from' field -- CREATE TABLE IF NOT EXISTS transfers_from ON CLUSTER "antelope" (