承接 apinstein/mp 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

apinstein/mp

Composer 安装命令:

composer require apinstein/mp

包简介

Migrations manager.

README 文档

README

MP: Migrations for PHP

MP is a generic migrations architecture for managing migrations between versions of a web application.

It can be used to migration database schemas as well as perform arbitary code during upgrades and downgrades.

INSTALLATION

pear install apinstein.pearfarm.org/mp

HOW IT WORKS
MP keeps track of the current version of your application. You can then request to migrate to any version.

MP also has a "clean" function which allows you to reset your application to "version 0". There is a clean() callback
which allows you to programmatically return your application to a pristine state when migrating with the "clean" option.

By default you can implement your "clean" functionality in the MigrationClean::clean() method of migrations/clean.php:

public function clean($migrator)
{
    $migrator->getDbCon()->exec("drop database foo;");
}

NOTE: If you prefer you can also create your baseline schema in clean. However, I usually set up the baseline schema in the first migration.

Each migration for your application is defined by a class in the migrations directory.

EXAMPLE CLI USAGE
$ mp -f                         # Use file-based version tracking; If no args will just print version.
                                # NOTE: First run of MP will create the migrations directory,
                                        create a stub clean script, and set the version to 0.
$ mp -f -n                      # Create a new migration; will write a stub file in migrations dir
$ mp -f -m                      # Migrate to head (latest revision)
$ mp -f -m20090716_204830       # Migrate to revision 20090716_204830
$ mp -f -r                      # Reset to "clean" state (version 0)

If you need DB access in your migrations, you can bootstrap them yourself, or, if you supply a dsn like so:
$ mp -x'pgsql:dbname=mydb;user=mydbuser;host=localhost'

Then in your migrations you can do:

$this->migrator->getDbCon()->exec($sql);

And in the clean() function, it's:
$migrator->getDbCon()->exec($sql);

NOTE: If you use Migrator's db connection, it is configured to throw PDOException on error.

EXAMPLE API USAGE
$m = new Migrator();
$m->clean();
$m->upgradeToLatest();
$m->downgradeToVersion('20090716_204830');
$m->upgradeToVersion('20090716_205029');
$m->downgradeToVersion('20090716_212141');

NOTE FOR SOURCE CONTROL
If you use the file-based version tracking (ie migrations/version.txt) then make sure to have your source control
system *ignore* that file. You definitely don't want your system to think it's been updated when you push new code
to production but before you run your migrations! Therefore it is recommended to use DB-based versioning wherever
possible.

INTEGRATION
While MP can be operated purely via the migrate command line tool, it is also designed to be implemented into your
web application or with any framework. You can use the Migrator API to custom-configure MP's behavior for your
application or framework.

This is ideal for use with ORMs that may already have an API to manage schemas but don't have a migrations system.
It also works well with ORMs that don't have an API to manage schemas, as you can still integrate with them to use
their DB connection for executing SQL migrations.

ROADMAP / TODO
- Add long-option support. See http://cliframework.com/, looks pretty interesting.
- Automatically walk up from pwd looking for migrations/ directory so you only have to be *under* your project root to run mp successfully.
- Addition of mutex protection to prevent multiple migrations from running at the same time.
- Addition of a generic schema manipulation API so you can use MP to manage your database without having to write SQL. Is this even necessary?
- This looks like an interesting project to integrate with: http://www.liquibase.org/
- Consider idea of adding the ability to link migrations to VCS/SCM tags -- sometimes a migration depends on a version of *code* as well as database structure!

apinstein/mp 适用场景与选型建议

apinstein/mp 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 39.5k 次下载、GitHub Stars 达 40, 最近一次更新时间为 2013 年 01 月 18 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「database」 「migrations」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 apinstein/mp 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 apinstein/mp 我们能提供哪些服务?
定制开发 / 二次开发

基于 apinstein/mp 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 39.5k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 40
  • 点击次数: 9
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 40
  • Watchers: 1
  • Forks: 7
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2013-01-18