onnov/php-clickhouse-migrator
Composer 安装命令:
composer require onnov/php-clickhouse-migrator
包简介
Migrations for Clickhouse. Fork from https://github.com/khaydarov/php-clickhouse-migrator
README 文档
README
- Migrations for Clickhouse. Fork from https://github.com/khaydarov/php-clickhouse-migrator
- For php-8.* && Symfony 6.*
composer r onnov/php-clickhouse-migrator
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
onnov/php-clickhouse-migrator 适用场景与选型建议
onnov/php-clickhouse-migrator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 54 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 12 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 onnov/php-clickhouse-migrator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 onnov/php-clickhouse-migrator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 54
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-12-26