onnov / php-clickhouse-migrator
Clickhouse 迁移工具。来自 https://github.com/khaydarov/php-clickhouse-migrator 的分支
v1.0.2
2022-07-26 11:18 UTC
Requires
- php: >=7.0
- smi2/phpclickhouse: ^1.3
- symfony/console: ^5.0|^6.0
- symfony/yaml: ^5.0|^6.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.16
- php-coveralls/php-coveralls: ^2.2
- phpbench/phpbench: @dev
- phpmd/phpmd: ^2.8
- phpunit/phpunit: ^8.5
- psy/psysh: @stable
- roave/security-advisories: dev-master
This package is auto-updated.
Last update: 2024-08-26 19:15:14 UTC
README
- Clickhouse 迁移工具。来自 https://github.com/khaydarov/php-clickhouse-migrator 的分支
- 适用于 php-8.* && Symfony 6.*
composer r onnov/php-clickhouse-migrator
要求
PHP 7.0 或更高版本
安装
它可以从 composer 中获取
composer require khaydarov\php-clickhouse-migrator
安装后,您可以通过脚本 ./vendor/bin/clickhouse-migrator
运行迁移器命令
用法
运行脚本时,将显示可用命令列表
$ ./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
初始化
每个命令都在包含 composer.json 和 vendor 目录的项目根目录下执行。
在运行命令之前,您需要创建一个配置文件。您可以使用自己创建的文件,或者运行 init
命令来创建新文件。
以下命令创建新的 php 配置文件
vendor/bin/clickhouse-migrator init -f php
配置
支持两种配置扩展:YAML 和 PHP
配置结构
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
指向环境凭据。当未传递 -e
时,使用此属性的值
创建新修订版
使用 create
命令创建新修订版
vendor/bin/clickhouse-migrator create RevisionName
RevisionName 是类名,因此必须使用驼峰式命名法。迁移文件将类似于 20200125120301_RevisionName
,其中 20200125120301
是 ID,其余部分是类名。
运行命令后,在迁移路径中将出现 20200125120301_RevisionName.php
文件
<?php use Khaydarovm\Clickhouse\Migrator\AbstractMigration; class RevisionName extends AbstractMigration { public function up() { } public function down() { } }
up()
方法用于迁移,down()
用于回滚。
目前 rollback
和 status
没有实现。但很快就会完成。
最初 AbstractMigration 提供了三种方法
- getDatabase() — 从配置文件获取数据库名称
- getCluster() - 从配置文件获取集群名称
- execute(string $query) - 执行传入的 SQL 查询的方法