Liferay: Upgrade Steps Audit
Liferay: Upgrade Steps Audit
How to monitor and run repeatedly the Upgrade Steps
Introduction
Liferay Upgrade Steps are designed to be run only once in order to perform some changes on the portal: database schema changes, data or configuration updates. But sometimes they can fail, or implementation logic might be not correct, and we might need to run them again after proper adjustments. Also, we need to see the state of each upgrade module to know exactly which upgrade steps were run already, and which ones are still pending.
Audit and Running Upgrades
Check Available Upgrade Steps
To check pending upgrade steps on the portal - you can run a Gogo Shell command: upgrade:check
You should see the list of upgrade steps not executed yet in the output:
Note: navigate to Control Panel → Gogo Shell or use the telnet terminal to run Gogo Shell commands.
Inspect a Specific Upgrade Module
To inspect a specific module you can use a Groovy Script. Navigate to Control Panel → Server Administration → Script, and run the following script:
/*--------- Check Upgrade Step Version ---------*/
def dq = com.liferay.portal.kernel.service.ReleaseLocalServiceUtil.dynamicQuery()
dq.add(com.liferay.portal.kernel.dao.orm.RestrictionsFactoryUtil.eq(
"servletContextName", "com.mycompany.myproject.upgrade.process"));
result = com.liferay.portal.kernel.service.ReleaseLocalServiceUtil.dynamicQuery(dq)
release = result.get(0);
out.println(release) // Get Release Version
Note: specify the servletContextName value for your module (check the Bundle-SymbolicName property in bnd.bnd)
In the output you’ll see information about the upgrade module including current step number (schemaVersion), status, etc.
Modifying the Upgrade Step Number
Sometimes you might need to run an already executed step again, for example after some fixes or business-logic adjustments. To make the upgrade step executed again - you need to decrease the schemaVersion for that module to have a lower value than the upgrade step, you can do it with Groovy Script as well:
/*--------- Change Upgrade Step Version ---------*/
def dq = com.liferay.portal.kernel.service.ReleaseLocalServiceUtil.dynamicQuery()
dq.add(com.liferay.portal.kernel.dao.orm.RestrictionsFactoryUtil.eq(
"servletContextName", "com.mycompany.myproject.upgrade.process"));
result = com.liferay.portal.kernel.service.ReleaseLocalServiceUtil.dynamicQuery(dq)
release = result.get(0);
release.setSchemaVersion("2.0.2")
release =
com.liferay.portal.kernel.service.ReleaseLocalServiceUtil.updateRelease(release)
out.println(release)
For example, if you have an Upgrade Step from 2.0.2 to 2.0.3 which is run already - current schemaVersion is 2.0.3, and if you want to run that step again - you need to set schemaVersion back to 2.0.2.
Running Upgrade Steps
To run pending upgrade steps you can use Gogo Shell command:
upgrade:execute module.symbolic.link
Note: specify the module.symbolic.link for your module (check the Bundle-SymbolicName property in bnd.bnd)
In the output you can see the logs related to execution of the Upgrade Steps.
Summary
Using Gogo Shell and Groovy Scripts you can audit the upgrade steps, rollback the version of the upgrade module and run required upgrade steps repeatedly as needed.
Enjoy
Comments
Post a Comment