FogBugz 8.0 is in beta! Join now to check out our new features.
2

I have a bunch of old customer emails and attachments that I want to get rid of. How can I get rid of large email attachments that are older than 6 months old?

flag

1 Answer

2

First, make sure to back up your database prior to running the following script. :)

The following query should delete any email attachments that are more than 6 months old.

DELETE FROM Attachment WHERE ixAttachment IN
    (SELECT Attachment.ixAttachment
            FROM Attachment INNER JOIN BugEvent
                ON Attachment.ixBugEvent = BugEvent.ixBugEvent
            WHERE DATEDIFF(mm, dt, GetDate()) > 6 AND fEmail = 1
    )

Or for MySQL

DELETE FROM Attachment WHERE ixAttachment IN
    (SELECT Attachment.ixAttachment
            FROM Attachment INNER JOIN BugEvent
                ON Attachment.ixBugEvent = BugEvent.ixBugEvent
            WHERE dt < DATE_SUB(NOW(), INTERVAL 6 MONTH) > 6 AND fEmail = 1
    )

If at some point you need to retrieve the deleted attachments for a specific bug, you should be able to do so by running the following query and then re-visiting that case (replace CASE_ID with the id of the bug whose attachments you're trying to recover):

UPDATE BugEvent SET fHTML = 0 WHERE ixBug = CASE_ID
link|flag
Since when does FogBugz extract email attachments from mails? I thought the whole EML-file was put as unicode string into the BugEvent table. Did you change this somewhen? – Christian Jun 17 at 7:03
1 
We do store the entire email in the BugEvent table, but we also extract any attachments and store them in the Attachment table. This allows us to avoid re-parsing the entire email every time someone downloads one of its attachments. This also allows us to easily display image attachments in FogBugz. – db Jun 17 at 14:08
Thanks for that answer! Did you already do that in FB 6.0? – Christian Jun 17 at 20:45
I don't believe so. In FB 6 I believe we re-parsed the email source every time we needed to get at one of its attachments. – db Jun 18 at 14:45

Your Answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.