mirror of
https://github.com/plausible/analytics.git
synced 2024-12-24 01:54:34 +03:00
8f85b110aa
* Configure ingest repo access/pool size If I'm not mistaken 3 is a sane default, the only inserts we're doing are: - session buffer dump - events buffer dump - GA import dump And all are serializable within their scopes? * Add IngestRepo * Start IngestRepo * Use IngestRepo for inserts * Annotate ClickhouseRepo as read_only So no insert* functions are expanded * Update moduledoc * rename alias * Fix default env var value so it can be casted * Use IngestRepo for migrations * Set default ingest pool size from 3 to 5 in case conns are restarting or else... * Ensure all Repo prometheus metrics are collected
59 lines
1.9 KiB
Elixir
59 lines
1.9 KiB
Elixir
defmodule Plausible.ClickhouseRepo.Migrations.CreateEventsAndSessions do
|
|
use Ecto.Migration
|
|
|
|
def up do
|
|
create_events()
|
|
create_sessions()
|
|
end
|
|
|
|
defp create_events() do
|
|
create_if_not_exists table(:events,
|
|
engine:
|
|
"MergeTree() PARTITION BY toYYYYMM(timestamp) ORDER BY (domain, toDate(timestamp), user_id) SETTINGS index_granularity = 8192"
|
|
) do
|
|
add(:name, :string)
|
|
add(:domain, :string)
|
|
add(:user_id, :UInt64)
|
|
add(:session_id, :UInt64)
|
|
add(:hostname, :string)
|
|
add(:pathname, :string)
|
|
add(:referrer, :string)
|
|
add(:referrer_source, :string)
|
|
add(:country_code, :"LowCardinality(FixedString(2))")
|
|
add(:screen_size, :"LowCardinality(String)")
|
|
add(:operating_system, :"LowCardinality(String)")
|
|
add(:browser, :"LowCardinality(String)")
|
|
|
|
add(:timestamp, :naive_datetime)
|
|
end
|
|
end
|
|
|
|
defp create_sessions() do
|
|
create_if_not_exists table(:sessions,
|
|
engine:
|
|
"CollapsingMergeTree(sign) PARTITION BY toYYYYMM(start) ORDER BY (domain, toDate(start), user_id, session_id) SETTINGS index_granularity = 8192"
|
|
) do
|
|
add(:session_id, :UInt64)
|
|
add(:sign, :Int8)
|
|
add(:domain, :string)
|
|
add(:user_id, :UInt64)
|
|
add(:hostname, :string)
|
|
add(:is_bounce, :boolean)
|
|
add(:entry_page, :string)
|
|
add(:exit_page, :string)
|
|
add(:pageviews, :integer)
|
|
add(:events, :integer)
|
|
add(:duration, :UInt32)
|
|
add(:referrer, :string)
|
|
add(:referrer_source, :string)
|
|
add(:country_code, :"LowCardinality(FixedString(2))")
|
|
add(:screen_size, :"LowCardinality(String)")
|
|
add(:operating_system, :"LowCardinality(String)")
|
|
add(:browser, :"LowCardinality(String)")
|
|
|
|
add(:start, :naive_datetime)
|
|
add(:timestamp, :naive_datetime)
|
|
end
|
|
end
|
|
end
|