webfactory / slimdump

A tool for creating configurable dumps of large MySQL-databases.
MIT License
184 stars 26 forks source link

Dump TRIGGER definitions _after_ data #100

Closed mpdude closed 1 year ago

mpdude commented 1 year ago

When the new CSV output mode with the concept of "output drivers" was added in #92, dumping TRIGGER definitions was made an implementation detail of the MySQL output driver. This caused TRIGGER definitions to be dumped right after the CREATE TABLE ... commands, before the actual data INSERT statements.

This potentially breaks the generated SQL files, since a newly created trigger may be relevant for the subsequent INSERT statements; however, MySQL requires that tables used in the trigger are also included in the LOCK TABLES statements.

The aim of this PR is to revert that change, i. e. to dump trigger definitions for a table after the data insert statements for it.

I think it is not necessary to move all trigger definitions to the very end of the output – that is, after all tables have been created and filled with data: A trigger depends on insert/update/deletes for a particular table and is executed only on these events. So, it is not a problem if a trigger refers to a table that has not been created/loaded yet as long as the trigger is not run (and avoiding to run it is the aim of this PR).