library version
A simple database versioning system for ZF2 applications.
valorin/version
A simple database versioning system for ZF2 applications.
- Monday, December 10, 2012
- by valorin
- Repository
- 0 Watchers
- 0 Stars
- 14 Installations
- 0 Dependents
- 0 Suggesters
- 0 Forks
- 0 Open issues
- 4 Versions
- 0 % Grown
ZF2 Version Module v2
I've stopped working on this module because I found Phinx, a fantastic DB Migration tool. I recommend you use it!, (*1)
I'm working on ZF2 Module to integrate it into a ZF2 application: zf2-phinx-module., (*2)
A simple versioning system for ZF2 applications using the Zend\Console
package to
provide a secure way to manage versions.
It currently supports the Zend\Db\Adapter
class for database management, although
it has been built to handle other adapter modules if required.
(Feel free to implement your own and make a Pull Request.), (*3)
IMPORTANT: This module is still very much in development., (*4)
Installation Instructions
-
Install compser, and add "valorin/version": "dev-master"
to your ./composer.json
:, (*5)
{
"require": {
"valorin/version": "dev-master"
}
}
-
Run ./composer.phar install
to download the module into your application., (*6)
-
Add the module (ValVersion
) config/application.config.php
:, (*7)
<?php
return array(
// ...
'modules' => array(
'Application',
// ...
'ValVersion',
),
// ...
);
-
Add the configuration to config/autoload/global.php
, updating paths as required:, (*8)
<?php
return array(
// ...
'valversion' => Array(
'DbAdapter' => Array(
'class_dir' => __DIR__ ."/../../data/versions",
'class_namespace' => "\Application\Version",
),
),
// ...
);
-
Create version scripts in your specified class_dir
, following the template:, (*9)
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;
}
}
-
Version Management should now be available via the ZF Console interface., (*10)
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.
Have fun :), (*11)
Licence
See LICENCE.txt., (*12)