adata-team/laravel-clickhouse-migrations

v1.0.6 2024-07-12 12:44 UTC

This package is auto-updated.

Last update: 2024-09-12 13:12:03 UTC


README

安装

通过Composer安装此包。

composer require adata-team/laravel-clickhouse-migrations

发布Clickhouse配置

php artisan vendor:publish --provider='Adata\ClickhouseMigrations\Providers\MigrationProvider'

基本用法

创建新的迁移文件

php artisan make:clickhouse-migration {name}

向上迁移

php artisan clickhouse-migrate

向下回退最后一个迁移

php artisan clickhouse-migration:rollback

高级用法

新建迁移

要创建新的迁移,使用以下命令

php artisan make:clickhouse-migration {name}

例如

php artisan make:clickhouse-migration create_users_table

新文件将位于配置中指定的路径:clickhouse.path

您可以使用包含添加新表模板的更准备的存根库,通过添加--table选项快速添加新表

php artisan make:clickhouse-migration create_users_table --table=users

字典

您可以使用包含添加新表模板的更准备的存根库,通过添加--table选项快速添加新表

php artisan make:clickhouse-migration create_users_dictionary --dictionary=users

路径

您可以通过传递--path选项来覆盖迁移文件夹的路径

php artisan make:clickhouse-migration create_users_table --path=database/new-migrations-folder

如果您想使用文件的绝对路径,请添加一个额外的选项 - 在现有选项中添加--realpath

php artisan make:clickhouse-migration create_users_table --path=/path/to/migrations --realpath

存根

创建新文件时,您可以使用自己的(覆盖)准备好的存根,列表:clickhouse.stubs

例如

php artisan make:clickhouse-migration create_users_table --stub=default

您还可以添加Handlers,通过它们,您可以在每次创建文件时自定义一个存根

php artisan make:clickhouse-migration create_users_table --stub=myStub --stub.handler='App\Clickhouse\MyHandler'

该类必须实现Adata\ClickhouseMigrations\Contracts\MigrationStubHandlerContract接口

您可以将您的$parameters传递,例如

php artisan make:clickhouse-migration create_users_table --stub.handler='App\Clickhouse\MyHandler' --stub.param=key:value --stub.param=table:products

您还可以注册一个全局处理器,该处理器将应用于所有生成的存根文件:clickhouse.handlers.global

向上迁移

使用Realpath选项的路径

强制

在生产迁移期间,要删除交互式问题,请使用--force选项

php artisan clickhouse-migrate --force

输出

要输出要应用迁移,请使用--output选项

php artisan clickhouse-migrate --output

在应用显示的迁移之前 - 将显示一个交互式问题,要删除它,您可以为此选项添加另一个--force选项

php artisan clickhouse-migrate --output --force

步骤

您可以指定需要应用多少个文件

php artisan clickhouse-migrate --step=1

0 - 所有文件

向下迁移

具有与向上迁移相同的属性。

其他

您可以使用smi2/phpClickHouse的单例对象查询ClickHouse(在迁移中使用)

app('clickhouse')->select(/* Query */);
app('clickhouse')->write(/* Query */);

许可证

MIT