承接 onnov/php-clickhouse-migrator 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

onnov/php-clickhouse-migrator

最新稳定版本:v1.0.2

Composer 安装命令:

composer require onnov/php-clickhouse-migrator

包简介

Migrations for Clickhouse. Fork from https://github.com/khaydarov/php-clickhouse-migrator

README 文档

README

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

统计信息

  • 总下载量: 54
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-12-26