This wiki does not contain official documentation and is currently deprecated and read only. Please try reading the documentation on the Liferay Developer Network, the new site dedicated to Liferay documentation. DISCOVER Build your web site, collaborate with your colleagues, manage your content, and more. DEVELOP Build applications that run inside Liferay, extend the features provided out of the box with Liferay's APIs. DISTRIBUTE Let the world know about your app by publishing it in Liferay's marketplace. PARTICIPATE Become a part of Liferay's community, meet other Liferay users, and get involved in the open source project. Writing Custom Upgrade Processes
Table of Contents [-]
Introduction#
By following a few, simple rules we can guarantee that Liferay can upgrade from any previous version to any newer version.
(See http://issues.liferay.com/browse/LPS-4583 )
Steps #
1. Create Table.java classes for any tables that you modify
Here's an example taken from the BookmarksEntry table for version 5.2.3:
package com.liferay.portal.upgrade.v5_2_3.util;
import java.sql.Types;
/**
* <a href="BookmarksEntryTable.java.html"><b><i>View Source</i></b></a>
*
* @author Brian Wing Shun Chan
*/
public class BookmarksEntryTable {
public static final String TABLE_NAME = "BookmarksEntry";
public static final Object[][] TABLE_COLUMNS = {
{"uuid_", new Integer(Types.VARCHAR)},
{"entryId", new Integer(Types.BIGINT)},
{"groupId", new Integer(Types.BIGINT)},
{"companyId", new Integer(Types.BIGINT)},
{"userId", new Integer(Types.BIGINT)},
{"createDate", new Integer(Types.TIMESTAMP)},
{"modifiedDate", new Integer(Types.TIMESTAMP)},
{"folderId", new Integer(Types.BIGINT)},
{"name", new Integer(Types.VARCHAR)},
{"url", new Integer(Types.VARCHAR)},
{"comments", new Integer(Types.VARCHAR)},
{"visits", new Integer(Types.INTEGER)},
{"priority", new Integer(Types.INTEGER)}
};
public static final String TABLE_SQL_CREATE = "create table BookmarksEntry (uuid_ VARCHAR(75) null,entryId...)";
public static final String TABLE_SQL_DROP = "drop table BookmarksEntry";
}This can now be auto-generated for you.
- All you need to do is create a directory that contains X number of src zip files.
- Point that directory in build.xxx.properties
- upgrade.table.path=K:/upgrade-table
- Run "ant build-upgrade-table" in portal-impl, and it'll automatically set everything now.
- http://issues.liferay.com/browse/LPS-4817
2. Use JDBC instead of ServiceImpl.java classes. Liferay services are usually tied to a specific version and may not work the same from one major revision to the next whereas JDBC will always work.
So use this:
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
con = DataAccess.getConnection();
ps = con.prepareStatement(
"select folderId, groupId from BookmarksFolder");
....instead of this:
List<BookmarksFolder> bookmarksFolders = BookmarksFolderLocalServiceUtil.getBookmarksFolders(...);
Final Notes #
That's it! You've now version proofed your upgrade process so that it will work no matter what version you're upgrading to.
You may want to use ps.executeUpdate() instead of runSQL() when updating content that may contain apostrophes or other special characters as updating content with special characters may cause issues.
Update #
This is also possible to be launched:
ant build-upgrade-table -Dupgrade.table.dir=src/com/liferay/portlet/dynamicdatamapping/model/impl
being -Dupgrade.table.dir the address where ModelImpl.java is