SELECT distinct crftd.path, crftd.storage_area_key
FROM cr_files_to_delete crftd
WHERE not exists (SELECT 1
FROM cr_revisions r
WHERE r.content = crftd.path)
delete from cr_files_to_delete
insert into cr_mime_types
(mime_type, file_extension)
select
:mime_type, :extension
from dual
where not exists (select 1 from cr_mime_types where mime_type = :mime_type)