Search code examples
kentico

Kentico 8.2 - Is there a way to delete Attachment History from the GUI


Our attachments have been stored in our database for a very long time, and it has caused the database to become huge and our backups to be extremely unreliable. We have moved our attachments to the file system and that shaved off a great deal of size.

Now our largest table is CMS_AttachmentHistory. I've been able to test brute force deleting every row in SQL (and every row in the CMS_VersionAttachment junction table). But is there a way to accomplish this in the Kentico Admin GUI without having to resort to this?

When I say brute force delete, I mean:

DELETE FROM dbo.CMS_VersionAttachment

DELETE FROM dbo.CMS_AttachmentHistory 

Solution

  • There is an option in the GUI that will do this, but it's also going to impact the page version history. If you go to Settings > Content > Content management and look in the Workflow section, you can see a setting named Version history length. Reducing this to a lower number (I believe 20 is the default) will reduce the version history stored to reflect the new value by deleting the unneeded rows.

    This will affect all version history though, not just the attachment, but also the pages themselves. That being the case, you would need to decide if you need/want to keep the version history of the pages or not.

    If you don't want to lose that history, then I'd say that a good option would be to write a script that can set the AttachmentBinary column to null for the records that you don't need/want (given that you say that you now store the files on the filesystem, any current versions will have the correct value, so this is probably all of them)