2020-09-17 16:36:01 +03:00
|
|
|
defmodule Plausible.ClickhouseRepo.Migrations.CreateEventsAndSessions do
|
|
|
|
use Ecto.Migration
|
|
|
|
|
|
|
|
def up do
|
|
|
|
create_events()
|
|
|
|
create_sessions()
|
|
|
|
end
|
|
|
|
|
|
|
|
defp create_events() do
|
2021-11-22 17:06:21 +03:00
|
|
|
create_if_not_exists table(:events,
|
2023-03-21 11:55:59 +03:00
|
|
|
primary_key: false,
|
|
|
|
engine: "MergeTree",
|
|
|
|
options:
|
|
|
|
"PARTITION BY toYYYYMM(timestamp) ORDER BY (domain, toDate(timestamp), user_id) SETTINGS index_granularity = 8192"
|
2021-11-22 17:06:21 +03:00
|
|
|
) 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)")
|
2020-09-17 16:36:01 +03:00
|
|
|
|
2021-11-22 17:06:21 +03:00
|
|
|
add(:timestamp, :naive_datetime)
|
2020-09-17 16:36:01 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
defp create_sessions() do
|
2021-11-22 17:06:21 +03:00
|
|
|
create_if_not_exists table(:sessions,
|
2023-03-21 11:55:59 +03:00
|
|
|
primary_key: false,
|
|
|
|
engine: "CollapsingMergeTree(sign)",
|
|
|
|
options:
|
|
|
|
"PARTITION BY toYYYYMM(start) ORDER BY (domain, toDate(start), user_id, session_id) SETTINGS index_granularity = 8192"
|
2021-11-22 17:06:21 +03:00
|
|
|
) do
|
|
|
|
add(:session_id, :UInt64)
|
|
|
|
add(:sign, :Int8)
|
|
|
|
add(:domain, :string)
|
|
|
|
add(:user_id, :UInt64)
|
|
|
|
add(:hostname, :string)
|
2023-03-21 11:55:59 +03:00
|
|
|
add(:is_bounce, :UInt8)
|
2021-11-22 17:06:21 +03:00
|
|
|
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)")
|
2020-09-17 16:36:01 +03:00
|
|
|
|
2021-11-22 17:06:21 +03:00
|
|
|
add(:start, :naive_datetime)
|
|
|
|
add(:timestamp, :naive_datetime)
|
2020-09-17 16:36:01 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|