GithubHelp home page GithubHelp logo

php-clickhouse-migrator's Introduction

php-clickhouse-migrator

Migrations for Clickhouse

Daily Downloads Latest Stable Version Coverage Status

Requirements

PHP 7.0 or newer

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

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

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

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

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

<?php

use Khaydarovm\Clickhouse\Migrator\AbstractMigration;

class RevisionName extends AbstractMigration
{
    public function up()
    {
    }

    public function down()
    {
    }
}

up() method is used for migrations and down() for rollbacks.

Currently rollback and status are not implemented. But it will be done soon.

Initially AbstractMigration provides three methods:

  • getDatabase() โ€” the database name from config file
  • getCluster() - the cluster name from config file
  • execute(string $query) - method executes passed SQL query

Development

Tests

php-clickhouse-migrator's People

Contributors

dependabot[bot] avatar khaydarov avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

onnov bugviktor90

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.