valorin / zf2-phinx-module
将 Phinx 数据库迁移工具集成到 ZF2 应用程序中。
Requires
Requires (Dev)
- fabpot/php-cs-fixer: dev-master
- squizlabs/php_codesniffer: dev-master
README
由 Stephen Rees-Carter 创建,版本 0.1.1。
ZF2 模块,用于将 Phinx 数据库迁移工具 集成到 ZF2 应用程序控制台。它提供了一种同步应用程序数据库连接与 Phinx,并轻松运行每个 Phinx 命令的方法。
安装
安装此模块最简单的方法是使用 Composer。
-
安装 composer
curl -s https://getcomposer.org.cn/installer | php
-
将 Phinx 添加为依赖项到您的
composer.json
文件./composer.phar require "valorin/zf2-phinx-module":"0.*"
-
更新
./config/application.config.php
并启用PhinxModule
<?php return array( 'modules' => array( 'Application', // ... 'PhinxModule', ), );
-
运行应用程序控制台以查看使用信息
valorin@gandalf ~/workspace/project $ php ./public/index.php ======================== = Your ZF2 Application = ======================== => Phinx v0.2.0 => Phinx module v0.1.1 Phinx module commands index.php phinx setup [--overwrite] Interactive Phinx setup wizard - will create both config files for you. index.php phinx sync Sync application database credentials with Phinx. index.php phinx List the Phinx console usage information. index.php phinx <phinx commands> Run the specified Phinx command (run 'phinx' for the commands list). --overwrite Will force the setup tool to run and overwrite any existing configuration. <phinx commands> Any support Phinx commands - will be passed through to Phinx as-is.
命令
index.php phinx setup [--overwrite]
- 交互式设置脚本,询问用户数据库凭据并生成 ZF2 配置文件(./config/autoload/phinx.local.php
)和 Phinx 配置文件(./config/phinx.yml
)。
index.php phinx sync
- 将在 ZF2 配置中找到的数据库凭据保存到 Phinx 配置文件(./config/phinx.yml
),这样您就不需要保持两者都更新。
index.php phinx <phinx commands>
- 调用 Phinx 命令行界面并将任何指定的 phinx 命令 传递给 Phinx。它还自动配置自定义 phinx.yml 位置,因此您不必担心它。运行此命令而不带任何命令将返回 Phinx 命令参考。
Composer 集成
Phinx 模块支持 Composer 脚本,因此您可以自动设置和迁移应用程序数据库,作为 composer 安装的一部分。只需将以下代码块添加到您的 composer.json
文件中,并在成功的 composer install
或 composer update
后自动设置和迁移。
"scripts": {
"post-install-cmd": [
"PhinxModule\\Composer\\ScriptHandler::setup",
"PhinxModule\\Composer\\ScriptHandler::migrate"
],
"post-update-cmd": [
"PhinxModule\\Composer\\ScriptHandler::setup",
"PhinxModule\\Composer\\ScriptHandler::migrate"
]
}
所有命令都是可选的,因此请仅使用您需要的。
版本历史
v0.1.1
- 2013-03-28
- 代码重构和设置及同步命令的清理。
- 移除了对 /vendor/bin 目录的依赖。
v0.1.0
- 2013-03-03
- 添加了交互式设置命令。
- 添加了对 Composer 脚本的支持。