Skip to content

Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.

Migration: add imported custom events (#4076)

RobertJoonasc106595be0a2
diff --git a/priv/ingest_repo/migrations/20240423094014_add_imported_custom_events.exs b/priv/ingest_repo/migrations/20240423094014_add_imported_custom_events.exs
new file mode 100644
index 0000000000..3c535d3cae
--- /dev/null
+++ b/priv/ingest_repo/migrations/20240423094014_add_imported_custom_events.exs
@@ -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