PayloadCMS plugin that sets up all necessary fields and hooks to enable collection versioning.
-
Run
npm install @stefgootzen/payload-plugin-versioningoryarn add @stefgootzen/payload-plugin-versioning. -
Add the following to the
pluginsection of the payload config. Use your own collections.
withVersioning({
enabled: true,
relations: [
{
baseSlug: MyBaseCollection.slug,
versionSlug: MyVersionCollection.slug,
},
],
})| Payload | Plugin-Versioning |
|---|---|
| 2.x | Compatible |
| 3.x | Untested |
One-to-many relationship management:
- Adds
versionsfield (many) onbasecollection. - Adds
basefield (one) onversioncollection.
Adds cascade behaviour:
- On
versiondelete: Deletesversiononbase. - On
basedelete: Deletes all correspondingversions.
Automatic versioning on versions:
- Adds an automatically incremented
versionNumberfield on version.
Utility for easy version creation:
- Easily create first
versiononbasecreation, like:axios.post(`${url}/api/base`, { ...baseData, version: { ...versionData } })
Payload's build-in versioning is useful when you've got a concept of a (latest) published document. This plugin is for you if versions are supposed to be "published".