Moved deletion of secondary tables before the deletion of machine table ...

...to satisfy the constraints, otherwise the deletion of records in MySQL and PostgreSQL would fail, as the constraints aren't satisfied. This caused the database not to be pruned when using MySQL and PostgreSQL, and the number of machines in the database starts to grow with every restart.