A dbschemix migration driver for ClickHouse, built on smi2/phpclickhouse.
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 migrationsMode::Mutation— version table is aReplacingMergeTree; reads useFINAL, rollback removes the row via a synchronousALTER TABLE ... DELETE.Mode::AppendOnly— append-only journal; everyup/downappends a row and the current state is derived withargMax. Nothing is physically deleted.
ClickHouse has no transactions:
up/downrun the migration and the version bookkeeping as separate statements, so a failure between them cannot be rolled back. The target database must already exist.
To run static analysis:
make checkTo fix code style:
make fixThe package is tested with
To run tests:
make tests