Using import feature to migrate content for existing document from a group field to a new slices schema

Hi there,

Rather than manually inputting data from a number of group fields, I'm keen to use the import feature to migrate content from one schema, where we're using group fields, to a new slice-based schema.

Where the existing group fields are named similarly to the below:

    "features_list": [{
        "item_name": "1 combi dispenser in the door for powder cleaning agent and rinsing agent"
    },

When I import the updated document, is it required that I include a key for the sliced content or will Prismic generate one if a key is missing? Or should I be generating a unique UID for that slice, similar to the below:

    "body2": [{
        "key": "product_details$cb87dc0f-0b6e-49ef-87c3-ec9e26d25a1d",
        "value": {
            "repeat": [{
                "item_name": "3-dimensional imbalance monitoring"
            }],
            "non-repeat": {}
        },
        "label": "features"
    },

Many thanks,

Duncan.

Ok, so I may have answered this myself. When importing the content you wish to migrate to an existing document, you just have to name the key by the slices key name, with no UID. A UID is generated by Prismic, and a new release is created on import.

An example of how your key should look on import, for the content you are migrating.

    "body2": [{
        "key": "product_details",
        "value": {
            "repeat": [{
                "item_name": "3-dimensional imbalance monitoring"
            }],
            "non-repeat": {}
        },
        "label": "features"
    },

Hey Duncan,

I'm glad you figured this out, but I can ask for a little more detail? Is what you are doing here migrating a group field from the static zone and transforming it into a Slice in the Slice Zone?

Thanks.

Hi Phil,

Yes, that is exactly what I'm doing. There is an additional level of complexity in the transformation process though.

This is mainly where I'm using a Python script to loop through the exported JSON files and check if the object keys for the related static group fields have an existing array.

If a condition matches an object key and an array exists, the existing array is then transformed into a new object with the new slice schema.

The matched object key will then have its array removed. So that when the release is generated and published in Prismic, we can successfully migrate away from the old schema without impacting the current web apps release, and upcoming release of our NextJS application.

I'm still currently finishing this script this evening. Though I hope that gives you an idea of the outcome I've designed, and am currently working on.

Does this help?

Really clear Duncan and I think this will help future users understand what's necessary for doing a similar transformation in their project structure.

Thanks for sharing and good luck with the migration.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.