« 返回到 Upgrade Instructions

Writing Custom Upgrade Processes

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

0 附件
39587 查看
平均 (0 票)
满分为 5,平均得分为 0.0。
评论
讨论主题回复 作者 日期
Xlent work... This reduces upgrade process... zaheer mohammed saddapalli 2009年10月7日 上午5:17

Xlent work...

This reduces upgrade process work.

I would like to ask one more question

Why should i migrate to higher version?
Why don't you provide all updates for irrespective of versions?

With regards,
Saddapalli Mohammed Zaheer
在 09-10-7 上午5:17 发帖。