PayloadCMS plugin that sets up all necessary fields and hooks to enable collection versioning.
-
Run
npm install @stefgootzen/payload-plugin-versioning
oryarn add @stefgootzen/payload-plugin-versioning
. -
Add the following to the
plugin
section 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
versions
field (many) onbase
collection. - Adds
base
field (one) onversion
collection.
Adds cascade behaviour:
- On
version
delete: Deletesversion
onbase
. - On
base
delete: Deletes all correspondingversions
.
Automatic versioning on versions:
- Adds an automatically incremented
versionNumber
field on version.
Utility for easy version creation:
- Easily create first
version
onbase
creation, 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".