Skip to content

Instantly share code, notes, and snippets.

@kinglozzer
Created June 16, 2022 11:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kinglozzer/9e6b51774e4777db2014c7c9efe25c89 to your computer and use it in GitHub Desktop.
Save kinglozzer/9e6b51774e4777db2014c7c9efe25c89 to your computer and use it in GitHub Desktop.
Migrating elemental from a subclass of Page to Page
# Assumes the first non-zero ElementalAreaID in the versions table is the correct one to use
# (because they basically never change). Swap out table names as appropriate for your class.
# Don't forget to update Page_Live too!
UPDATE Page p
INNER JOIN
(
SELECT RecordID, ElementalAreaID
FROM CaseStudyPage_Versions
WHERE ElementalAreaID > 0
GROUP BY RecordID, ElementalAreaID, Version
ORDER BY Version ASC
) c
ON p.ID = c.RecordID
SET p.ElementalAreaID = c.ElementalAreaID
WHERE c.RecordID IS NOT NULL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment