analytics/test/support/clickhouse_setup.ex
Uku Taht 5d1dc0d27c
Clickhouse DB (#62)
* WIP

* Get all stats from Clickhouse

* Use https dependency

* Do not namespace db tables in hydrate task

* Update hydration task

* Ingest data to clickhouse

* Double-write to both Clickhouse and Postgres

* Add test setup

* Keep old stats module

* Prepare for live ingestion test
2020-05-07 14:28:41 +03:00

58 lines
1.6 KiB
Elixir

defmodule Plausible.Test.ClickhouseSetup do
def run() do
create_events()
create_sessions()
end
def create_events() do
ddl = """
CREATE TABLE IF NOT EXISTS events (
timestamp DateTime,
name String,
domain String,
user_id FixedString(64),
hostname String,
pathname String,
referrer Nullable(String),
referrer_source Nullable(String),
initial_referrer Nullable(String),
initial_referrer_source Nullable(String),
country_code Nullable(FixedString(2)),
screen_size Nullable(String),
operating_system Nullable(String),
browser Nullable(String)
) ENGINE = MergeTree()
PARTITION BY toYYYYMM(timestamp)
ORDER BY (name, domain, timestamp, user_id)
SETTINGS index_granularity = 8192
"""
Clickhousex.query(:clickhouse, ddl, [],log: {Plausible.Clickhouse, :log, []})
end
def create_sessions() do
ddl = """
CREATE TABLE IF NOT EXISTS sessions (
domain String,
user_id FixedString(64),
hostname String,
start DateTime,
is_bounce UInt8,
entry_page Nullable(String),
exit_page Nullable(String),
referrer Nullable(String),
referrer_source Nullable(String),
country_code Nullable(FixedString(2)),
screen_size Nullable(String),
operating_system Nullable(String),
browser Nullable(String)
) ENGINE = MergeTree()
PARTITION BY toYYYYMM(start)
ORDER BY (domain, start, user_id)
SETTINGS index_granularity = 8192
"""
Clickhousex.query(:clickhouse, ddl, [],log: {Plausible.Clickhouse, :log, []})
end
end