[CalendarServer-changes] [9291] CalendarServer/branches/users/glyph/uuid-normalize/txdav/common/ datastore

source_changes at macosforge.org source_changes at macosforge.org
Thu May 24 13:34:24 PDT 2012


Revision: 9291
          http://trac.macosforge.org/projects/calendarserver/changeset/9291
Author:   glyph at apple.com
Date:     2012-05-24 13:34:24 -0700 (Thu, 24 May 2012)
Log Message:
-----------
Skip the upgrade if it's immediately obvious you can do so.

Modified Paths:
--------------
    CalendarServer/branches/users/glyph/uuid-normalize/txdav/common/datastore/sql.py
    CalendarServer/branches/users/glyph/uuid-normalize/txdav/common/datastore/upgrade/sql/upgrades/upgrade_from_2_to_3.py

Modified: CalendarServer/branches/users/glyph/uuid-normalize/txdav/common/datastore/sql.py
===================================================================
--- CalendarServer/branches/users/glyph/uuid-normalize/txdav/common/datastore/sql.py	2012-05-24 20:34:21 UTC (rev 9290)
+++ CalendarServer/branches/users/glyph/uuid-normalize/txdav/common/datastore/sql.py	2012-05-24 20:34:24 UTC (rev 9291)
@@ -67,15 +67,11 @@
 from twext.python.clsprop import classproperty
 from twext.enterprise.ienterprise import AlreadyFinishedError
 from twext.enterprise.dal.parseschema import significant
-from twext.enterprise.dal.syntax import Delete, utcNowSQL, Union
-from twext.enterprise.dal.syntax import Insert
-from twext.enterprise.dal.syntax import Len
-from twext.enterprise.dal.syntax import Max
-from twext.enterprise.dal.syntax import Parameter
-from twext.enterprise.dal.syntax import SavepointAction
-from twext.enterprise.dal.syntax import Select
-from twext.enterprise.dal.syntax import Update
 
+from twext.enterprise.dal.syntax import \
+    Delete, utcNowSQL, Union, Insert, Len, Max, Parameter, SavepointAction, \
+    Select, Update, ColumnSyntax, TableSyntax, Upper
+
 from txdav.base.propertystore.base import PropertyName
 from txdav.base.propertystore.none import PropertyStore as NonePropertyStore
 from txdav.base.propertystore.sql import PropertyStore
@@ -87,8 +83,6 @@
 from txdav.xml.rfc2518 import DisplayName
 
 from txdav.base.datastore.util import normalizeUUIDOrNot
-from twext.enterprise.dal.syntax import ColumnSyntax
-from twext.enterprise.dal.syntax import TableSyntax
 
 from cStringIO import StringIO
 from sqlparse import parse
@@ -4205,11 +4199,27 @@
 
 
 @inlineCallbacks
-def fixCaseNormalization(store):
+def fixUUIDNormalization(store):
     """
-    Fix all case normalization for a given store.
+    Fix all UUIDs in the given SQL store to be in a canonical form;
+    00000000-0000-0000-0000-000000000000 format and upper-case.
     """
     t = store.newTransaction(disableCache=True)
+
+    # First, let's see if there are any calendar or addressbook homes that have
+    # a lower-case OWNER_UID.  If there are none, then we can early-out and
+    # avoid the tedious and potentially expensive inspection of oodles of
+    # calendar data.
+    for x in [schema.CALENDAR_HOME, schema.ADDRESSBOOK_HOME]:
+        slct = Select([x.OWNER_UID], From=x,
+                      Where=x.OWNER_UID != Upper(x.OWNER_UID))
+        rows = yield slct.on(t)
+        if rows:
+            break
+    else:
+        log.msg("No potentially denormalized UUIDs detected, "
+                "skipping normalization upgrade.")
+        returnValue(None)
     try:
         yield _normalizeHomeUUIDsIn(t, ECALENDARTYPE)
         yield _normalizeHomeUUIDsIn(t, EADDRESSBOOKTYPE)

Modified: CalendarServer/branches/users/glyph/uuid-normalize/txdav/common/datastore/upgrade/sql/upgrades/upgrade_from_2_to_3.py
===================================================================
--- CalendarServer/branches/users/glyph/uuid-normalize/txdav/common/datastore/upgrade/sql/upgrades/upgrade_from_2_to_3.py	2012-05-24 20:34:21 UTC (rev 9290)
+++ CalendarServer/branches/users/glyph/uuid-normalize/txdav/common/datastore/upgrade/sql/upgrades/upgrade_from_2_to_3.py	2012-05-24 20:34:24 UTC (rev 9291)
@@ -21,7 +21,7 @@
 as in calendar data and properties.
 """
 
-from txdav.common.datastore.sql import fixCaseNormalization
+from txdav.common.datastore.sql import fixUUIDNormalization
 from twisted.internet.defer import inlineCallbacks
 from txdav.common.datastore.upgrade.sql.upgrades.util import updateDataVersion
 
@@ -30,10 +30,10 @@
 @inlineCallbacks
 def doUpgrade(sqlStore):
     """
-    Do the case-normalization upgrade if necessary and then bump the data
+    Do the UUID-normalization upgrade if necessary and then bump the data
     version to indicate that it's been done.
     """
-    yield fixCaseNormalization(sqlStore)
+    yield fixUUIDNormalization(sqlStore)
 
     # Always bump the DB value
     yield updateDataVersion(
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20120524/be2fbb6b/attachment-0001.html>


More information about the calendarserver-changes mailing list