Skip to content

dbschemix/clickhouse

Repository files navigation

Database Migrator: ClickHouse

A dbschemix migration driver for ClickHouse, built on smi2/phpclickhouse.

Usage

use dbschemix\clickhouse\Driver;
use dbschemix\clickhouse\Mode;
use dbschemix\core\Config;
use dbschemix\core\Migration;
use dbschemix\core\Migrator;

$driver = new Driver(
    host: '127.0.0.1',
    port: 8123,
    database: 'main',
    mode: Mode::Mutation,   // or Mode::AppendOnly
    username: 'default',
    password: '',
    // options: ['settings' => [...], 'https' => true, ...] // phpClickHouse passthrough
);

$migrator = new Migrator([
    new Migration(path: __DIR__ . '/migration/main', driver: $driver, config: new Config()),
]);

$migrator->init(); // creates the version table
$migrator->up();   // applies pending migrations

Modes

  • Mode::Mutation — version table is a ReplacingMergeTree; reads use FINAL, rollback removes the row via a synchronous ALTER TABLE ... DELETE.
  • Mode::AppendOnly — append-only journal; every up/down appends a row and the current state is derived with argMax. Nothing is physically deleted.

ClickHouse has no transactions: up/down run the migration and the version bookkeeping as separate statements, so a failure between them cannot be rolled back. The target database must already exist.

Static analysis

To run static analysis:

make check

To fix code style:

make fix

Testing

The package is tested with

To run tests:

make tests

About

dbschemix: clickhouse database migration driver

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors