scriptburn / db-version-update
更新数据库结构的包,根据目标包版本进行更新
1.0.1
2017-12-20 13:02 UTC
Requires
- php: >=5.4.0
- scriptburn/db-settings: >=1.0
- scriptburn/simple-debug: >=1.0
This package is auto-updated.
Last update: 2024-08-30 01:20:05 UTC
README
##使用方法
创建一个子类,如下所示(已提供 sampleDbUpdateService.php 作为示例子类):class DbUpdateService extends \Scriptburn\UpdateDb {
// will be called for target db version 1
public function update_routine_1()
{
/* make sure to return true
other wise db update will stop propogating
and update process will run again
*/
return true;
}
// will be called for target db version 2
public function update_routine_2()
{
/* make sure to return true
other wise db update will stop propogating
and update process will run again
*/
return true;
}
}
接下来,我们将调用实际的功能,检查是否需要数据库更新。最佳代码位置是在中间件中 // 确保composer.json中有一个名为 dbversion 的键 $optionalVersionData=['type' => 'composer', 'path' => "/path/to/composer.json"];
$dbUpdateCheck = new App\Services\DbUpdateService(< \ScriptBurn\Settings 实例 >, < pdo连接实例 >, $optionalVersionData);
// 如果您将$optionalVersionData作为第三个参数传递给
App\Services\DbUpdateService
构造函数,则不需要传递当前数据库版本到方法maybeUpdate作为第二个参数 $dbUpdateCheck->maybeUpdate('scriptburn/git-auto-deploy',< 可选当前数据库版本号 >');