take a look at this SQL queries:
it gives you good idea about the DB structure and how files and their previous version belong together. Should be not hard to adopt for deleted files…