lundi 29 décembre 2014

How to ensure MYSQL imports of .sql files properly retain foreign key relationships, constraints, etc


Recently, we restored a MySQL '*.sql' file on two separate brand new MySQL instances. The MySQL version is 5.5.40 running on CentOS 6.6.


In one instance, everything restored fine. On the other, a foreign key relationship didn't import properly. We found this out when running smoke tests. The following error showed in the application log:


Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (prod.table1, CONSTRAINT table1_ibfk_1 FOREIGN KEY (unique_id_1) REFERENCES table2 (id))


Is there a way to proactively confirm after such a restore that all foreign keys and other constraints were properly imported? Obviously application functional testing can reveal this, but there will need to be a lot of tests done to make sure all foreign key relationships were covered, and it's very challenging to define tests that cover every possible relationship. I'm hoping for something more sophisticated.


I know that there are tools to checksum the data in the tables but that's not my goal here. I want to checksum the table relationships. I'm hoping that someone can point me to a utility or set of utilities that will allow a comparison of the database structure in the .sql file to the database itself after restore/import.





Aucun commentaire:

Enregistrer un commentaire