Author: vmassol
Date: 2008-02-06 00:08:39 +0100 (Wed, 06 Feb 2008)
New Revision: 7303

Modified:
   
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/store/migration/hibernate/R4359XWIKI1459Migrator.java
Log:
XWIKI-2074: Database Migration fails when migrating from 1.0 or older directly 
to 1.2 without going through a 1.1 upgrade

Merged from 1.2 branch (rev 7301)

Modified: 
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/store/migration/hibernate/R4359XWIKI1459Migrator.java
===================================================================
--- 
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/store/migration/hibernate/R4359XWIKI1459Migrator.java
      2008-02-05 22:55:39 UTC (rev 7302)
+++ 
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/store/migration/hibernate/R4359XWIKI1459Migrator.java
      2008-02-05 23:08:39 UTC (rev 7303)
@@ -82,7 +82,13 @@
                     Statement stmt = session.connection().createStatement();
                     ResultSet rs;
                     try {
-                        rs = stmt.executeQuery("select XWD_ID, XWD_ARCHIVE, 
XWD_FULLNAME from xwikidoc where XWD_ARCHIVE is not null order by XWD_VERSION");
+                        // We place an empty character in archives for 
documents that have already been migrated so
+                        // that we can re-execute this migrator and not start 
over.
+                        // Note that we cannot use NULL since in old databases 
(prior to 1.1) the XWD_ARCHIVE column
+                        // had a not null constraint and since this column has 
disappeared in 1.2 and after, the
+                        // hibernate update script will not have modified the 
nullability of it...
+                        // (see http://jira.xwiki.org/jira/browse/XWIKI-2074).
+                        rs = stmt.executeQuery("select XWD_ID, XWD_ARCHIVE, 
XWD_FULLNAME from xwikidoc where (XWD_ARCHIVE is not null and XWD_ARCHIVE <> ' 
') order by XWD_VERSION");
                     } catch (SQLException e) {
                         // most likely there is no XWD_ARCHIVE column, so 
migration is not needed
                         // is there easier way to find what column is not 
exist?
@@ -91,7 +97,7 @@
                     Transaction originalTransaction = 
((XWikiHibernateVersioningStore)context.getWiki().getVersioningStore()).getTransaction(context);
                     
((XWikiHibernateVersioningStore)context.getWiki().getVersioningStore()).setSession(null,
 context);
                     
((XWikiHibernateVersioningStore)context.getWiki().getVersioningStore()).setTransaction(null,
 context);
-                    PreparedStatement deleteStatement = 
session.connection().prepareStatement("update xwikidoc set XWD_ARCHIVE=null 
where XWD_ID=?");
+                    PreparedStatement deleteStatement = 
session.connection().prepareStatement("update xwikidoc set XWD_ARCHIVE=' ' 
where XWD_ID=?");
 
                     while (rs.next()) {
                         if (LOG.isInfoEnabled()) {

_______________________________________________
notifications mailing list
notifications@xwiki.org
http://lists.xwiki.org/mailman/listinfo/notifications

Reply via email to