fiisoft/phinx
Composer 安装命令:
composer require fiisoft/phinx
包简介
Console-commands to use Phinx's library console-commands in custom console application (based on symfony/console package).
关键字:
README 文档
README
Console-commands to use Phinx's library console-commands in custom console application (based on symfony/console package).
My advice is - do not use it unless you are enough strong mentally to immune for such bad code.
It contains wrappers for Phinx's commands:
- breakpoint
- create
- migrate
- rollback
- seed:create
- seed:run
- status
- test
It also contains six special commands (not available in Phinx):
- mark - marks migration as migrated without migrating it (adds entry log to phinxlog so migration seems to be already migrated)
- unmark - removes entry log from phinxlog, without rollback on migration (so migration will be migrated on next migrate)
- repeat - repeats single migration (specified by its version number) even if migrated
- revoke - performs rollback on single migration (specified by its version number)
- remove - removes entry log from phinxlog and deletes corresponding migration file from disk
- cleanup - removes entries of missing migrations from phinxlog (if files are not available)
In addition, it comes with special generic-purpose command phinx which allows to run other Phinx-specific commands in special way.
Keep in mind that this library uses its own configuration-schema as well as template for migrations classes and base abstract class for them.
The main goal of this custom configuration is to manage migrations for many destiny databases (in various environments). Therefore configurations are grouped in something called "destiny".
Here are some examples.
- The simplest possible (aka minimal required) configuration:
$config = new PhinxConfig([ 'local' => [ 'environments' => [ 'dev' => [ 'adapter' => 'pgsql', 'host' => 'localhost', 'name' => 'dbname', 'user' => 'username', 'pass' => 'password', ] ], ] ]);
This creates config for one destiny called local with one environment dev.
Migration files for this destiny will be stored in (current working directory)/phinx/local/migrations directory.
Notice that the name of destiny becames part of path.
- Similar configuration but with path to files with migrations in specified directory without name of destiny:
$config = new PhinxConfig([ 'local' => [ 'paths_root' => __DIR__ . DIRECTORY_SEPARATOR . 'phinx', 'environments' => [ 'dev' => [ 'adapter' => 'pgsql', 'host' => 'localhost', 'name' => 'dbname', 'user' => 'username', 'pass' => 'password', ] ], ] ]);
In this case path to migration files is __DIR__/phinx/migrations - there is no name of destiny local in path.
- Third way to create the simplest configuration is to specify path to directory with migrations like this:
$config = new PhinxConfig([ 'defaults' => [ 'phinx_files' => __DIR__ . DIRECTORY_SEPARATOR . 'dev', ], 'local' => [ 'environments' => [ 'dev' => [ 'adapter' => 'pgsql', 'host' => 'localhost', 'name' => 'dbname', 'user' => 'username', 'pass' => 'password', ] ], ] ]);
This defines root folder for all destinations. The path for migration files for local is now __DIR__/dev/local/migrations.
To handle various different sets of migrations reffered to the same database, use:
$config = new PhinxConfig([ 'defaults' => [ 'adapter' => 'pgsql', 'host' => 'localhost', 'name' => 'dbname', 'user' => 'username', 'pass' => 'password', ], 'alpha' => [ 'environments' => [ 'dev' => [ ], ], ], 'bravo' => [ 'environments' => [ 'dev' => [ ], 'default_migration_table' => 'phinx_migrations', ], ], ];
This configuration defines two destinations: alpha and bravo.
Migration files for alpha will be stored in (current working directory)/phinx/alpha/migrations
and the name of the table used by Phinx will be phinxlog (as default).
Migration files for bravo will be stored in (current working directory)/phinx/bravo/migrations
and the name of the table used by Phinx will be phinx_migrations.
Because there are no other data specified, both destinations will share the same database, so it gives possibility to handle various sets of migrations for the same database.
There is also a bin/finx executable file provided with library. Usage of it is a bit hard to explain because it uses its own schema of arguments.
Some examples (lets assume the local destination is defined in configuration):
bin/finx listshow list of available commandsbin/finxthe same as above (command list is default)bin/finx phinxshow help for generic command (phinx)bin/finx phinx local statusshow status of migrations from destiny localbin/finx phinx localthe same as above (command status is default)bin/finx localthe same as above (status is default, keyword phinx can be omitted)bin/finx phinx:status localthe same as above (by direct call of command status)
Some examples of call command migrate with environment dev from destination local, in different ways (and all do exactly the same!):
bin/finx phinx local migrate -e devbin/finx phinx local dev migratebin/finx phinx local migratebin/finx phinx:migrate local -e devbin/finx phinx:migrate local devbin/finx phinx:migrate localbin/finx local migrate -e devbin/finx local dev migratebin/finx local migrate(this one I prefer)
As you can see, it's a bit crazy.
fiisoft/phinx 适用场景与选型建议
fiisoft/phinx 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 39 次下载、GitHub Stars 达 1, 最近一次更新时间为 2017 年 10 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「console」 「migration」 「phinx」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 fiisoft/phinx 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 fiisoft/phinx 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 fiisoft/phinx 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
This class provides you with an easy-to-use interface to progress bars.
Phinx makes it ridiculously easy to manage the database migrations for your PHP app.
A Laravel package to retrieve data from Google Search Console
Additional artisan commands for Laravel
Very simple SQL-based database migrations tool - a heavily stripped down fork of robmorgan/phinx
Lets you add foreign keys in a swift! Foreign key adder in laravel migration.
统计信息
- 总下载量: 39
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-10-08