Migration: add imported custom events (#4076)

* Add `imported_custom_events` to CH

* remove redundant table setting

* add path column

---------

Co-authored-by: Adrian Gruntkowski <adrian.gruntkowski@gmail.com>
This commit is contained in:
RobertJoonas 2024-05-07 11:46:27 +01:00 committed by GitHub
parent 02d4709be7
commit c106595be0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -0,0 +1,41 @@
defmodule Plausible.IngestRepo.Migrations.AddImportedCustomEvents do
use Ecto.Migration
def change do
# NOTE: Using another table for determining cluster presence
on_cluster = Plausible.MigrationUtils.on_cluster_statement("imported_pages")
settings =
if Plausible.MigrationUtils.clustered_table?("imported_pages") do
"""
ENGINE = ReplicatedMergeTree('/clickhouse/{cluster}/tables/{shard}/{database}/imported_custom_events', '{replica}')
ORDER BY (site_id, import_id, date, name)
SETTINGS replicated_deduplication_window = 0, storage_policy = 'tiered'
"""
else
"""
ENGINE = MergeTree()
ORDER BY (site_id, import_id, date, name)
SETTINGS replicated_deduplication_window = 0
"""
end
execute """
CREATE TABLE IF NOT EXISTS imported_custom_events #{on_cluster}
(
`site_id` UInt64,
`import_id` UInt64,
`date` Date,
`name` String CODEC(ZSTD(3)),
`link_url` String CODEC(ZSTD(3)),
`path` String CODEC(ZSTD(3)),
`visitors` UInt64,
`events` UInt64
)
#{settings}
""",
"""
DROP TABLE IF EXISTS imported_custom_events #{on_cluster} SYNC
"""
end
end