valorin / 版本
此包已被废弃且不再维护。未建议替代包。
为 ZF2 应用程序提供简单数据库版本控制系统的包。
2.0.0-alpha3
2012-10-31 23:14 UTC
Requires
- php: >=5.3.3
- zendframework/zendframework: 2.*
This package is auto-updated.
Last update: 2019-09-08 09:39:56 UTC
README
我停止了这个模块的开发,因为我发现了Phinx,一个出色的数据库迁移工具。我推荐您使用它!
我正在开发一个 ZF2 模块,将其集成到 ZF2 应用程序中: zf2-phinx-module。
遗留信息
使用 Zend\Console
包提供安全版本管理方式的一个简单版本控制系统,用于 ZF2 应用程序。它目前支持 Zend\Db\Adapter
类进行数据库管理,尽管它已经被构建为可以处理其他适配器模块,如果需要的话。 (您可以自由实现自己的并提交一个 Pull Request。)
重要:此模块仍在积极开发中。
安装说明
-
安装 Composer,并将
"valorin/version": "dev-master"
添加到您的./composer.json
{ "require": { "valorin/version": "dev-master" } }
-
运行
./composer.phar install
将模块下载到您的应用程序中。 -
将模块(
ValVersion
)添加到config/application.config.php
<?php return array( // ... 'modules' => array( 'Application', // ... 'ValVersion', ), // ... );
-
将配置添加到
config/autoload/global.php
,根据需要更新路径<?php return array( // ... 'valversion' => Array( 'DbAdapter' => Array( 'class_dir' => __DIR__ ."/../../data/versions", 'class_namespace' => "\Application\Version", ), ), // ... );
-
在指定的
class_dir
中创建版本脚本,按照模板操作Filename: [#version]-[ClassName].php i.e: 0-CreateStructure.php
<?php namespace Application\Version; use ValVersion\Script\VersionAbstract; class CreateStructure extends VersionAbstract { public function upgrade($adapter) { $sql = Array( "CREATE TABLE `table1` ( // ... )", "CREATE TABLE `table2` ( // ... )", ); foreach ($sql as $query) { $adapter->query($query, \Zend\Db\Adapter\Adapter::QUERY_MODE_EXECUTE); } return true; } public function downgrade($adapter) { $sql = Array( "DROP TABLE IF EXISTS `table1`", "DROP TABLE IF EXISTS `table2`", ); foreach ($sql as $query) { $adapter->query($query, \Zend\Db\Adapter\Adapter::QUERY_MODE_EXECUTE); } return true; } }
-
现在应该可以通过 ZF 控制台界面访问版本管理。
valorin@gandalf:~/workspace/zf$ php ./public/index.php > ValVersion module v2.0.0 alpha Version Management index.php version status Display the current version status of application. index.php version upgrade Upgrade the application to the latest version. index.php version upgrade TARGET Upgrade the application to the specified version. index.php version downgrade TARGET Downgrade the application to the specified version.
祝您玩得开心 :)
许可证
请参阅 LICENCE.txt。