dyike/sqltool

sql diff tool.

v1.2.0 2016-09-26 01:58 UTC

This package is not auto-updated.

Last update: 2025-01-18 21:36:10 UTC


README

Build Status

基于PHP编写的查看线上线下数据库更新修改的状态,同时生成相应的sql语句。

安装

使用 Composer 安装:

composer require "dyike/sqlTool:~1.2"

使用

查看线上线下数据库的表,新增表、新增字段、修改字段的sql

use Dyike\Sqltool\Sql;
use Dyike\Sqltool\JudgeSql;

$tableOffLine = new Sql('hostOnLine', 'dbName', 'dbUser', 'dbPassword', 'dbPort');
$tableOnLine = new Sql('hostOFFLine', 'dbName', 'dbUser', 'dbPassword', 'dbPort');

//线上的数据表
$tOnLine = $tableOnLine->getTables();
//线下的数据表
$tOffLine = $tableOffLine->getTables();

$judgeSql = new JudgeSql();
//新增的数据
$getTablesToAdd = $judgeSql->getTableToAdd($tOnLine, $tOffLine);
foreach ($getTablesToAdd as $value) {
    //获取新增表的创建SQL
    $sql = $tableOffLine->getCreateTableSql($value);
    print_r($sql);
    echo "<br>";
}

foreach ($tOnLine as $value) {
    //获取线下表的字段
    $fieldsOffLine = $tableOffLine->getFields($value);
    //获取线上表的字段
    $fieldsOnLine = $tableOnLine->getFields($value);
    //新增字段的SQL
    $addFieldSql = $judgeSql->toAddFieldSql($fieldsOffLine, $fieldsOnLine, $value);
    //修改更新字段的SQL
    $updateFieldSql = $judgeSql->toUpdateFields($fieldsOffLine, $fieldsOnLine, $value);
}

License

MIT