analytics/priv/clickhouse_repo/migrations/20200915070607_create_events_and_sessions.exs
Uku Taht 4b36bb7138
Use clickhouse_ecto for db connection (#317)
* Use clickhouse-ecto for stats

* Use clickhouse ecto instead of low-level clickhousex

* Remove defaults from event schema

* Remove all references to Clickhousex

* Document configuration change

* Ensure createdb and migrations can be run in a release

* Remove config added for debug

* Update plausible_variables.sample.env
2020-09-17 16:36:01 +03:00

53 lines
1.7 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 (name, domain, user_id, timestamp) 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, user_id, session_id, start) 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