Implementing Content Versioning
This guide covers the process of enabling and utilizing Content Versioning in Directus.
Content Versioning allows teams to create and manage different versions of their content. There are several reasons to use Content Versioning, including drafting content without publishing it, and more ways to collaborate with others.
- Version: A version is a snapshot of a piece of content at a particular point in time. Each version represents the state of the content at a specific moment, and it can be used to track changes and maintain a history of the content.
- Main: The main version is the original version of a piece of content that has been created and published. It is the default version that is displayed to users. The main version is the "source of truth" for all other versions.
- Promote: Promoting a version means to make it the new main version. When a new version is promoted, it becomes the main version that is displayed to users, and it replaces the previous main version.
Setting Up Content Versioning
To enable Content Versioning for a collection in Directus, follow these steps:
- Log in to your Directus instance.
- Navigate to Settings > Data Model.
- Select the collection that you want to enable Content Versioning for.
- Scroll down to the Content Versioning section.
- Toggle "Enable Versions" and save your data model.
Creating a New Version
With Content Versioning set up, you can now create a new version of your content:
- Open an item within your desired collection.
- At the top of the item view, you will notice a dropdown with the main Content Version displayed as "main".
- From the dropdown, click "Create Version".
- Provide a key and a name for the new version. For instance, you can use "draft" as the key and "My Draft" as the name.
- Click "Save" to create the new version.
All new versions originate from the main version. This implies that the main version acts as the single source of truth for other versions.
Making Changes to a Version
After creating a new version, you can make changes without affecting the main version:
- Open the item in the newly created version e.g. "My Draft" version.
- Make the desired edits to the item's content.
- Save the changes.
- Notice that the main version remains unaffected, while the changes are reflected only in the "My Draft" version.
Reviewing and Promoting a Version
Once you are satisfied with the changes made in a version and want to incorporate them into the main version, you can promote the version. Follow these steps to promote a version:
- Open the version you want to promote.
- Select the "Promote Version" option from the dropdown.
- In the "Changes" tab, you can review all the changes made in the version and decide which changes to accept or reject.
- Switch to the "Preview" tab to see a preview of the changes you are about to promote.
- After reviewing the changes, confirm the promotion by clicking "Save".
After promoting a version, you can choose to keep or delete the version.
Programmatically Implement Content Versioning
You have the option to integrate Content Versioning through the API. To learn how to accomplish this, please refer to our API reference documentation.
Revisions and Content Versioning
Under the hood, content versions are stored in the
directus_revisions collection. In bigger projects this collection can get large.
Some Directus users combat this my periodically purging some or all data in this collection. Be aware that this could unintentionally purge content versions, so purging logic may have to be updated.
You have now set up Content Versioning for a collection and learned how to promote a version to the main version. Here are some additional tips when using this feature:
- Name versions descriptively so it's clear what changes each version contains.
- To prevent conflicts, ensure no modifications are made to the main version at the time a new version is created.
- Access the version history by referring the "Revisions" sidebar.
- Rollback to a previous main version by using the existing revert feature.
- Configure roles and permissions as needed to the