Expand my Community achievements bar.

Learn about Edge Delivery Services in upcoming GEM session
SOLVED

How to deal with missing properties on nodes from earlier versions

Avatar

Level 2

Hi guys, imagine the following scenario:

I have a custom Template, let's call it my-template. This template is used to create Pages with properties called propA, propB and propC. My Sling scripts under /apps/<...>/components expects the Pages under /content to have those properties.

This is deployed to production environment and everything works fine.

Now, the business needs changes and I need to change my-template. It now has properties propA, propX and propY, where: 

  • propX is the same of former propB, but the previous name doesn't make more sense;
  • propY is a brand new property and,
  • propC was deleted as we don't need it anymore.

Then, my questions are:

  1. How should my Sling scripts deal with the old Pages (the ones with propA, propB and propC) created before the new Template properties where there? 
  2. Should I write my code to deal with both "versions" of Page I might have in the production environment?
  3. Having a relational database background, I would run a update SQL script to fix the old data. But how can I do such a thing with JCR? And more, Am I supposed to do such a thing?
  4. And lastly, how about nodes that are not under /content (e.g. /etc nodes)?

I  hope I could get my idea through. Shall you have any question, please, let me know.

Thank you in advance.

1 Accepted Solution

Avatar

Correct answer by
Level 4

Hi.

How about this tool: https://github.com/HS2-SOLUTIONS/hs2-aem-commons/tree/master/on-deploy-scripts-framework?
(I'm not sure if it is suitable for production environments)

Regards,

Daniel.

View solution in original post

5 Replies

Avatar

Level 5

question - how many pages in there which have old properties ? if they are few, you can write a groovy script or java code to update those properties. If those pages are in great number, you still can use the same script but need to be very careful while running it. You can run the script on the chunks to make sure that is works fine, other option is also fine -- put the condition inside the code to make it backward compatible with new properties but it is little weird to check the conditions for non existing properties in new pages.

Avatar

Level 2

Hi, thank you very much for your reply.

Unfortunately my Production environment is controlled by another team and I do not access to run scripts or even fix the Page nodes  by myself.

I can only send them packages to be installed via Package Manager.

I have definitely think about make the code backward compatible, but it doesn't seem to me as a good practice. In the future we might have new updates and then the code complexity could get to a point where it is very high just to keep the backward compatibility.

Avatar

Correct answer by
Level 4

Hi.

How about this tool: https://github.com/HS2-SOLUTIONS/hs2-aem-commons/tree/master/on-deploy-scripts-framework?
(I'm not sure if it is suitable for production environments)

Regards,

Daniel.

Avatar

Level 2
Hi kautuk, I didn't have the chance to apply any of this approaches as I moved to another project that does not AEM. :( I appreciate all the replies though, and they seems really promising. Let us know your experience if you apply any of them (or even a different approach) Thank you