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?
5 Answers
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:
-
-
1While this Plugin is great, please also note there seems to be a native way now -> craftcms.stackexchange.com/a/35150/6673 Nov 18, 2020 at 11:42
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
-
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! :)– FrikselApr 20, 2020 at 17:31
-
As much as I love carlcs' work and plugin - this should be the right answer @bperdue Nov 18, 2020 at 11:41
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.
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
-
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!!).– carlcsJul 23, 2015 at 5:49
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!
-
-
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, 2015 at 17:34