philwc/version-db

轻松数据库版本控制 :)

v0.1 2013-11-22 22:27 UTC

This package is not auto-updated.

Last update: 2024-09-23 15:51:13 UTC


README

#VersionDB

##安装方法

  • 添加到你的 composer.json 文件中
"require": {
     "philwc/version-db": "dev-master"
}
  • 运行
composer.phar update
  • 添加一个 settings.yml 文件
parameters:
    database:
      user: <DBUSER>
      password: <DBPASS>
      host: <DBHOST>
      name: <DBNAME>
      changelogtable: changelog
    file:
      sqlDir: <LOCATION OF SQL FILES>
  • 在项目根目录下创建一个名为 console 的新文件,内容如下
#!/usr/bin/env php
<?php
require __DIR__ . '/vendor/autoload.php';
require __DIR__ . '/vendor/philwc/version-db/console';

##使用方法

  • 添加修订版本
php console add

系统会提示你填写所需的字段

  • 升级数据库
php console upgrade

这将读取 SQL 目录(从 settings.yml 文件),并按日期顺序应用更新 SQL 脚本

  • 降级数据库
php console downgrade

这将读取变更日志表,并允许你选择降级到哪个版本。然后它会按日期降序应用降级 SQL 脚本,直到达到指定的记录。

  • Web 前端

有一个示例文件(index.php),说明了如何使用前端。字段可以通过以下方式渲染:

$change = new \philwc\Web\AddChange();
$change->getHtml($action);

或者通过手动渲染,即

$change = new \philwc\Web\AddChange();
$html   = '<form id="vdbAdd" method="POST">';
foreach ($change->getFields() as $field) {
    //Split the fields names into a nice title format
    $a          = preg_split('/(?<=[a-z])(?=[A-Z])/x', $field);
    $fieldTitle = ucwords(implode(' ', $a));

    $html .= '<label class="input-group" for="' . $field . '">' . $fieldTitle . ': <input class="visibleInput" type="text" name="' . $field . '" id="' . $field . '"/></label>';
}
$html .= '<input name="submit" type="submit"></form>';

echo $html;

Bitdeli Badge