fix(db-*): add delete version id for non-mongodb (#10613)
Fixes #10526 ### What? `updateVersion` throws error at deleting before version of draft. ### Why? When triggers `db.updateVersion` with non-mongodb environment, `saveVersion` in `payload/src/versions/saveVersions.ts` doesn't remove `id` in `versionData`. ### How? Add `delete versionData.id` for non-mongodb environments. --------- Co-authored-by: German Jablonski <43938777+GermanJablo@users.noreply.github.com>
This commit is contained in:
32
test/versions/collections/AutosaveWithMultiSelect.ts
Normal file
32
test/versions/collections/AutosaveWithMultiSelect.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import type { CollectionConfig } from 'payload'
|
||||
|
||||
import { autosaveWithMultiSelectCollectionSlug } from '../slugs.js'
|
||||
|
||||
const AutosaveWithMultiSelectPosts: CollectionConfig = {
|
||||
slug: autosaveWithMultiSelectCollectionSlug,
|
||||
versions: {
|
||||
drafts: {
|
||||
autosave: {
|
||||
interval: 2000,
|
||||
},
|
||||
},
|
||||
},
|
||||
fields: [
|
||||
{
|
||||
name: 'title',
|
||||
label: 'Title',
|
||||
type: 'text',
|
||||
required: true,
|
||||
unique: true,
|
||||
localized: true,
|
||||
},
|
||||
{
|
||||
name: 'tag',
|
||||
type: 'select',
|
||||
options: ['blog', 'essay', 'portfolio'],
|
||||
hasMany: true,
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
export default AutosaveWithMultiSelectPosts
|
||||
@@ -6,6 +6,7 @@ import { buildConfigWithDefaults } from '../buildConfigWithDefaults.js'
|
||||
import AutosavePosts from './collections/Autosave.js'
|
||||
import AutosaveWithDraftButtonPosts from './collections/AutosaveWithDraftButton.js'
|
||||
import AutosaveWithDraftValidate from './collections/AutosaveWithDraftValidate.js'
|
||||
import AutosaveWithMultiSelectPosts from './collections/AutosaveWithMultiSelect.js'
|
||||
import CustomIDs from './collections/CustomIDs.js'
|
||||
import { Diff } from './collections/Diff/index.js'
|
||||
import DisablePublish from './collections/DisablePublish.js'
|
||||
@@ -41,6 +42,7 @@ export default buildConfigWithDefaults({
|
||||
Posts,
|
||||
AutosavePosts,
|
||||
AutosaveWithDraftButtonPosts,
|
||||
AutosaveWithMultiSelectPosts,
|
||||
AutosaveWithDraftValidate,
|
||||
DraftPosts,
|
||||
DraftWithMax,
|
||||
|
||||
@@ -8,7 +8,7 @@ import * as qs from 'qs-esm'
|
||||
import { fileURLToPath } from 'url'
|
||||
|
||||
import type { NextRESTClient } from '../helpers/NextRESTClient.js'
|
||||
import type { DraftPost } from './payload-types.js'
|
||||
import type { AutosaveMultiSelectPost } from './payload-types.js'
|
||||
|
||||
import { devUser } from '../credentials.js'
|
||||
import { initPayloadInt } from '../helpers/initPayloadInt.js'
|
||||
@@ -18,6 +18,7 @@ import AutosaveGlobal from './globals/Autosave.js'
|
||||
import {
|
||||
autosaveCollectionSlug,
|
||||
autoSaveGlobalSlug,
|
||||
autosaveWithMultiSelectCollectionSlug,
|
||||
draftCollectionSlug,
|
||||
draftGlobalSlug,
|
||||
localizedCollectionSlug,
|
||||
@@ -654,6 +655,71 @@ describe('Versions', () => {
|
||||
expect(Number(updatedUpdatedAt)).toBeGreaterThan(Number(createdUpdatedAt))
|
||||
})
|
||||
|
||||
it('should update correct version at doc that has hasMany field when saving with autosave', async () => {
|
||||
const firstDocTag: AutosaveMultiSelectPost['tag'] = ['blog', 'essay']
|
||||
const doc = await payload.create({
|
||||
collection: autosaveWithMultiSelectCollectionSlug,
|
||||
data: {
|
||||
title: 'title 1',
|
||||
tag: firstDocTag,
|
||||
_status: 'published',
|
||||
},
|
||||
draft: false,
|
||||
})
|
||||
await payload.update({
|
||||
collection: autosaveWithMultiSelectCollectionSlug,
|
||||
id: doc.id,
|
||||
data: {
|
||||
title: 'title 2',
|
||||
tag: firstDocTag,
|
||||
},
|
||||
draft: true,
|
||||
autosave: true,
|
||||
})
|
||||
|
||||
const doc2 = await payload.create({
|
||||
collection: autosaveWithMultiSelectCollectionSlug,
|
||||
data: {
|
||||
title: 'title 1-2',
|
||||
tag: ['blog'],
|
||||
_status: 'published',
|
||||
},
|
||||
draft: false,
|
||||
})
|
||||
|
||||
await payload.update({
|
||||
collection: autosaveWithMultiSelectCollectionSlug,
|
||||
id: doc2.id,
|
||||
data: {
|
||||
tag: ['blog'],
|
||||
title: 'title 2-2',
|
||||
},
|
||||
draft: true,
|
||||
autosave: true,
|
||||
})
|
||||
await payload.update({
|
||||
collection: autosaveWithMultiSelectCollectionSlug,
|
||||
id: doc2.id,
|
||||
data: {
|
||||
tag: ['blog'],
|
||||
title: 'title 3-2',
|
||||
},
|
||||
draft: true,
|
||||
autosave: true,
|
||||
})
|
||||
|
||||
const lastDocVersion = await payload.findVersions({
|
||||
collection: autosaveWithMultiSelectCollectionSlug,
|
||||
where: {
|
||||
parent: {
|
||||
equals: doc.id,
|
||||
},
|
||||
},
|
||||
limit: 1,
|
||||
})
|
||||
expect(lastDocVersion.docs[0]?.version.tag).toEqual(firstDocTag)
|
||||
})
|
||||
|
||||
it('should validate when publishing with the draft arg', async () => {
|
||||
// no title (not valid for publishing)
|
||||
const doc = await payload.create({
|
||||
|
||||
@@ -72,6 +72,7 @@ export interface Config {
|
||||
'autosave-posts': AutosavePost;
|
||||
'autosave-with-draft-button-posts': AutosaveWithDraftButtonPost;
|
||||
'autosave-with-validate-posts': AutosaveWithValidatePost;
|
||||
'autosave-multi-select-posts': AutosaveMultiSelectPost;
|
||||
'draft-posts': DraftPost;
|
||||
'draft-with-max-posts': DraftWithMaxPost;
|
||||
'draft-with-validate-posts': DraftWithValidatePost;
|
||||
@@ -96,6 +97,7 @@ export interface Config {
|
||||
'autosave-posts': AutosavePostsSelect<false> | AutosavePostsSelect<true>;
|
||||
'autosave-with-draft-button-posts': AutosaveWithDraftButtonPostsSelect<false> | AutosaveWithDraftButtonPostsSelect<true>;
|
||||
'autosave-with-validate-posts': AutosaveWithValidatePostsSelect<false> | AutosaveWithValidatePostsSelect<true>;
|
||||
'autosave-multi-select-posts': AutosaveMultiSelectPostsSelect<false> | AutosaveMultiSelectPostsSelect<true>;
|
||||
'draft-posts': DraftPostsSelect<false> | DraftPostsSelect<true>;
|
||||
'draft-with-max-posts': DraftWithMaxPostsSelect<false> | DraftWithMaxPostsSelect<true>;
|
||||
'draft-with-validate-posts': DraftWithValidatePostsSelect<false> | DraftWithValidatePostsSelect<true>;
|
||||
@@ -291,6 +293,18 @@ export interface AutosaveWithValidatePost {
|
||||
createdAt: string;
|
||||
_status?: ('draft' | 'published') | null;
|
||||
}
|
||||
/**
|
||||
* This interface was referenced by `Config`'s JSON-Schema
|
||||
* via the `definition` "autosave-multi-select-posts".
|
||||
*/
|
||||
export interface AutosaveMultiSelectPost {
|
||||
id: string;
|
||||
title: string;
|
||||
tag?: ('blog' | 'essay' | 'portfolio')[] | null;
|
||||
updatedAt: string;
|
||||
createdAt: string;
|
||||
_status?: ('draft' | 'published') | null;
|
||||
}
|
||||
/**
|
||||
* This interface was referenced by `Config`'s JSON-Schema
|
||||
* via the `definition` "draft-with-max-posts".
|
||||
@@ -695,6 +709,10 @@ export interface PayloadLockedDocument {
|
||||
relationTo: 'autosave-with-validate-posts';
|
||||
value: string | AutosaveWithValidatePost;
|
||||
} | null)
|
||||
| ({
|
||||
relationTo: 'autosave-multi-select-posts';
|
||||
value: string | AutosaveMultiSelectPost;
|
||||
} | null)
|
||||
| ({
|
||||
relationTo: 'draft-posts';
|
||||
value: string | DraftPost;
|
||||
@@ -850,6 +868,17 @@ export interface AutosaveWithValidatePostsSelect<T extends boolean = true> {
|
||||
createdAt?: T;
|
||||
_status?: T;
|
||||
}
|
||||
/**
|
||||
* This interface was referenced by `Config`'s JSON-Schema
|
||||
* via the `definition` "autosave-multi-select-posts_select".
|
||||
*/
|
||||
export interface AutosaveMultiSelectPostsSelect<T extends boolean = true> {
|
||||
title?: T;
|
||||
tag?: T;
|
||||
updatedAt?: T;
|
||||
createdAt?: T;
|
||||
_status?: T;
|
||||
}
|
||||
/**
|
||||
* This interface was referenced by `Config`'s JSON-Schema
|
||||
* via the `definition` "draft-posts_select".
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
export const autosaveCollectionSlug = 'autosave-posts'
|
||||
export const autosaveWithMultiSelectCollectionSlug = 'autosave-multi-select-posts'
|
||||
|
||||
export const autosaveWithDraftButtonSlug = 'autosave-with-draft-button-posts'
|
||||
|
||||
@@ -28,6 +29,7 @@ export const textCollectionSlug = 'text'
|
||||
|
||||
export const collectionSlugs = [
|
||||
autosaveCollectionSlug,
|
||||
autosaveWithMultiSelectCollectionSlug,
|
||||
draftCollectionSlug,
|
||||
postCollectionSlug,
|
||||
diffCollectionSlug,
|
||||
|
||||
Reference in New Issue
Block a user