Download the PHP package maba/database-inconsistency-finder without Composer
On this page you can find all versions of the php package maba/database-inconsistency-finder. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download maba/database-inconsistency-finder
More information about maba/database-inconsistency-finder
Files in maba/database-inconsistency-finder
Package database-inconsistency-finder
Short Description Library that helps finding inconsistencies between database tables or different databases
License MIT
Informations about the package database-inconsistency-finder
Database inconsistency finder
Library that helps to find orphaned records (if they should be removed when nothing points to them), references to non-existing records and invalid number of references to those records.
When could this be helpful?
- you don't use foreign keys and could have invalid references. This could happen due to different reasons:
- you have several different databases, for example when sharding or using microservices;
- you don't use foreign keys for easier database structure migrations;
- you have application that just does not use foreign keys;
- you want to find orphaned records. For example, you can have Files in a database table and if nothing points to this record, we want to delete the file itself.
Normally, these restrictions would be guaranteed by your application. Unfortunately, stuff happens and there might be some inconsistencies that just occur time to time.
Installation
Configuration and usage
Currently all work is done synchronously. You can configure this by implementing
JobDistributorFactoryInterface
and related JobDistributorInterface
. In this case create service tree yourself,
do not use the Factory
class.
Internals
Consistency validation is performed in the following manner:
- ID range is queried from the database (from-to IDs in the main table)
- range is divided into separate intervals for job distribution
- each job is given to concrete worker
- worker validates consistency by using
SUM
query to the database, which is relatively fast - if inconsistencies are found in the interval, it's split into even smaller intervals
- with each smaller interval
SUM
query is repeated - for those intervals where inconsistencies are found, inconsistency seeking algorithm is ran
Inconsistency seeking algorithm
- all IDs and their corresponding reference counts are fetched from the database
- all related tables are iterated over and all IDs are fetched from there
- fetched data is looped to find any inconsistencies
These actions are performed in-memory, so it's essential that interval in this stage would be already quite small.
Consistency validation
Consistency is validated by issuing SUM
queries to database. To avoid false positives, we select not the sum
of reference counts, but sum of CRC32 of referenced IDs (and sum them that many times how many times they were
referenced).
Semantic versioning
This library follows semantic versioning.
See Symfony BC rules for basic information about what can be changed and what not in the API.
Running tests
Contributing
Feel free to create issues and give pull requests.
You can fix any code style issues using this command:
All versions of database-inconsistency-finder with dependencies
ext-pdo_mysql Version *
predis/predis Version ^1.1
doctrine/dbal Version 2.9.2