feat(clickhouse): Init Clickhouse container on startup (#4365)

Co-authored-by: Vrishab Srivatsa <136090360+vsrivatsa-juspay@users.noreply.github.com>
This commit is contained in:
Sampras Lopes
2024-05-06 16:34:04 +05:30
committed by GitHub
parent b878677f15
commit 89e5884f9e
10 changed files with 540 additions and 277 deletions

View File

@ -1,34 +1,5 @@
CREATE TABLE payment_intents_queue (
`payment_id` String,
`merchant_id` String,
`status` LowCardinality(String),
`amount` UInt32,
`currency` LowCardinality(Nullable(String)),
`amount_captured` Nullable(UInt32),
`customer_id` Nullable(String),
`description` Nullable(String),
`return_url` Nullable(String),
`connector_id` LowCardinality(Nullable(String)),
`statement_descriptor_name` Nullable(String),
`statement_descriptor_suffix` Nullable(String),
`setup_future_usage` LowCardinality(Nullable(String)),
`off_session` Nullable(Bool),
`client_secret` Nullable(String),
`active_attempt_id` String,
`business_country` String,
`business_label` String,
`modified_at` DateTime CODEC(T64, LZ4),
`created_at` DateTime CODEC(T64, LZ4),
`last_synced` Nullable(DateTime) CODEC(T64, LZ4),
`sign_flag` Int8
) ENGINE = Kafka SETTINGS kafka_broker_list = 'kafka0:29092',
kafka_topic_list = 'hyperswitch-payment-intent-events',
kafka_group_name = 'hyper-c1',
kafka_format = 'JSONEachRow',
kafka_handle_error_mode = 'stream';
CREATE TABLE payment_intents_dist (
CREATE TABLE payment_intents_queue
(
`payment_id` String,
`merchant_id` String,
`status` LowCardinality(String),
@ -47,6 +18,38 @@ CREATE TABLE payment_intents_dist (
`active_attempt_id` String,
`business_country` LowCardinality(String),
`business_label` String,
`attempt_count` UInt8,
`modified_at` DateTime CODEC(T64, LZ4),
`created_at` DateTime CODEC(T64, LZ4),
`last_synced` Nullable(DateTime) CODEC(T64, LZ4),
`sign_flag` Int8
) ENGINE = Kafka SETTINGS kafka_broker_list = 'kafka0:29092',
kafka_topic_list = 'hyperswitch-payment-intent-events',
kafka_group_name = 'hyper',
kafka_format = 'JSONEachRow',
kafka_handle_error_mode = 'stream';
CREATE TABLE payment_intents
(
`payment_id` String,
`merchant_id` LowCardinality(String),
`status` LowCardinality(String),
`amount` UInt32,
`currency` LowCardinality(Nullable(String)),
`amount_captured` Nullable(UInt32),
`customer_id` Nullable(String),
`description` Nullable(String),
`return_url` Nullable(String),
`connector_id` LowCardinality(Nullable(String)),
`statement_descriptor_name` Nullable(String),
`statement_descriptor_suffix` Nullable(String),
`setup_future_usage` LowCardinality(Nullable(String)),
`off_session` Nullable(Bool),
`client_secret` Nullable(String),
`active_attempt_id` String,
`business_country` LowCardinality(String),
`business_label` String,
`attempt_count` UInt8,
`modified_at` DateTime DEFAULT now() CODEC(T64, LZ4),
`created_at` DateTime DEFAULT now() CODEC(T64, LZ4),
`last_synced` Nullable(DateTime) CODEC(T64, LZ4),
@ -55,16 +58,15 @@ CREATE TABLE payment_intents_dist (
INDEX connectorIndex connector_id TYPE bloom_filter GRANULARITY 1,
INDEX currencyIndex currency TYPE bloom_filter GRANULARITY 1,
INDEX statusIndex status TYPE bloom_filter GRANULARITY 1
) ENGINE = CollapsingMergeTree(
sign_flag
)
ENGINE = CollapsingMergeTree(sign_flag)
PARTITION BY toStartOfDay(created_at)
ORDER BY
(created_at, merchant_id, payment_id)
TTL created_at + toIntervalMonth(6)
;
ORDER BY (created_at, merchant_id, payment_id)
TTL created_at + toIntervalMonth(18)
SETTINGS index_granularity = 8192;
CREATE MATERIALIZED VIEW kafka_parse_payment_intent TO payment_intents_dist (
CREATE MATERIALIZED VIEW payment_intents_mv TO payment_intents
(
`payment_id` String,
`merchant_id` String,
`status` LowCardinality(String),
@ -83,6 +85,7 @@ CREATE MATERIALIZED VIEW kafka_parse_payment_intent TO payment_intents_dist (
`active_attempt_id` String,
`business_country` LowCardinality(String),
`business_label` String,
`attempt_count` UInt8,
`modified_at` DateTime64(3),
`created_at` DateTime64(3),
`last_synced` Nullable(DateTime64(3)),
@ -108,9 +111,10 @@ SELECT
active_attempt_id,
business_country,
business_label,
attempt_count,
modified_at,
created_at,
last_synced,
now() as inserted_at,
now() AS inserted_at,
sign_flag
FROM payment_intents_queue;
FROM payment_intents_queue;