Open
Conversation
UmbrellioUtils::ClickHouse becomes a polymorphic facade with two adapters: Backends::Legacy (existing `click_house` HTTP gem) and Backends::Native (new `clickhouse-native` TCP gem). Consumers pick the backend via `UmbrellioUtils.config.clickhouse_backend` — default stays `:legacy` so existing users are unaffected. Shared logic (from, count, DDL helpers, parse_value, temp-table plumbing) lives on Backends::Base; each adapter provides the low-level ops (execute/query/insert/describe_table/tables/server_version/ admin_execute) and a SERVER_ERROR class. DDL that creates/drops the configured database routes through admin_execute so the native adapter can open a one-shot client against the always-present `default` db (the native TCP protocol needs a reachable db, unlike HTTP). Native consumers also get a `::ClickHouse.config` shim (loaded eagerly from `configure` when `:native` is set) so external code that reads `::ClickHouse.config` directly — e.g. umbrellio-sequel-plugins' ch:create rake task — keeps working without the old click_house gem. ch:connect rake task is now backend-agnostic via UmbrellioUtils::ClickHouse.config. Version bump 1.12.1 → 1.13.0. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Allows consumers to inject a custom logger (e.g. a SemanticLogger named channel) into the native ClickHouse pool, instead of the default Rails.logger fallback. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Promotes the test-env-aware ON CLUSTER suppression that consumers (profile-service, unetsafe) were duplicating in their local CH modules. Adds: - UmbrellioUtils.config.clickhouse_cluster (default "click_cluster", set to nil/blank to skip the clause everywhere). - Backends::Base#on_cluster(sync:) — returns the ON CLUSTER clause, or "" when the cluster name is blank or `Rails.env.test?`. The cluster *name* is still used by callers like Distributed engine declarations regardless of this clause (each ON CLUSTER op blocks for hundreds of ms on a single-node CH waiting for replicas that don't exist). - truncate_table! / drop_table! / optimize_table! and Migrations#create_distributed_table! now use the helper instead of hardcoding `ON CLUSTER click_cluster`. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
UmbrellioUtils::ClickHousebecomes a polymorphic facade picking between two backends based onUmbrellioUtils.config.clickhouse_backend::legacy(default) — routes through theclick_houseHTTP gem, same behavior as before.:native— routes through theclickhouse-nativeTCP gem.Default stays
:legacy, so existing consumers keep working unchanged.Design
Backends::Baseowns shared logic (from,count,db_name, DDL helpers,parse_value,pg_table_connection,populate_temp_table!,with_temp_table,sql_for,ch_dataset?,log_errors). Each concrete adapter implements the low-level ops (execute/query/query_value/query_each/insert/describe_table/tables/server_version/admin_execute/config/logger) plus aSERVER_ERRORclass for error logging.Backends::Legacypreserves the historical HTTP-driver behavior (memoizedClickHouse::Connection, per-host DNS resolution,Misc::StrictHash-wrapped JSON responses).Backends::NativewrapsClickhouseNative::Pool, built from::ClickHouse.config.create_database/drop_databaseroute throughadmin_execute, a one-shot client against the always-presentdefaultdb — unlike HTTP, the native TCP protocol needs a reachable database to issue DDL, so this unblocksrake ch:createon fresh environments.UmbrellioUtils.config.clickhouse_native_settingslets native consumers set pool-wide session settings (e.g.allow_experimental_analyzer).::ClickHouse.configshimNative consumers without the old
click_housegem don't get::ClickHouse.configfor free. A small shim atlib/umbrellio_utils/click_house/config.rbprovides it (reading fromRails.application.config_for(:clickhouse)), gated byunless defined?(ClickHouse::Connection)so the legacy gem always wins when both are loaded. The shim is loaded eagerly fromUmbrellioUtils.configurewhenclickhouse_backend == :native, so other gems that access::ClickHouse.configdirectly (e.g.umbrellio-sequel-plugins'ch:createtask) keep working.Rake task
ch:connectnow readsUmbrellioUtils::ClickHouse.config(which resolves via the active backend), so the task is backend-agnostic. Projects that locally overrodech:connectto work around the old gem-binding can drop their override.Ruby compatibility
clickhouse-nativerequires Ruby >= 3.3. Added it as a dev dep gated byinstall_ifso CI still bundles on 3.1/3.2 (we skip the native backend spec context when the gem isn't installed).Version
1.12.1 → 1.13.0 (new feature, backward compatible).
Test plan
spec/umbrellio_utils/click_house/backend_dispatch_spec.rbcovers legacy+native dispatch and unknown-backend errors.:native,rake ch:create/ch:migrate/ch:connectall work).🤖 Generated with Claude Code