[CalendarServer-changes] [9327] CalendarServer/trunk

source_changes at macosforge.org source_changes at macosforge.org
Mon Jun 4 15:14:46 PDT 2012


Revision: 9327
          http://trac.macosforge.org/projects/calendarserver/changeset/9327
Author:   glyph at apple.com
Date:     2012-06-04 15:14:45 -0700 (Mon, 04 Jun 2012)
Log Message:
-----------
Don't bump the schema version for the proxies database; instead, use a specific key to note whether this specific data tweak has been done.

Modified Paths:
--------------
    CalendarServer/trunk/twistedcaldav/directory/calendaruserproxy.py

Property Changed:
----------------
    CalendarServer/trunk/

Modified: CalendarServer/trunk/twistedcaldav/directory/calendaruserproxy.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/calendaruserproxy.py	2012-06-04 22:14:45 UTC (rev 9326)
+++ CalendarServer/trunk/twistedcaldav/directory/calendaruserproxy.py	2012-06-04 22:14:45 UTC (rev 9327)
@@ -416,7 +416,7 @@
 
     """
 
-    schema_version = "5"
+    schema_version = "4"
     schema_type    = "CALENDARUSERPROXY"
 
     class ProxyDBMemcacher(Memcacher):
@@ -777,6 +777,44 @@
 
 
     @inlineCallbacks
+    def open(self):
+        """
+        Open the database, normalizing all UUIDs in the process if necessary.
+        """
+        result = yield super(ProxyDB, self).open()
+        yield self._maybeNormalizeUUIDs()
+        returnValue(result)
+
+
+    @inlineCallbacks
+    def _maybeNormalizeUUIDs(self):
+        alreadyDone = yield self._db_value_for_sql(
+            "select VALUE from CALDAV where KEY = 'UUIDS_NORMALIZED'"
+        )
+        if alreadyDone is None:
+            for (groupname, member) in (
+                    (yield self._db_all_values_for_sql(
+                        "select GROUPNAME, MEMBER from GROUPS"))
+                ):
+                grouplist = groupname.split("#")
+                grouplist[0] = normalizeUUID(grouplist[0])
+                newGroupName = "#".join(grouplist)
+                newMemberName = normalizeUUID(member)
+                if newGroupName != groupname or newMemberName != member:
+                    yield self._db_execute("""
+                        update GROUPS set GROUPNAME = :1, MEMBER = :2
+                        where GROUPNAME = :3 and MEMBER = :4
+                    """, [newGroupName, newMemberName,
+                          groupname, member])
+            yield self._db_execute(
+                """
+                insert or ignore into CALDAV (KEY, VALUE)
+                values ('UUIDS_NORMALIZED', 'YES')
+                """
+            )
+
+
+    @inlineCallbacks
     def _db_upgrade_data_tables(self, old_version):
         """
         Upgrade the data from an older version of the DB.
@@ -799,20 +837,7 @@
                 ifnotexists=True,
             )
 
-        if int(old_version) < 5:
-            for (groupname, member) in (
-                    (yield self._db_all_values_for_sql(
-                        "select GROUPNAME, MEMBER from GROUPS"))
-                ):
-                grouplist = groupname.split("#")
-                grouplist[0] = normalizeUUID(grouplist[0])
-                yield self._db_execute("""
-                    update GROUPS set GROUPNAME = :1, MEMBER = :2
-                    where GROUPNAME = :3 and MEMBER = :4
-                """, ["#".join(grouplist), normalizeUUID(member),
-                      groupname, member])
 
-
     def _db_empty_data_tables(self):
         """
         Empty the underlying database tables.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20120604/17034241/attachment.html>


More information about the calendarserver-changes mailing list