Clean up historic content versions that contain legacy Grid JSON

Yeah I’ve encountered this.. even with document cleanup Umbraco retains 2 versions the published and saved version and I think the migrators (uSync as well) only ever migrate the version flagged as latest.

As it’s duff data now you could write a sql query to simply set the older versions to the new version.

(I’ve used “Two Column” as your UID but be careful if not, and choose something that will only get your legacy grid content, you’ll also need to find your matching propertytypeid(s) for those now blockgrid/list

;WITH LatestPerNode AS (
    SELECT
        cv.nodeId,
        pd.textValue,
        cv.versionDate,
        ROW_NUMBER() OVER (
            PARTITION BY cv.nodeId
            ORDER BY cv.versionDate DESC
        ) AS rn
    FROM umbracoPropertyData pd
    JOIN umbracoContentVersion cv
        ON pd.versionId = cv.id
    WHERE pd.propertytypeid = 1206
      AND pd.textValue LIKE '{"layout":%'
)
UPDATE oldpd
SET oldpd.textValue = latest.textValue
FROM umbracoPropertyData oldpd
JOIN umbracoContentVersion oldcv
    ON oldpd.versionId = oldcv.id
JOIN LatestPerNode latest
    ON latest.nodeId = oldcv.nodeId
   AND latest.rn = 1
WHERE oldpd.propertytypeid = 1206
  AND oldpd.textValue LIKE '%Two Column%'
  AND oldcv.versionDate < latest.versionDate;

or you could just take the view to just empty the old versions.

UPDATE umbracoPropertyData SET textValue = NULL WHERE textValue LIKE '%Two Column%';

Don’t forget to rebuild the hybrid cache.. aka nuCache just incase there were published remnants..