Skip to content

Commit

Permalink
Fix engine when not using a cluster (#59)
Browse files Browse the repository at this point in the history
Thanks @Matlefebvre1234 for finding this out.
  • Loading branch information
0237h authored Aug 14, 2024
1 parent eec8aaf commit 965ca9d
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions create_schema.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ while [[ "$#" -gt 0 ]]; do
done

ON_CLUSTER_DIRECTIVE=""
ENGINE_TYPE="ReplacingMergeTree()"
if [ -n "$CLUSTER_NAME" ]; then
ON_CLUSTER_DIRECTIVE="ON CLUSTER $CLUSTER_NAME"
ENGINE_TYPE="ReplicatedReplacingMergeTree('/clickhouse/tables/{uuid}/{shard}', '{replica}')"
fi

cat > $SCHEMA_FILE <<- EOM
Expand All @@ -44,7 +46,7 @@ CREATE TABLE IF NOT EXISTS cursors $ON_CLUSTER_DIRECTIVE
block_num Int64,
block_id String
)
ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/{uuid}/{shard}', '{replica}')
ENGINE = $ENGINE_TYPE
PRIMARY KEY (id)
ORDER BY (id);
Expand Down Expand Up @@ -74,7 +76,7 @@ CREATE TABLE IF NOT EXISTS transfer_events $ON_CLUSTER_DIRECTIVE
block_num UInt64,
timestamp DateTime
)
ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/{uuid}/{shard}', '{replica}')
ENGINE = $ENGINE_TYPE
PRIMARY KEY (trx_id, action_index)
ORDER BY (trx_id, action_index);
Expand All @@ -99,7 +101,7 @@ CREATE TABLE IF NOT EXISTS balance_change_events $ON_CLUSTER_DIRECTIVE
block_num UInt64,
timestamp DateTime
)
ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/{uuid}/{shard}', '{replica}')
ENGINE = $ENGINE_TYPE
PRIMARY KEY (account, block_num, trx_id, action_index)
ORDER BY (account, block_num, trx_id, action_index);
Expand All @@ -125,7 +127,7 @@ CREATE TABLE IF NOT EXISTS supply_change_events $ON_CLUSTER_DIRECTIVE
block_num UInt64,
timestamp DateTime
)
ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/{uuid}/{shard}', '{replica}')
ENGINE = $ENGINE_TYPE
PRIMARY KEY (contract, block_num, trx_id, action_index)
ORDER BY (contract, block_num, trx_id, action_index);
Expand All @@ -150,7 +152,7 @@ CREATE TABLE IF NOT EXISTS issue_events $ON_CLUSTER_DIRECTIVE
block_num UInt64,
timestamp DateTime
)
ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/{uuid}/{shard}', '{replica}')
ENGINE = $ENGINE_TYPE
PRIMARY KEY (contract, symcode, to, amount, trx_id, action_index)
ORDER BY (contract, symcode, to, amount, trx_id, action_index);
Expand All @@ -174,7 +176,7 @@ CREATE TABLE IF NOT EXISTS retire_events $ON_CLUSTER_DIRECTIVE
block_num UInt64,
timestamp DateTime
)
ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/{uuid}/{shard}', '{replica}')
ENGINE = $ENGINE_TYPE
PRIMARY KEY (contract, symcode, amount, trx_id, action_index)
ORDER BY (contract, symcode, amount, trx_id, action_index);
Expand All @@ -197,7 +199,7 @@ CREATE TABLE IF NOT EXISTS create_events $ON_CLUSTER_DIRECTIVE
block_num UInt64,
timestamp DateTime
)
ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/{uuid}/{shard}', '{replica}')
ENGINE = $ENGINE_TYPE
PRIMARY KEY (contract, symcode, trx_id, action_index)
ORDER BY (contract, symcode, trx_id, action_index);
Expand Down Expand Up @@ -255,7 +257,7 @@ CREATE TABLE IF NOT EXISTS historical_account_balances $ON_CLUSTER_DIRECTIVE
block_num UInt64,
timestamp DateTime
)
ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/{uuid}/{shard}', '{replica}')
ENGINE = $ENGINE_TYPE
PRIMARY KEY (block_num, account, contract, symcode)
ORDER BY (block_num, account, contract, symcode, value);
Expand Down Expand Up @@ -362,7 +364,7 @@ CREATE TABLE IF NOT EXISTS historical_token_supplies $ON_CLUSTER_DIRECTIVE
block_num UInt64,
timestamp DateTime
)
ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/{uuid}/{shard}', '{replica}')
ENGINE = $ENGINE_TYPE
PRIMARY KEY (block_num, contract, symcode, issuer)
ORDER BY (block_num, contract, symcode, issuer);
Expand Down Expand Up @@ -402,7 +404,7 @@ CREATE TABLE IF NOT EXISTS transfers_from $ON_CLUSTER_DIRECTIVE
block_num UInt64,
timestamp DateTime
)
ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/{uuid}/{shard}', '{replica}')
ENGINE = $ENGINE_TYPE
PRIMARY KEY (from, to, contract, symcode, trx_id, action_index)
ORDER BY (from, to, contract, symcode, trx_id, action_index);
Expand Down Expand Up @@ -445,7 +447,7 @@ CREATE TABLE IF NOT EXISTS historical_transfers_from $ON_CLUSTER_DIRECTIVE
block_num UInt64,
timestamp DateTime
)
ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/{uuid}/{shard}', '{replica}')
ENGINE = $ENGINE_TYPE
PRIMARY KEY (block_num, from, to, contract, symcode, trx_id, action_index)
ORDER BY (block_num, from, to, contract, symcode, trx_id, action_index);
Expand Down Expand Up @@ -488,7 +490,7 @@ CREATE TABLE IF NOT EXISTS transfers_to $ON_CLUSTER_DIRECTIVE
block_num UInt64,
timestamp DateTime
)
ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/{uuid}/{shard}', '{replica}')
ENGINE = $ENGINE_TYPE
PRIMARY KEY (to, contract, symcode, trx_id, action_index)
ORDER BY (to, contract, symcode, trx_id, action_index);
Expand Down Expand Up @@ -531,7 +533,7 @@ CREATE TABLE IF NOT EXISTS historical_transfers_to $ON_CLUSTER_DIRECTIVE
block_num UInt64,
timestamp DateTime
)
ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/{uuid}/{shard}', '{replica}')
ENGINE = $ENGINE_TYPE
PRIMARY KEY (block_num, to, contract, symcode, trx_id, action_index)
ORDER BY (block_num, to, contract, symcode, trx_id, action_index);
Expand Down Expand Up @@ -574,7 +576,7 @@ CREATE TABLE IF NOT EXISTS transfers_block_num $ON_CLUSTER_DIRECTIVE
block_num UInt64,
timestamp DateTime
)
ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/{uuid}/{shard}', '{replica}')
ENGINE = $ENGINE_TYPE
PRIMARY KEY (block_num, contract, symcode, trx_id, action_index)
ORDER BY (block_num, contract, symcode, trx_id, action_index);
Expand All @@ -599,4 +601,4 @@ EOM

echo "[+] Created '$SCHEMA_FILE'"
echo "[*] Run the following command to apply:"
echo "cat $SCHEMA_FILE | clickhouse client -h <host> --port 9000 -d <database> -u <user> --password <password>"
echo "cat $SCHEMA_FILE | clickhouse client -h <host> --port 9000 -d <database> -u <user> --password <password>"

0 comments on commit 965ca9d

Please sign in to comment.