PHPackages                             rasuvaeff/yii3-clickhouse-toolkit - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. rasuvaeff/yii3-clickhouse-toolkit

ActiveLibrary[Database &amp; ORM](/categories/database)

rasuvaeff/yii3-clickhouse-toolkit
=================================

Yii3 config bridge for rasuvaeff/clickhouse-toolkit: DI wiring and console commands from environment.

v1.1.0(1mo ago)05BSD-3-ClausePHPPHP 8.3 - 8.5CI passing

Since Jul 8Pushed 1mo agoCompare

[ Source](https://github.com/rasuvaeff/yii3-clickhouse-toolkit)[ Packagist](https://packagist.org/packages/rasuvaeff/yii3-clickhouse-toolkit)[ Docs](https://github.com/rasuvaeff/yii3-clickhouse-toolkit)[ RSS](/packages/rasuvaeff-yii3-clickhouse-toolkit/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (32)Versions (3)Used By (0)

rasuvaeff/yii3-clickhouse-toolkit
=================================

[](#rasuvaeffyii3-clickhouse-toolkit)

[![Stable Version](https://camo.githubusercontent.com/0344dc7bd8933c9ad9aca173899f790011070734b174d40b080598593d52c784/68747470733a2f2f706f7365722e707567782e6f72672f7261737576616566662f796969332d636c69636b686f7573652d746f6f6c6b69742f762f737461626c65)](https://packagist.org/packages/rasuvaeff/yii3-clickhouse-toolkit)[![Total Downloads](https://camo.githubusercontent.com/996febf5143dc1efa64ae09cc2b2192001f6055a7efe81f6427edaef597e0361/68747470733a2f2f706f7365722e707567782e6f72672f7261737576616566662f796969332d636c69636b686f7573652d746f6f6c6b69742f646f776e6c6f616473)](https://packagist.org/packages/rasuvaeff/yii3-clickhouse-toolkit)[![Build](https://github.com/rasuvaeff/yii3-clickhouse-toolkit/actions/workflows/build.yml/badge.svg)](https://github.com/rasuvaeff/yii3-clickhouse-toolkit/actions)[![Static analysis](https://github.com/rasuvaeff/yii3-clickhouse-toolkit/actions/workflows/static-analysis.yml/badge.svg)](https://github.com/rasuvaeff/yii3-clickhouse-toolkit/actions)[![Psalm Level](https://camo.githubusercontent.com/faf0277ea62a4958c4499d78efc9a474531008e555a69e8d3dccb792fe69304a/68747470733a2f2f73686570686572642e6465762f6769746875622f7261737576616566662f796969332d636c69636b686f7573652d746f6f6c6b69742f6c6576656c2e737667)](https://shepherd.dev/github/rasuvaeff/yii3-clickhouse-toolkit)[![License](https://camo.githubusercontent.com/e34349dd72c1b2293b7c594f0c44d917e11a1e31e2ef5665e09e98345cd3e3f7/68747470733a2f2f706f7365722e707567782e6f72672f7261737576616566662f796969332d636c69636b686f7573652d746f6f6c6b69742f6c6963656e7365)](https://packagist.org/packages/rasuvaeff/yii3-clickhouse-toolkit)[Русская версия](README.ru.md)

Yii3 config bridge for [`rasuvaeff/clickhouse-toolkit`](https://github.com/rasuvaeff/clickhouse-toolkit). Install it and a ClickHouse client, migration runner and the three migration console commands are wired into the container straight from `CLICKHOUSE_*`environment variables — no hand-written `config/di.php` boilerplate.

This package ships **only configuration** (`config/di.php` + `config/params.php`) and a small parameter factory. All the actual ClickHouse machinery lives in `rasuvaeff/clickhouse-toolkit`; this is the glue that makes it a one-line install in a Yii3 application.

> Using an AI coding assistant? [llms.txt](llms.txt) has a compact API reference you can use.

Requirements
------------

[](#requirements)

- PHP 8.3–8.5
- [`rasuvaeff/clickhouse-toolkit`](https://github.com/rasuvaeff/clickhouse-toolkit) `^1.2` (pulled in automatically; migration commands need ≥ 1.2.0)
- A Yii3 application using [`yiisoft/config`](https://github.com/yiisoft/config)with the standard `RecursiveMerge::groups('params', …)` setup (the app template default)
- A PSR-18 HTTP client + PSR-17 factories (e.g. `guzzlehttp/guzzle`)

Installation
------------

[](#installation)

```
composer require rasuvaeff/yii3-clickhouse-toolkit
```

`yiisoft/config` discovers the bundled config plugin automatically.

What it wires
-------------

[](#what-it-wires)

Once installed, the following container entries resolve from the merged config:

Container idResolves toNotes`Rasuvaeff\ClickHouseToolkit\ClickHouseConfig``ClickHouseConfig`built from the params below`Rasuvaeff\ClickHouseToolkit\ClickHouseClientFactory``ClickHouseClientFactory`picks up an app-bound PSR-18 client / PSR-17 factories if present`SimPod\ClickHouseClient\Client\PsrClickHouseClient`live clientvia `ClickHouseClientFactory::create()``SimPod\ClickHouseClient\Client\ClickHouseClient`alias → `PsrClickHouseClient`type-hint the interface`Rasuvaeff\ClickHouseToolkit\ClickHouseMigrationRunner`migration runnerneeds `migrationsPath` (see below)`Rasuvaeff\ClickHouseToolkit\ClickHouseMigrationRunnerInterface`alias → runner`Rasuvaeff\ClickHouseToolkit\ClickHouseMigrationGenerator`migration generatorneeds `migrationsPath``Rasuvaeff\ClickHouseToolkit\ClickHouseMutationBuilder`mutation builder`ALTER … UPDATE/DELETE`, over the live client`Rasuvaeff\ClickHouseToolkit\ClickHousePartitionManager`partition managerdrop/attach/freeze/move partitions, over the live clientThree console commands are registered under `yiisoft/yii-console`:

CommandAction`clickhouse:migrations:generate `create the next `NNN_*.sql` file`clickhouse:migrations:status`show applied / pending / missing / diverged`clickhouse:migrations:migrate`apply pending migrationsConfiguration
-------------

[](#configuration)

Defaults come from environment variables. Override any of them by redefining the `rasuvaeff/yii3-clickhouse-toolkit` params key in your application config.

ParamEnv varDefault`host``CLICKHOUSE_HOST``127.0.0.1``port``CLICKHOUSE_PORT``8123``database``CLICKHOUSE_DB``default``username``CLICKHOUSE_USER``default``password``CLICKHOUSE_PASSWORD``''``secure``CLICKHOUSE_SECURE``false` (accepts `1/true/on/yes`)`migrationsPath``CLICKHOUSE_MIGRATIONS_PATH`*unset — required for migrations*`migrationPlaceholders`—`[]``migrationsPath` has **no safe default**: resolving the migration runner or generator without it throws a clear `RuntimeException` rather than silently operating relative to the working directory. Set the env var, or point the param at your migrations directory:

```
// config/common/params.php
return [
    'rasuvaeff/yii3-clickhouse-toolkit' => [
        'migrationsPath' => dirname(__DIR__, 2) . '/resources/clickhouse-migrations',
    ],
];
```

### Migration placeholders

[](#migration-placeholders)

`migrationPlaceholders` is passed to the runner as `{{key}}` substitutions, applied to every migration file **before** it is hashed and executed. That is how a package can ship DDL whose table name the application configures instead of hard-coding it:

```
// config/common/params.php
'rasuvaeff/yii3-clickhouse-toolkit' => [
    'migrationPlaceholders' => [
        'exposures_table' => 'ab_exposures',
    ],
],
```

Non-string keys and non-scalar values are dropped rather than reaching `str_replace()`. An unresolved `{{…}}` makes the runner throw, naming the file and the token — a typo does not travel to ClickHouse. Changing a value after a migration has been applied is reported as a divergence; see the `rasuvaeff/clickhouse-toolkit` README for what to do then.

Usage
-----

[](#usage)

Type-hint the client (or the interface) anywhere in your app:

```
use SimPod\ClickHouseClient\Client\ClickHouseClient;

final readonly class ReportService
{
    public function __construct(private ClickHouseClient $client) {}

    public function activeUsers(): int
    {
        return (int) $this->client->select('SELECT count() FROM events')->getRows()[0]['count()'];
    }
}
```

Run migrations from the Yii3 console:

```
./yii clickhouse:migrations:generate "create events table"
./yii clickhouse:migrations:migrate
./yii clickhouse:migrations:status
```

### Custom PSR-18 client (timeouts / TLS)

[](#custom-psr-18-client-timeouts--tls)

Bind your own configured PSR-18 client in the app; the bridge injects it into `ClickHouseClientFactory` automatically (it reads `Psr\Http\Client\ClientInterface`and the PSR-17 factories from the container when they are bound, otherwise falls back to auto-discovery):

```
// config/common/di.php
use Psr\Http\Client\ClientInterface;
use GuzzleHttp\Client;

return [
    ClientInterface::class => static fn (): Client => new Client(['timeout' => 5.0]),
];
```

### Composition with backend packages

[](#composition-with-backend-packages)

This bridge is the **single** binder of the toolkit client/config. Backend packages such as [`rasuvaeff/yii3-outbox-clickhouse`](https://github.com/rasuvaeff/yii3-outbox-clickhouse)consume `ClickHouseClientFactory` but never bind it, so installing both is conflict-free (verified against a real `yiisoft/config` merge). Their console commands and params co-exist under the standard recursive `params` merge.

Security
--------

[](#security)

- Connection credentials travel through environment variables and `X-ClickHouse-*` headers, never in the URI. Keep `CLICKHOUSE_PASSWORD` in your secret store, not in committed config.
- All query safety (parameterized queries, identifier validation) is the responsibility of `rasuvaeff/clickhouse-toolkit` — see its README.

Examples
--------

[](#examples)

Runnable, server-independent examples live in [`examples/`](examples/).

Development
-----------

[](#development)

No PHP/Composer on the host — everything runs in Docker via the `composer:2` image.

```
make install
make build          # validate → normalize → require-checker → cs → psalm → test
make cs-fix
make mutation       # minMsi 100
make release-check
```

License
-------

[](#license)

BSD-3-Clause. See [LICENSE.md](LICENSE.md).

###  Health Score

42

—

FairBetter than 88% of packages

Maintenance94

Actively maintained with recent releases

Popularity5

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~16 days

Total

2

Last Release

31d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b0812d5572a7041dfe36e222d295b2e6dc55833a605350fcde58a51a5965ed30?d=identicon)[rasuvaeff](/maintainers/rasuvaeff)

---

Top Contributors

[![rasuvaeff](https://avatars.githubusercontent.com/u/1352718?v=4)](https://github.com/rasuvaeff "rasuvaeff (7 commits)")

---

Tags

clickhouseconfig-bridgedatabasemigrationsolapphpyii3configdimigrationsclickhouseBridgeyiiyii3

###  Code Quality

Static AnalysisPsalm, Rector

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/rasuvaeff-yii3-clickhouse-toolkit/health.svg)

```
[![Health](https://phpackages.com/badges/rasuvaeff-yii3-clickhouse-toolkit/health.svg)](https://phpackages.com/packages/rasuvaeff-yii3-clickhouse-toolkit)
```

###  Alternatives

[tempest/framework

The PHP framework that gets out of your way.

2.3k37.6k21](/packages/tempest-framework)[cakephp/cakephp

The CakePHP framework

8.9k20.0M1.9k](/packages/cakephp-cakephp)[flow-php/flow

PHP ETL - Extract Transform Load - Data processing framework

86337.5k](/packages/flow-php-flow)[drupal/core-recommended

Locked core dependencies; require this project INSTEAD OF drupal/core.

6943.5M450](/packages/drupal-core-recommended)[chargebee/chargebee-php

ChargeBee API client implementation for PHP

758.7M10](/packages/chargebee-chargebee-php)[typo3/cms-core

TYPO3 CMS Core

3313.6M5.7k](/packages/typo3-cms-core)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
