fix(db-postgres): x3 and more nested blocks regression (#12770)

This commit is contained in:
Sasha
2025-06-12 19:37:07 +03:00
committed by GitHub
parent e7b5884ec2
commit df8be92d47
7 changed files with 119 additions and 6 deletions

View File

@@ -387,6 +387,7 @@ export const traverseFields = ({
if (typeof blocksTableNameMap[blockTableName] === 'undefined') {
blocksTableNameMap[blockTableName] = 1
} else if (
!adapter.rawTables[blockTableName] ||
!validateExistingBlockIsIdentical({
block,
localized: field.localized,

View File

@@ -72,6 +72,33 @@ export default buildConfigWithDefaults({
name: 'number',
type: 'number',
},
{
type: 'blocks',
name: 'blocks',
blocks: [
{
slug: 'block',
fields: [
{
type: 'blocks',
name: 'nested',
blocks: [
{
slug: 'block',
fields: [
{
type: 'blocks',
name: 'nested',
blocks: [],
},
],
},
],
},
],
},
],
},
{
type: 'tabs',
tabs: [

View File

@@ -2666,4 +2666,28 @@ describe('database', () => {
expect((e as ValidationError).message).toEqual('The following field is invalid: slugField')
}
})
it('should support x3 nesting blocks', async () => {
const res = await payload.create({
collection: 'posts',
data: {
title: 'title',
blocks: [
{
blockType: 'block',
nested: [
{
blockType: 'block',
nested: [],
},
],
},
],
},
})
expect(res.blocks).toHaveLength(1)
expect(res.blocks[0]?.nested).toHaveLength(1)
expect(res.blocks[0]?.nested[0]?.nested).toHaveLength(0)
})
})

View File

@@ -84,6 +84,7 @@ export interface Config {
'compound-indexes': CompoundIndex;
aliases: Alias;
'blocks-docs': BlocksDoc;
'unique-fields': UniqueField;
users: User;
'payload-locked-documents': PayloadLockedDocument;
'payload-preferences': PayloadPreference;
@@ -108,6 +109,7 @@ export interface Config {
'compound-indexes': CompoundIndexesSelect<false> | CompoundIndexesSelect<true>;
aliases: AliasesSelect<false> | AliasesSelect<true>;
'blocks-docs': BlocksDocsSelect<false> | BlocksDocsSelect<true>;
'unique-fields': UniqueFieldsSelect<false> | UniqueFieldsSelect<true>;
users: UsersSelect<false> | UsersSelect<true>;
'payload-locked-documents': PayloadLockedDocumentsSelect<false> | PayloadLockedDocumentsSelect<true>;
'payload-preferences': PayloadPreferencesSelect<false> | PayloadPreferencesSelect<true>;
@@ -178,6 +180,21 @@ export interface Post {
localized?: string | null;
text?: string | null;
number?: number | null;
blocks?:
| {
nested?:
| {
nested?: unknown[] | null;
id?: string | null;
blockName?: string | null;
blockType: 'block';
}[]
| null;
id?: string | null;
blockName?: string | null;
blockType: 'block';
}[]
| null;
D1?: {
D2?: {
D3?: {
@@ -525,6 +542,16 @@ export interface BlocksDoc {
updatedAt: string;
createdAt: string;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "unique-fields".
*/
export interface UniqueField {
id: string;
slugField?: string | null;
updatedAt: string;
createdAt: string;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "users".
@@ -617,6 +644,10 @@ export interface PayloadLockedDocument {
relationTo: 'blocks-docs';
value: string | BlocksDoc;
} | null)
| ({
relationTo: 'unique-fields';
value: string | UniqueField;
} | null)
| ({
relationTo: 'users';
value: string | User;
@@ -682,6 +713,27 @@ export interface PostsSelect<T extends boolean = true> {
localized?: T;
text?: T;
number?: T;
blocks?:
| T
| {
block?:
| T
| {
nested?:
| T
| {
block?:
| T
| {
nested?: T | {};
id?: T;
blockName?: T;
};
};
id?: T;
blockName?: T;
};
};
D1?:
| T
| {
@@ -997,6 +1049,15 @@ export interface BlocksDocsSelect<T extends boolean = true> {
updatedAt?: T;
createdAt?: T;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "unique-fields_select".
*/
export interface UniqueFieldsSelect<T extends boolean = true> {
slugField?: T;
updatedAt?: T;
createdAt?: T;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "users_select".

View File

@@ -1,5 +1,5 @@
{
"id": "945960df-cc37-406f-a343-58ea672a2286",
"id": "353cac31-1e1a-4190-8584-025abe855faa",
"prevId": "00000000-0000-0000-0000-000000000000",
"version": "7",
"dialect": "postgresql",

View File

@@ -1,4 +1,4 @@
import type { MigrateDownArgs, MigrateUpArgs } from '@payloadcms/db-postgres'
import type { MigrateDownArgs, MigrateUpArgs} from '@payloadcms/db-postgres';
import { sql } from '@payloadcms/db-postgres'

View File

@@ -1,9 +1,9 @@
import * as migration_20250528_153134 from './20250528_153134.js'
import * as migration_20250611_163948 from './20250611_163948.js'
export const migrations = [
{
up: migration_20250528_153134.up,
down: migration_20250528_153134.down,
name: '20250528_153134',
up: migration_20250611_163948.up,
down: migration_20250611_163948.down,
name: '20250611_163948',
},
]