tflori/breyta
Composer 安装命令:
composer require tflori/breyta
包简介
Library for database migrations
README 文档
README
Breyta is a library for database migrations. There are a lot of applications for database migrations but no actual library (without any user interface).
Trivia
I created this library after trying ruckusing-migrations. It's the only one that does not require any additional library to provide a user interface and is mentioned in awesome-php. Unfortunately it seems to be not actively developed and maintained. Also I'm missing some functionality and it is very old, not using PSR-2/4 and namespaces.
The name for this library comes again from the Icelandic language and means "to change".
Concept
- A migration is a set of database statements
- A migration has to run in a transaction
- Logging is important and goes to the migration table
- No code generating from this library (pure SQL)
- No user interface (API only)
- Generate fancy output and support progress bars
Installation
We only support and suggest using composer - everything else on your own risk.
$ composer require tflori/breyta
Usage
This might change in the next days till version 1.
Migration Script:
<?php namespace Breyta\Migrations; use Breyta\AbstractMigration; class CreateAnimalsTable extends AbstractMigration { public function up(): void { $this->exec('DROP TABLE IF EXISTS animals'); $this->exec('CREATE TABLE animals ( id MEDIUMINT NOT NULL AUTO_INCREMENT, name CHAR(30) NOT NULL, PRIMARY KEY (id) )'); } public function down(): void { $this->exec('DROP TABLE IF EXISTS animals'); } }
Control structure:
<?php namespace App\Cli\Commands; class MigrateCommand extends AbstractCommand // implements \Breyta\ProgressInterface { /** * Your database connection * @var PDO */ protected $db; public function handle() { $breyta = new \Breyta\Migrations($this->db, '/path/to/migrations', function($class, ...$args) { // return app()->make($class, $args); // the closure is optional. default: if ($class === \Breyta\AdapterInterface::class) { return new \Breyta\BasicAdapter(...$args); // first arg = closure $executor } return new $class(...$args); // first arg = AdapterInterface $adapter }); // register handler (optional) /** @var \Breyta\CallbackProgress $callbackProgress */ $callbackProgress = $breyta->getProgress(); $callbackProgress->onStart([$this, 'start']) ->onBeforeMigration([$this, 'beginMigration']) ->onBeforeExecution([$this, 'beforeExecution']) ->onAfterExecution([$this, 'afterExecution']) ->onAfterMigration([$this, 'finishMigration']) ->onFinish([$this, 'finish']); // alternative: implement \Breyta\ProgressInterface and register // $breyta->setProgress($this); $breyta->migrate(); } }
Please also have a look at the reference for a better overview of the api.
tflori/breyta 适用场景与选型建议
tflori/breyta 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6.41k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2018 年 11 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 tflori/breyta 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 tflori/breyta 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 6.41k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 13
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-11-20