PNixx / clickhouse-activerecord

A Ruby database ActiveRecord driver for ClickHouse

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Querying other databases

dipth opened this issue · comments

For legacy reasons we have 15 different Clickhouse databases living on the same physical Clickhouse server.
Each of these databases represents data for a single country.
In our Rails application we have country-switching implemented using:
https://github.com/rails-on-services/apartment

The idea is that we have identical Clickhouse tables in each of the 15 databases but with localized data for each country.

We would like to avoid having separate connection configurations for each country in our database.yml and having separate duplicate versions of the model-classes.

It should be possible to query data from another database than the one that you're connected to, but it seems that the current database name is always prefixed on all table-names in the SELECT queries that are executed in Clickhouse.

What would the best approach for us be, to support switching between databases using a single configuration and connection pool?

You can try https://github.com/kenn/standby gem. The ClickHouse adapter does not create a persistent connection, so the pool does not matter.