#Migrate two Blocks into one

6 messages · Page 1 of 1 (latest)

balmy urchin
#

Hey, I have a small Problem. I accedently created two ways to embed Images on my Page I have the default Media Block and a custom one made by me. Both use the same data but I want to combine these two Blocks into one. Does anyone know hot to migrate them?

mild pasture
#

I think the easiest way would be to mabe combined field with mediaBlock fields, your custom mediaBlock fields and additional field "type" which define what kind of mediaBlock you want to use

Something like that:

export const combinedMediaBlock = (): Field => ({
  name: 'mediaBlock',
  label: {
    en: 'Media Block',
  },
  interfaceName: 'mediaBlock',
  type: 'group',
  fields: [
    {
      type: 'select',
      name: 'type',
      label: {
        en: 'Type',
      },
      options: [
        {
          label: {
            en: 'Default',
          },
          value: 'default',
        },
        {
          label: {
            en: 'Custom',
          },
          value: 'custom',
        },
      ],
    },
    {
      type: 'group',
      name: 'default',
      fields: mediaBlockFields(),
      admin: {
        condition: (_data, siblingData) => siblingData?.type === 'default',
      },
    },
    {
      type: 'group',
      name: 'custom',
      fields: customMediaBlockFields(),
      admin: {
        condition: (_data, siblingData) => siblingData?.type === 'custom',
      },
    },
  ],
});
balmy urchin
#

Its not like that I want to remove my old Block and jsut have one currently I have the default MediaBlock and a CustomMediaBlock but they do exactly the same but are stored differently in the DB. I Just want to migrate the CustomMediaBlock to a MediaBlock

mild pasture
#

so maybe you would to copy the table data of block in the database which you want to migrate , then change the fields names. or just change names and set properties one more time

#

I dont think payload has such a built-in function