Tool for copy records from one Mysql database to another with all dependencies.
Additional features:
- Build database UML (https://plantuml.com/)
- Build array/json 2-level tree for representation database
Via Composer
Add information about new package in your composer.json
"repositories": [
...
{
"type": "vcs",
"url": "https://github.com/lazada-com/database_minifier",
"name": "lazada-com/database_minifier"
}
],
"require-dev": {
"lazada-com/database_minifier": ">=0.0.1"
},
Create new object:
$dm = new \Lazada\DatabaseMinifier\DatabaseMinifier($masterConfig, $slaveConfig);
Where configs in format
array('dbname' => {DBNAME}, 'username' => {USERNAME}, 'password'=> {PASSWORD}, 'host' => {HOST}[, 'driver_options' => {options}])
You can build your database tree and use it in your purposes in format
[
"%table%": [
"primary_key": ["%PK1%", "%PK2%" /* , ... * /],
"references": [
"%table%": [
["%fk%": "%pk%" /* , ... * /] /* , ... * /
] /* , ... * /
],
"referenced_by": [
"%table%": [
["%fk%": "%pk%" /* , ... * /] /* , ... * /
] /* , ... * /
]
] /* , ... * /
]
Returns Json object like DatabaseMinifier::buildArrayTree()
copyRecordsByCriteria($tableName, array $criteria = [], $copyReferencedBy = true, $skipExists = false)
Copy all records (with all dependencies) from master db
to salve. If $copyReferencedBy
is true
it will also copy
all records depends on found records. If skipExists
is true tool will not try copy exists records in slave
db
See DatabaseMinifier::copyRecordsByCriteria
See DatabaseMinifier::copyRecordsByPks
See DatabaseMinifier::copyRecordsByCriteria
Build text-based uml for DB
- Create databases for tests: e.g.
test_master
ANDtest_slave
- Install master dump
mysql -uroot test_master < tests/_data/master_dump.sql
- Copy structure from master database to slave
mysqldump -uroot test_master --add-drop-table --no-data --verbose --result-file=/tmp/slave_dump.sql
mysql -uroot test_slave < /tmp/slave_dump.sql
- Copy
tests/BaseTest.php.dist
totests/BaseTest.php
and configure it - set your databases coordinates - Copy
phpunit.xml.dist
tophpunit.xml
- Run tests
phpunit -c phpunit.xml
Please see CONTRIBUTING for details.
The MIT License (MIT). Please see License File for more information.