12

I've been working on a site for a while in beta. The number of versions for all the pages is getting big and the database is now over 2MB. I'd love to just delete all the old versions of all pages when I go live with the site. Is there any easy way to do this?

14

I just wrote a plugin that deletes all versions (truncates the craft_entryversions table) and then saves a new version for each of your entries, so you can later revert back to it:

Delete All Entry Versions

2
7

EDIT: This is the only answer for Craft 3! All other answers refer to solutions in Craft 2.


The question is very old, but maybe in 2020 somebody still finds it. Nowadays you can just ./craft utils/prune-revisions

2
  • Hey, thanks a lot for this! I wanted to cleanup the revisions without going into sql every time, so in the end had set the max revisions to a low number to keep the entries low. But then we were missing the revisions. This solution way better! :)
    – Friksel
    Apr 20 '20 at 17:31
  • As much as I love carlcs' work and plugin - this should be the right answer @bperdue Nov 18 '20 at 11:41
5

I have a site with quite a lot of traffic and user submissions. After a while DB backups started taking too long (uncompressed sql dump over 300mb).

Instead of keeping the last change, I now keep 30 days worth of changes. I have a cron job set up to remove older revisions.

mysql -e 'DELETE FROM craft_entryversions WHERE dateUpdated < DATE_SUB(NOW(),INTERVAL 30 DAY)' dbname

If you don't need revisions for certain sections, just disable revisions altogether on a per section basis.

I hope this helps other people with large craft_entryversions tables.

3

You should be able to just safely delete them from the craft_entryversions table.

Obviously this deletes all your entry versions, so each entry will just exist at its last known 'live' state.

Also, backup your database first. :)

2
  • 2
    +1 for "backup your database first"
    – Lindsey D
    Jul 23 '15 at 5:02
  • There's one problem with this approach. You're also deleting the current versions with this, so you won't be able to revert to them once edits are made and saved. To solve this, open each entry and resave it (something you would better do with a custom plugin!!).
    – carlcs
    Jul 23 '15 at 5:49
0

Just to add to this, you can easily remove previous versions of files (except the current/most recent) with the following SQL query:

DELETE FROM craft_entryversions WHERE id NOT IN (SELECT id FROM (SELECT max(id), entryId FROM craft_entryversions GROUP BY entryId) X);

Obviously backup the old database/table first!

2
  • This is NOT a good idea, current version != last added version.
    – carlcs
    Nov 30 '15 at 17:12
  • Obviously a sledgehammer but in pre-launch instances where versioning isn't really being used yet this has proven a good way to clear out a bloated database of entries! Nov 30 '15 at 17:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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