Message Boards

How can I rerun my UpgradeProcess?

Matthew K., modified 3 Years ago.

How can I rerun my UpgradeProcess?

Junior Member Posts: 74 Join Date: 8/31/15 Recent Posts

Hello guys,

I am kind of used to the old Liferay 6.2 UpgradeProcess, but now I have to write my first UpgradeProcess for Liferay 7.3 and I don't know how to execute it for a second time. Here is my code:

@Component(immediate = true, service = UpgradeStepRegistrator.class)
public class MyUpgradeRegistrator implements UpgradeStepRegistrator {

	@Override
	public void register(Registry registry) {
		registry.register("0.0.0", "1.0.0", new com.sample.upgrade.v1_0_0.MyUpgradeStep());
	}

}

After deploying that component, the code in MyUpgradeStep is executed correctly. And if I redeploy the jar file, nothing happens, which is also correct. Now I change the code to:

@Component(immediate = true, service = UpgradeStepRegistrator.class)
public class MyUpgradeRegistrator implements UpgradeStepRegistrator {

	@Override
	public void register(Registry registry) {
                registry.register("0.0.0", "1.0.0", new com.sample.upgrade.v1_0_0.MyUpgradeStep());
                registry.register("1.0.0", "2.0.0", new com.sample.upgrade.v2_0_0.MyUpgradeStep());
	}

}

My expectation is that the first UpgradeStep does not run because it was already executed, but the second should run because it was never executed before. However, nothing happens. What did I wrong?

thumbnail
Andrew Jardine, modified 3 Years ago.

RE: How can I rerun my UpgradeProcess?

Liferay Legend Posts: 2416 Join Date: 12/22/10 Recent Posts

Hey Matt,

Never tried this oen myself but I have made a mistake in the past (easy to overlook) where I wrote the upgrade task but then forgot to change the version information in the bnd file. Did you remember to make that change as well? 

You probably did but I thought I would ask anyway -- even if you didn't, someone else that comes along might have :)

Matthew K., modified 3 Years ago.

RE: How can I rerun my UpgradeProcess?

Junior Member Posts: 74 Join Date: 8/31/15 Recent Posts

Hey Andrew, thanks for your answer, but I guess that this won't work anymore. I found this line in the Liferay code.

if (PropsValues.UPGRADE_DATABASE_AUTO_RUN ||
    (_releaseLocalService.fetchRelease(bundleSymbolicName) ==
        null)) {
    _upgradeExecutor.execute(
        bundleSymbolicName, upgradeInfos,
        OutputStreamContainerConstants.FACTORY_NAME_DUMMY);
}

So the UpgradeProcess will only rerun, if that portal property is set or if the bundleSymbolicName is not present in the release table. So changing versions won't have any effect. I have to rename my complete bundle if I want to execute my UpgradeProcess once again. This is actually a huge drawback compared to Liferay 6, but apparently you cannot change anything about that.

thumbnail
Andrew Jardine, modified 3 Years ago.

RE: RE: How can I rerun my UpgradeProcess?

Liferay Legend Posts: 2416 Join Date: 12/22/10 Recent Posts

Hey Matt,

I'm not convinced that it totally correct. The reason I say that is because when 7.0 was first released service builder changes were not automatically applied. The "correct" approach was to change the version numbers and include upgrade steps. I know that now, with the portal-developer properties included, that is no longer needed (locally) but for deployments outside of local, an upgrade task I believe is still best practice. What version do you have in you bnd file for your module?

Matthew K., modified 3 Years ago.

RE: RE: How can I rerun my UpgradeProcess?

Junior Member Posts: 74 Join Date: 8/31/15 Recent Posts

I dont have any specific version in my bnd file, only the Bundle-Name and the Bundle-SymbolicName. The bundle version is automatically inserted to the metadata of the module by the maven bnd plugin. So there is no need to put it there.