[CalendarServer-changes] [8802] CalendarServer/branches/users/glyph/case-insensitive-uid

source_changes at macosforge.org source_changes at macosforge.org
Wed Feb 29 10:16:38 PST 2012


Revision: 8802
          http://trac.macosforge.org/projects/calendarserver/changeset/8802
Author:   glyph at apple.com
Date:     2012-02-29 10:16:38 -0800 (Wed, 29 Feb 2012)
Log Message:
-----------
Update everywhere that touches something == OWNER_UID to instead do Lower(something) == OWNER_UID.  Also, make notification homes case-insensitive as well.

Modified Paths:
--------------
    CalendarServer/branches/users/glyph/case-insensitive-uid/calendarserver/tools/calverify.py
    CalendarServer/branches/users/glyph/case-insensitive-uid/calendarserver/tools/dbinspect.py
    CalendarServer/branches/users/glyph/case-insensitive-uid/contrib/tools/sqldata_from_path.py
    CalendarServer/branches/users/glyph/case-insensitive-uid/txdav/common/datastore/sql.py
    CalendarServer/branches/users/glyph/case-insensitive-uid/txdav/common/datastore/sql_legacy.py
    CalendarServer/branches/users/glyph/case-insensitive-uid/txdav/common/datastore/sql_schema/current.sql
    CalendarServer/branches/users/glyph/case-insensitive-uid/txdav/common/datastore/sql_schema/upgrades/oracle-dialect/upgrade_from_8_to_9.sql
    CalendarServer/branches/users/glyph/case-insensitive-uid/txdav/common/datastore/sql_schema/upgrades/postgres-dialect/upgrade_from_8_to_9.sql
    CalendarServer/branches/users/glyph/case-insensitive-uid/txdav/common/datastore/upgrade/sql/upgrade.py

Property Changed:
----------------
    CalendarServer/branches/users/glyph/case-insensitive-uid/

Modified: CalendarServer/branches/users/glyph/case-insensitive-uid/calendarserver/tools/calverify.py
===================================================================
--- CalendarServer/branches/users/glyph/case-insensitive-uid/calendarserver/tools/calverify.py	2012-02-29 18:16:31 UTC (rev 8801)
+++ CalendarServer/branches/users/glyph/case-insensitive-uid/calendarserver/tools/calverify.py	2012-02-29 18:16:38 UTC (rev 8802)
@@ -62,6 +62,7 @@
 import os
 import sys
 import time
+from twext.enterprise.dal.syntax import Lower
 
 def usage(e=None):
     if e:
@@ -266,7 +267,7 @@
                 cb, type="inner", on=(ch.RESOURCE_ID == cb.CALENDAR_HOME_RESOURCE_ID).And(
                     cb.BIND_MODE == _BIND_MODE_OWN)).join(
                 co, type="inner", on=(cb.CALENDAR_RESOURCE_ID == co.CALENDAR_RESOURCE_ID)),
-            Where=(ch.OWNER_UID == Parameter("UID"))
+            Where=(ch.OWNER_UID == Lower(Parameter("UID")))
         ).on(self.txn, **kwds))
         returnValue(int(rows[0][0]) if rows else 0)
 
@@ -339,7 +340,7 @@
                 cb, type="inner", on=(ch.RESOURCE_ID == cb.CALENDAR_HOME_RESOURCE_ID)).join(
                 co, type="inner", on=(cb.CALENDAR_RESOURCE_ID == co.CALENDAR_RESOURCE_ID).And(
                     cb.BIND_MODE == _BIND_MODE_OWN).And(
-                    cb.CALENDAR_RESOURCE_NAME != "inbox")),
+                    cb.CALENDAR_RESOURCE_NAME != Lower("inbox"))),
             GroupBy=(ch.OWNER_UID, co.RESOURCE_ID, co.ICALENDAR_UID, co.MD5, co.ORGANIZER,),
         ).on(self.txn, **kwds))
         returnValue(tuple(rows))
@@ -352,9 +353,9 @@
         ch = schema.CALENDAR_HOME
         kwds = {"uuid": uuid}
         if len(uuid) != 36:
-            where = (ch.OWNER_UID.StartsWith(Parameter("uuid")))
+            where = (ch.OWNER_UID.StartsWith(Lower(Parameter("uuid"))))
         else:
-            where = (ch.OWNER_UID == Parameter("uuid"))
+            where = (ch.OWNER_UID == Lower(Parameter("uuid")))
         rows = (yield Select(
             [ch.OWNER_UID, co.RESOURCE_ID, co.ICALENDAR_UID, co.MD5, co.ORGANIZER,],
             From=ch.join(

Modified: CalendarServer/branches/users/glyph/case-insensitive-uid/calendarserver/tools/dbinspect.py
===================================================================
--- CalendarServer/branches/users/glyph/case-insensitive-uid/calendarserver/tools/dbinspect.py	2012-02-29 18:16:31 UTC (rev 8801)
+++ CalendarServer/branches/users/glyph/case-insensitive-uid/calendarserver/tools/dbinspect.py	2012-02-29 18:16:38 UTC (rev 8802)
@@ -43,6 +43,7 @@
 import os
 import sys
 import traceback
+from twext.enterprise.dal.syntax import Lower
 
 def usage(e=None):
     if e:
@@ -520,7 +521,7 @@
                 cb, type="inner", on=(ch.RESOURCE_ID == cb.CALENDAR_HOME_RESOURCE_ID).And(
                     cb.BIND_MODE == _BIND_MODE_OWN)).join(
                 co, type="inner", on=(cb.CALENDAR_RESOURCE_ID == co.CALENDAR_RESOURCE_ID)),
-            Where=(ch.OWNER_UID == Parameter("UID")),
+            Where=(ch.OWNER_UID == Lower(Parameter("UID"))),
         ).on(txn, **{"UID": uid}))
         returnValue(tuple(rows))
 
@@ -571,7 +572,7 @@
                 cb, type="inner", on=(ch.RESOURCE_ID == cb.CALENDAR_HOME_RESOURCE_ID).And(
                     cb.BIND_MODE == _BIND_MODE_OWN)).join(
                 co, type="inner", on=(cb.CALENDAR_RESOURCE_ID == co.CALENDAR_RESOURCE_ID)),
-            Where=((ch.OWNER_UID == Parameter("UID")).And(cb.CALENDAR_RESOURCE_NAME == Parameter("NAME"))),
+            Where=((ch.OWNER_UID == Lower(Parameter("UID"))).And(cb.CALENDAR_RESOURCE_NAME == Parameter("NAME"))),
         ).on(txn, **{"UID": uid, "NAME": name}))
         returnValue(tuple(rows))
 

Modified: CalendarServer/branches/users/glyph/case-insensitive-uid/contrib/tools/sqldata_from_path.py
===================================================================
--- CalendarServer/branches/users/glyph/case-insensitive-uid/contrib/tools/sqldata_from_path.py	2012-02-29 18:16:31 UTC (rev 8801)
+++ CalendarServer/branches/users/glyph/case-insensitive-uid/contrib/tools/sqldata_from_path.py	2012-02-29 18:16:38 UTC (rev 8802)
@@ -109,7 +109,7 @@
     %(object_name)s = '%(resource)s' and %(object_bind_id)s = (
         select %(bind_id)s from %(bind_table)s where
             %(bind_name)s = '%(collection)s' and %(bind_home_id)s = (
-                select RESOURCE_ID from %(home_table)s where OWNER_UID = '%(uid)s'
+                select RESOURCE_ID from %(home_table)s where OWNER_UID = lower('%(uid)s')
             )
     );""" % sqlstrings[datatype]
     

Modified: CalendarServer/branches/users/glyph/case-insensitive-uid/txdav/common/datastore/sql.py
===================================================================
--- CalendarServer/branches/users/glyph/case-insensitive-uid/txdav/common/datastore/sql.py	2012-02-29 18:16:31 UTC (rev 8801)
+++ CalendarServer/branches/users/glyph/case-insensitive-uid/txdav/common/datastore/sql.py	2012-02-29 18:16:38 UTC (rev 8802)
@@ -71,6 +71,7 @@
 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 Lower
 
 from txdav.base.propertystore.base import PropertyName
 from txdav.base.propertystore.none import PropertyStore as NonePropertyStore
@@ -842,7 +843,7 @@
     def _resourceIDFromOwnerQuery(cls): #@NoSelf
         home = cls._homeSchema
         return Select([home.RESOURCE_ID],
-                      From=home, Where=home.OWNER_UID == Parameter("ownerUID"))
+                      From=home, Where=home.OWNER_UID == Lower(Parameter("ownerUID")))
 
     @classproperty
     def _ownerFromFromResourceID(cls): #@NoSelf
@@ -909,7 +910,7 @@
             try:
                 resourceid = (yield Insert(
                     {
-                        cls._homeSchema.OWNER_UID: uid,
+                        cls._homeSchema.OWNER_UID: Lower(uid),
                         cls._homeSchema.DATAVERSION: cls._dataVersionValue,
                     },
                     Return=cls._homeSchema.RESOURCE_ID).on(txn))[0][0]
@@ -3008,11 +3009,11 @@
 
     _resourceIDFromUIDQuery = Select(
         [_homeSchema.RESOURCE_ID], From=_homeSchema,
-        Where=_homeSchema.OWNER_UID == Parameter("uid"))
+        Where=_homeSchema.OWNER_UID == Lower(Parameter("uid")))
 
 
     _provisionNewNotificationsQuery = Insert(
-        {_homeSchema.OWNER_UID: Parameter("uid")},
+        {_homeSchema.OWNER_UID: Lower(Parameter("uid"))},
         Return=_homeSchema.RESOURCE_ID
     )
 

Modified: CalendarServer/branches/users/glyph/case-insensitive-uid/txdav/common/datastore/sql_legacy.py
===================================================================
--- CalendarServer/branches/users/glyph/case-insensitive-uid/txdav/common/datastore/sql_legacy.py	2012-02-29 18:16:31 UTC (rev 8801)
+++ CalendarServer/branches/users/glyph/case-insensitive-uid/txdav/common/datastore/sql_legacy.py	2012-02-29 18:16:38 UTC (rev 8802)
@@ -56,6 +56,7 @@
 
 
 from pycalendar.duration import PyCalendarDuration
+from twext.enterprise.dal.syntax import Lower
 
 log = Logger()
 
@@ -220,7 +221,8 @@
         inv = schema.INVITE
         home = cls._homeSchema
         return cls._allColumnsQuery(
-            (inv.RESOURCE_ID == Parameter("resourceID")).And(home.OWNER_UID == Parameter("principalUID"))
+            (inv.RESOURCE_ID == Parameter("resourceID"))
+            .And(home.OWNER_UID == Lower(Parameter("principalUID")))
         )
 
 

Modified: CalendarServer/branches/users/glyph/case-insensitive-uid/txdav/common/datastore/sql_schema/current.sql
===================================================================
--- CalendarServer/branches/users/glyph/case-insensitive-uid/txdav/common/datastore/sql_schema/current.sql	2012-02-29 18:16:31 UTC (rev 8801)
+++ CalendarServer/branches/users/glyph/case-insensitive-uid/txdav/common/datastore/sql_schema/current.sql	2012-02-29 18:16:38 UTC (rev 8802)
@@ -90,7 +90,8 @@
 
 create table NOTIFICATION_HOME (
   RESOURCE_ID integer      primary key default nextval('RESOURCE_ID_SEQ'), -- implicit index
-  OWNER_UID   varchar(255) not null unique                                 -- implicit index
+  OWNER_UID   varchar(255) not null unique,                                -- implicit index
+  constraint NOTIFICATION_HOME_CASE check(OWNER_UID = lower(OWNER_UID))
 );
 
 create table NOTIFICATION (

Modified: CalendarServer/branches/users/glyph/case-insensitive-uid/txdav/common/datastore/sql_schema/upgrades/oracle-dialect/upgrade_from_8_to_9.sql
===================================================================
--- CalendarServer/branches/users/glyph/case-insensitive-uid/txdav/common/datastore/sql_schema/upgrades/oracle-dialect/upgrade_from_8_to_9.sql	2012-02-29 18:16:31 UTC (rev 8801)
+++ CalendarServer/branches/users/glyph/case-insensitive-uid/txdav/common/datastore/sql_schema/upgrades/oracle-dialect/upgrade_from_8_to_9.sql	2012-02-29 18:16:38 UTC (rev 8802)
@@ -27,3 +27,8 @@
 
 alter table ADDRESSBOOK_HOME
 add constraint ADDRESSBOOK_HOME_CASE check(OWNER_UID = lower(OWNER_UID));
+
+update NOTIFICATION_HOME set OWNER_UID = lower(OWNER_UID);
+
+alter table NOTIFICATION_HOME
+add constraint NOTIFICATION_HOME_CASE check(OWNER_UID = lower(OWNER_UID));

Modified: CalendarServer/branches/users/glyph/case-insensitive-uid/txdav/common/datastore/sql_schema/upgrades/postgres-dialect/upgrade_from_8_to_9.sql
===================================================================
--- CalendarServer/branches/users/glyph/case-insensitive-uid/txdav/common/datastore/sql_schema/upgrades/postgres-dialect/upgrade_from_8_to_9.sql	2012-02-29 18:16:31 UTC (rev 8801)
+++ CalendarServer/branches/users/glyph/case-insensitive-uid/txdav/common/datastore/sql_schema/upgrades/postgres-dialect/upgrade_from_8_to_9.sql	2012-02-29 18:16:38 UTC (rev 8802)
@@ -27,3 +27,8 @@
 
 alter table ADDRESSBOOK_HOME
 add constraint ADDRESSBOOK_HOME_CASE check(OWNER_UID = lower(OWNER_UID));
+
+update NOTIFICATION_HOME set OWNER_UID = lower(OWNER_UID);
+
+alter table NOTIFICATION_HOME
+add constraint NOTIFICATION_HOME_CASE check(OWNER_UID = lower(OWNER_UID));

Modified: CalendarServer/branches/users/glyph/case-insensitive-uid/txdav/common/datastore/upgrade/sql/upgrade.py
===================================================================
--- CalendarServer/branches/users/glyph/case-insensitive-uid/txdav/common/datastore/upgrade/sql/upgrade.py	2012-02-29 18:16:31 UTC (rev 8801)
+++ CalendarServer/branches/users/glyph/case-insensitive-uid/txdav/common/datastore/upgrade/sql/upgrade.py	2012-02-29 18:16:38 UTC (rev 8802)
@@ -322,6 +322,7 @@
                 # that differ only by case and re-name one of them to 'x.old'.
                 yield self.renameCaseDuplicates(sqlTxn, 'CALENDAR')
                 yield self.renameCaseDuplicates(sqlTxn, 'ADDRESSBOOK')
+                yield self.renameCaseDuplicates(sqlTxn, 'NOTIFICATION')
             yield sqlTxn.execSQLBlock(sql)
             if caseFix:
                 # This does not fit neatly into the existing upgrade machinery,
@@ -329,7 +330,7 @@
                 # upgrade system could take something like this into account,
                 # though.
                 yield self.mergeCaseDuplicates(sqlTxn, 'CALENDAR')
-                yield self.mergeCaseDuplicates(sqlTxn, 'ADDRESSBOOK')
+                # yield self.mergeCaseDuplicates(sqlTxn, 'ADDRESSBOOK')
             yield sqlTxn.commit()
         except RuntimeError:
             yield sqlTxn.abort()
@@ -341,15 +342,17 @@
         """
         Re-name case duplicates.
 
-        Prior to schema version 9, home UIDs were case-sensitive.
+        Prior to schema version 9, home UIDs were case-sensitive.  This method
+        re-names any names which are equivalent except for case differences, so
+        that adding the uniform-case constraint will succeed.
 
         @param type: The type of home to scan; 'CALENDAR' or 'ADDRESSBOOK'
         @type type: C{str}
         """
-        # This is using the most recent 'schema' object, which happens to work for
-        # the moment, but will fail if the schema changes too radically.  Ideally
-        # this should be pointed at a schema object parsed from an older version of
-        # the schema.
+        # This is using the most recent 'schema' object, which happens to work
+        # for the moment, but will fail if the schema changes too radically.
+        # Ideally this should be pointed at a schema object parsed from an older
+        # version of the schema.
         home = getattr(schema, type + '_HOME')
         left = home.alias()
         right = home.alias()
@@ -368,6 +371,7 @@
             both.sort(key=lambda x: x[1])
             # Note: determineNewest may return None sometimes.
             older = both[0][0]
+            self.log_warn("Moving aside case-duplicate home " + repr(older))
             yield Update({home.OWNER_UID: _CASE_DUPLICATE_PREFIX + older},
                          Where=home.OWNER_UID == older).on(sqlTxn)
 
@@ -375,8 +379,8 @@
     @inlineCallbacks
     def mergeCaseDuplicates(self, sqlTxn, type):
         """
-        Merge together homes which were previously case-duplicates of each other,
-        once the schema is upgraded.
+        Merge together homes which were previously case-duplicates of each
+        other, once the schema is upgraded.
         """
         home = getattr(schema, type + '_HOME')
         oldHomes = yield Select(
@@ -414,6 +418,15 @@
     @param type: The type of home to scan; 'CALENDAR' or 'ADDRESSBOOK'
     @type type: C{str}
     """
+    if type == 'NOTIFICATION':
+        return Select(
+            [Max(schema.NOTIFICATION.MODIFIED)],
+            From=schema.NOTIFICATION_HOME.join(
+                schema.NOTIFICATION,
+                on=schema.NOTIFICATION_HOME.RESOURCE_ID ==
+                    schema.NOTIFICATION.NOTIFICATION_HOME_RESOURCE_ID),
+            Where=schema.NOTIFICATION_HOME.OWNER_UID == uid
+        )
     home = getattr(schema, type + "_HOME")
     bind = getattr(schema, type + "_BIND")
     child = getattr(schema, type)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20120229/4d051e95/attachment-0001.html>


More information about the calendarserver-changes mailing list