payloadcms / payload

The best way to build a modern backend + admin UI. No black magic, all TypeScript, and fully open-source, Payload is both an app framework and a headless CMS.
https://payloadcms.com
MIT License
21.07k stars 1.27k forks source link

Blocks in blocks not possible in v3 with Postgres #6957

Open yobottehg opened 5 days ago

yobottehg commented 5 days ago

Link to reproduction

No response

Payload Version

3.0.0-Beta51

Node Version

20 LTS

Next.js Version

15.0-rc.0

Describe the Bug

When a Collection has a block field with some available blocks and one of these blocks has an additional blocks field It's not possible to generate a migration for this field.

We have a page collection with some Blocks. The blocks field looks like this:

{
      name: 'content',
      label: 'Content',
      type: 'blocks',
      minRows: 0,
      localized: true,
      blocks: [
        RichTextBlock,
        ImageBlock,
        TextImageBlock,
        LocalVideoBlock,
        RemoteVideoBlock,
        CTABlock,
        StructuredDataBlock,
        HighlightBoxBlock,
        AccordionBlock,
      ],
    },

The AccordionBlock now should allow for multiple accordion items where each one has a title and can have additional content elements inside.

The base fields for the accordionBlock look like this (First without the block in block feature):

fields: [
    {
      name: 'panels',
      label: 'Accordion Panels',
      type: 'array',
      fields: [{ name: 'title', label: 'Panel Title', type: 'text' }],
    },
  ],

This works. However when we add a blocks field inside the accordion fields we get different error messages:

1. version (It should work like this?)

fields: [
        { name: 'title', label: 'Panel Title', type: 'text' },
        {
          name: 'content',
          label: 'Content',
          type: 'blocks',
          localized: true,
          minRows: 0,
          blocks: [RichTextBlock, ImageBlock],
        },
      ],

yields [08:27:02] ERROR (payload): Error: cannot connect to Postgres. Details: Cannot read properties of undefined (reading 'Symbol(drizzle:Name)') when running payload migrate:create

Strange error which has nothing to do with the connection but seems like a serious issue in Drizzle?

2. version (differentiate blocks db table)

fields: [
        { name: 'title', label: 'Panel Title', type: 'text' },
        {
          name: 'content',
          label: 'Content',
          type: 'blocks',
          localized: true,
          dbName: 'accordion_item_content',
          minRows: 0,
          blocks: [RichTextBlock, ImageBlock],
        },
      ],

yields [08:28:22] ERROR (payload): There were 1 errors validating your Payload config [08:28:22] ERROR (payload): 1: Collection "pages" > Field "content" > "value" does not match any of the allowed type when running payload migrate:create.

If i remove the AccordionBlock from the pages collection it works again. So unsure which value is checked here.

If i remove the localized: true from the field i the yielded error is:

InvalidConfiguration: The table pages has multiple blocks with slug richText, but the schemas do not match. One is localized, but another is not. Block schemas of the same name must match exactly.

also with a different dbName for the accordion item.

I think it would work if I would create dedicated accordion_item_rich_text blocks but I would like to not go that route if possible.

Any hints on where to go from here would be very good!

Reproduction Steps

Please see bug description.

Adapters and Plugins

db-postgres

paulpopus commented 2 days ago

Hey @yobottehg, does this happen on the latest version of beta?

Also are you able to copy your configuration in a repro we can reproduce more easily please? Our test suite automatically tests for pg and we have a lot of nested blocks.