PHPackages                             khaydarovm/php-clickhouse-migrator - 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. khaydarovm/php-clickhouse-migrator

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

khaydarovm/php-clickhouse-migrator
==================================

Migrations for Clickhouse

v2.0.0(3y ago)12.2k3[1 PRs](https://github.com/khaydarov/php-clickhouse-migrator/pulls)MITPHPPHP ^8.0

Since Jan 31Pushed 3y ago2 watchersCompare

[ Source](https://github.com/khaydarov/php-clickhouse-migrator)[ Packagist](https://packagist.org/packages/khaydarovm/php-clickhouse-migrator)[ RSS](/packages/khaydarovm-php-clickhouse-migrator/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (7)Versions (5)Used By (0)

php-clickhouse-migrator
=======================

[](#php-clickhouse-migrator)

Migrations for Clickhouse

[![Daily Downloads](https://camo.githubusercontent.com/5a6b45f930b96b4f5f7d732681a2487608817c4609c392aa012b56eff8481fed/68747470733a2f2f706f7365722e707567782e6f72672f6b6861796461726f762f7068702d636c69636b686f7573652d6d69677261746f722f642f6461696c79)](https://packagist.org/packages/khaydarov/php-clickhouse-migrator)[![Latest Stable Version](https://camo.githubusercontent.com/9b11288b4e13805ad35c5cd1dca96d5347000bd05ab6c5f12c2dfd9bfe6290ec/68747470733a2f2f706f7365722e707567782e6f72672f6b6861796461726f762f7068702d636c69636b686f7573652d6d69677261746f722f762f737461626c652e706e67)](https://packagist.org/packages/khaydarov/php-clickhouse-migrator)[![Coverage Status](https://camo.githubusercontent.com/d533b3127a907d767fb8a59a7c9142168905b17ec8b9a46f8eb1ab747d06c63b/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6b6861796461726f762f7068702d636c69636b686f7573652d6d69677261746f722f62616467652e706e67)](https://coveralls.io/r/khaydarov/php-clickhouse-migrator)

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

[](#requirements)

PHP 7.0 or newer

### Installation

[](#installation)

It is available from composer

```
composer require khaydarov\php-clickhouse-migrator
```

After installation you can run migrator commands via script `./vendor/bin/clickhouse-migrator`

Usage
-----

[](#usage)

When you run the script there will be the list of available commands

```
$ ./clickhouse-migrator
Console Tool

Usage:
  command [options] [arguments]

Options:
  -h, --help            Display this help message
  -q, --quiet           Do not output any message
  -V, --version         Display this application version
      --ansi            Force ANSI output
      --no-ansi         Disable ANSI output
  -n, --no-interaction  Do not ask any interactive question
  -v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Available commands:
  create    Create new migration file
  help      Displays help for a command
  init      Initialize Clickhouse migrations project
  list      Lists commands
  migrate   Migrate to specific revision of database
```

### Initialization

[](#initialization)

Each command is executed in the project's root where composer.json and vendor directory placed.

Before running commands you need to create a config file. It is possible to use your own created file or run `init` to create new one.

The command below creates new php config file

```
vendor/bin/clickhouse-migrator init -f php
```

### Configuration

[](#configuration)

There are two supporting config extensions: YAML and PHP

The config structure

```
default: development

paths:
  migrations: migrations

environments:
  development:
    cluster: local
    host: localhost
    port: 8123
    database: db
    username: user
    password: pass

  staging:
    cluster: stage
    host: stage.host
    port: 8123
    database: db
    username: user
    password: pass

  production:
    cluster: production
    host: production.host
    port: 8123
    database: db
    username: user
    password: pass
```

`default` points to the environment credentials. This property value used when `-e` is not passed

### Creating new revision

[](#creating-new-revision)

Use the `create` command to create a new revision

```
vendor/bin/clickhouse-migrator create RevisionName
```

The RevisionName is a class name, so it must be in camel case notation. Migration file will be like `20200125120301_RevisionName`, where `20200125120301` is ID and the rest is class name.

After running the command the file `20200125120301_RevisionName.php` will be appeared in migration path

```
