Skip to content

Commit

Permalink
fix: 🐛 cluster name for not found
Browse files Browse the repository at this point in the history
returns false
  • Loading branch information
karlosmid committed Jan 8, 2025
1 parent d24fdab commit 7f44487
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
16 changes: 10 additions & 6 deletions lib/plausible/migration_utils.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@ defmodule Plausible.MigrationUtils do
end

def cluster_name do
case Plausible.IngestRepo.query(
"SELECT cluster FROM system.clusters where cluster = '#{Plausible.IngestRepo.config()[:database]}' limit 1;"
) do
{:ok, %{rows: [[cluster]]}} -> cluster
{:ok, _} -> raise "No cluster defined."
{:error, _} -> raise "Cluster not found"
try do
case Plausible.IngestRepo.query(
"SELECT cluster FROM system.clusters where cluster = '#{Plausible.IngestRepo.config()[:database]}' limit 1;"
) do
{:ok, %{rows: [[cluster]]}} -> cluster
{:ok, _} -> false
{:error, _} -> false
end
rescue
_ -> false
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Plausible.IngestRepo.Migrations.AddImportedCustomEvents do
def change do
# NOTE: Using another table for determining cluster presence
on_cluster = Plausible.MigrationUtils.on_cluster_statement("imported_pages")
cluster? = Plausible.MigrationUtils.clustered_table?("imported_pages")
cluster? = Plausible.MigrationUtils.cluster_name()

cluster_name =
if cluster? do
Expand All @@ -14,7 +14,7 @@ defmodule Plausible.IngestRepo.Migrations.AddImportedCustomEvents do
end

settings =
if Plausible.MigrationUtils.clustered_table?("imported_pages") do
if Plausible.MigrationUtils.cluster_name() do
"""
ENGINE = ReplicatedMergeTree('/clickhouse/#{cluster_name}/tables/{shard}/{database}/imported_custom_events', '{replica}')
ORDER BY (site_id, import_id, date, name)
Expand Down

0 comments on commit 7f44487

Please sign in to comment.