gared/database-structure-diff
Composer 安装命令:
composer require gared/database-structure-diff
包简介
Show database structure diffs between databases and sql structure dump
README 文档
README
This tool is written in PHP and is using doctrine to create diffs between database schemes. You can create a diff between a sql schema dump and a database. The output format is either a list of ALTER-SQL commands or a pretty text output. Another option is to get the diff programatically and use the result in your code.
Installation
Use composer
composer require gared/database-structure-diff
or clone this repository
git clone https://github.com/gared/database-structure-diff.git composer install --no-dev
Configuration
Copy the file config.example.php or copy this example in a file
<?php return [ [ [ 'dbname' => 'database_name', 'user' => 'username', 'password' => 'password', 'host' => 'hostname', 'driver' => 'pdo_mysql', ], [ 'dbname' => 'database_name', 'path' => 'path/to/file.sql', 'driver' => 'file', ], ], ];
You can also define multiple groups to make diff
<?php return [ [ [ 'dbname' => 'database_name', 'user' => 'username', 'password' => 'password', 'host' => 'hostname', 'driver' => 'pdo_mysql', ], [ 'dbname' => 'database_name', 'path' => 'path/to/file.sql', 'driver' => 'file', ], ], [ [ 'dbname' => 'database_name', 'user' => 'username', 'password' => 'password', 'host' => 'hostname', 'driver' => 'pdo_mysql', ], [ 'dbname' => 'database_name', 'user' => 'username', 'password' => 'password', 'host' => 'hostname', 'driver' => 'pdo_mysql', ], ], ];
For more database configuration read the doctrine configuration: https://www.doctrine-project.org/projects/doctrine-dbal/en/stable/reference/configuration.html
Usage
If you cloned this repository execute
php bin/console database:calculate-diff config.php
or if you installed it with composer
php vendor/gared/database-structure-diff/bin/console database:calculate-diff config.php
or use the option "output-file" to store an ALTER script to a file
php bin/console database:calculate-diff config.php --output-file alter.sql
Example output
$ php vendor/gared/database-structure-diff/bin/console database:calculate-diff config.php Database: example@10.10.1.1 => File: strcture.sql ------------------------------------------------- New tables ========== * user: user_id, name Removed tables ============== * player Changed tables ============== team ---- Added columns * team_short_name: String 10 Changed columns path * length: 100 => 255 Removed columns * user_id Removed indexes * FK_team_user Added foreign keys * FK_C4E0A61F3A35FDA4: (team_type_id) => team_type (team_type_id) group ----- Renamed indexes * fk_group => fk_group_idx
Use in your code
You can also work with the response of the diff in your code. Example code:
<?php require __DIR__ . '/vendor/autoload.php'; $fromConnection = new \DatabaseDiffer\Model\Config\Connection([ 'dbname' => 'database_name', 'user' => 'username', 'password' => 'password', 'host' => 'hostname', 'driver' => 'pdo_mysql', ]); $toConnection = new \DatabaseDiffer\Model\Config\Connection([ 'dbname' => 'database_name', 'path' => 'path/to/file.sql', 'driver' => 'file', ]); $group = new \DatabaseDiffer\Model\Config\Group($fromConnection, $toConnection); $diffService = new \DatabaseDiffer\Service\SchemaDiffService($group); $schemaDiff = $diffService->getSchemaDiff(); // $schemaDiff has all informations about changed tables, sequences, etc.
Supported Platforms
- Doctrine supported databases (MySQL, MariaDB, Oracle, etc.)
- You need at least PHP 7.4
gared/database-structure-diff 适用场景与选型建议
gared/database-structure-diff 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.29k 次下载、GitHub Stars 达 8, 最近一次更新时间为 2019 年 08 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 gared/database-structure-diff 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 gared/database-structure-diff 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 3.29k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 9
- 点击次数: 15
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-08-25