Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions scripts/patchLegalVersions.ts → scripts/patchVersions.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
import { getPayloadClient } from "../src/payloadClient";

const COLLECTION_TO_UPDATE = "some-collection"; // change this to the collection you want to update
const COLLECTION_TO_UPDATE = "events"; // change this to the collection you want to update
const EXPECTED_STATUS: "published" | "draft" = "published";

/**
* Need to enable versioning for an existing collection?
* See https://github.com/payloadcms/payload/discussions/5353
*
* This script should not be run standalone, unless you need to do local testing.
* To update a remote database, this file serves as a template and the below code
* should be copied to a migration file.
*/
async function patchCollectionVersioning() {
try {
const payload = await getPayloadClient();

// patch all documents to draft status
// patch all documents to expected status
const result = await payload.update({
collection: COLLECTION_TO_UPDATE,
where: {},
data: {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore - _status is a system field but we need to set it
_status: "draft",
_status: EXPECTED_STATUS,
},
});

console.log(`Successfully patched ${result.docs.length} documents to draft status.`);
console.log(`Successfully patched ${result.docs.length} documents to ${EXPECTED_STATUS} status.`);
console.log("This will trigger the versioning system to populate the versions collection.");
process.exit(0);
} catch (error) {
Expand Down
4 changes: 4 additions & 0 deletions src/collections/Events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export const Events: CollectionConfig = {
url: ({ data }) => `${process.env.NEXT_PUBLIC_SERVER_URL}/events/${data.slug}`,
},
},
versions: {
drafts: true,
maxPerDoc: 20,
},
access: {
create: canEditContent,
delete: canEditContent,
Expand Down
Loading
Loading