activecollab/databasemigrations
Composer 安装命令:
composer require activecollab/databasemigrations
包简介
Database schema migrations
README 文档
README
Migrations
To write a migration, create a class that is discoverable by Finder that you are using, and extend Migration class:
<?php namespace Acme\App\Migrations; use ActiveCollab\DatabaseMigrations\Migration\Migration; class AddUserRolesTable extends Migration { /** * {@inheritdoc} */ public function up() { } }
If you don't like how Migration class is structured, you can write your migrations any way you want, as long as you implement MigrationInterface:
<?php namespace Acme\App\Migrations; use ActiveCollab\DatabaseMigrations\Migration\MigrationInterface; class AddUserRolesTable implements MigrationInterface { … }
Migrations that extend Migration class get two important properties injected via constructor:
connection- aActiveCollab\DatabaseConnection\ConnectionInterfaceinstance with valid connection to the database, andlog- a PSR-3LoggerInterfaceinstance.
<?php namespace Acme\App\Migrations; use ActiveCollab\DatabaseMigrations\Migration\Migration; class AddUserRolesTable extends Migration { /** * {@inheritdoc} */ public function up() { if (!in_array('user_roles', $this->connection->getTableNames()) { $this->logger->debug('{table} not found in the database', ['table' => 'user_roles']); $thos->connection->execute('CREATE TABLE STATEMENT'); $this->logger->debug('{table} created', ['table' => 'user_roles']); } } }
Finders
Migration classes are "discovered" using objects that implement FinderInterface interface. All that we expect from finders is that they return an array where key is migration class name, and value is path where we can expect to find the class definition. This makes migration library independent on directory and file structure that you decide to use to organize your migrations.
This library currently implements only one Finder - Migrations in Changesets.
Migrations in a Changeset Finder
What we found to work really well for Active Collab project are migrations that are grouped in changesets. A changeset is a directory that has one or more related migrations. Valid format of the changeset directory name is YYYY-MM-DD-what-this-is-all-about. Here's a couple of valid changeset names:
2016-01-02-add-invoicing-module2016-03-12-remove-is-trashed-project-field2016-12-09-fix-users-table-indexes
Timestamp part of the changeset name is used for sorting, and details part is used to make it clear what the changeset is all about.
Command Line
Database Migrations package includes a couple of traits that make implementation of commands that work with migrations easy. These commands are:
- List all migrations and their status (All)
- Run all non-executed migrations (Up)
- Create a new migration file (Create)
In order to use these traits, you need to include them in a regular Symfony Console class, and provide implementation of getMigrations() method. This method needs to return a valid, configured MigrationsInterface instance.
Create helper has extra requirements and extension points that lets you configure how migration stubs are created. Please check protected and abstract methods under Override comment in /src/Command/Create.php file for details.
To Do
- Add basic field, index and foreign key management helper methods to the base
Migrationimplementation
activecollab/databasemigrations 适用场景与选型建议
activecollab/databasemigrations 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 16.93k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2016 年 03 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「migrations」 「mysql」 「activecollab」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 activecollab/databasemigrations 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 activecollab/databasemigrations 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 activecollab/databasemigrations 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dibi is Database Abstraction Library for PHP
Symfony ClickhouseMigrationsBundle
Very simple SQL-based database migrations tool - a heavily stripped down fork of robmorgan/phinx
Library that enables easy persistance of objects to the MySQL 5.7+ database
Tag objects and collections using etag
Define database structure in PHP and let the library generate object classes and tables
统计信息
- 总下载量: 16.93k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 7
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-03-13