<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[14247] CalendarServer/trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.calendarserver.org//changeset/14247">14247</a></dd>
<dt>Author</dt> <dd>cdaboo@apple.com</dd>
<dt>Date</dt> <dd>2015-01-06 08:44:21 -0800 (Tue, 06 Jan 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>Fix for sequence handling to cope with async iTIP messaging race conditions.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServertrunkcalendarservertaputilpy">CalendarServer/trunk/calendarserver/tap/util.py</a></li>
<li><a href="#CalendarServertrunkcalendarservertoolscalverifypy">CalendarServer/trunk/calendarserver/tools/calverify.py</a></li>
<li><a href="#CalendarServertrunkcalendarservertoolspurgepy">CalendarServer/trunk/calendarserver/tools/purge.py</a></li>
<li><a href="#CalendarServertrunkrequirementsstabletxt">CalendarServer/trunk/requirements-stable.txt</a></li>
<li><a href="#CalendarServertrunktwistedcaldavdatafiltershiddeninstancepy">CalendarServer/trunk/twistedcaldav/datafilters/hiddeninstance.py</a></li>
<li><a href="#CalendarServertrunktwistedcaldavicalpy">CalendarServer/trunk/twistedcaldav/ical.py</a></li>
<li><a href="#CalendarServertrunktxdavcaldavdatastoreschedulingicaldiffpy">CalendarServer/trunk/txdav/caldav/datastore/scheduling/icaldiff.py</a></li>
<li><a href="#CalendarServertrunktxdavcaldavdatastoreschedulingimplicitpy">CalendarServer/trunk/txdav/caldav/datastore/scheduling/implicit.py</a></li>
<li><a href="#CalendarServertrunktxdavcaldavdatastoreschedulingitippy">CalendarServer/trunk/txdav/caldav/datastore/scheduling/itip.py</a></li>
<li><a href="#CalendarServertrunktxdavcaldavdatastoreschedulingprocessingpy">CalendarServer/trunk/txdav/caldav/datastore/scheduling/processing.py</a></li>
<li><a href="#CalendarServertrunktxdavcaldavdatastoreschedulingtesttest_icaldiffpy">CalendarServer/trunk/txdav/caldav/datastore/scheduling/test/test_icaldiff.py</a></li>
<li><a href="#CalendarServertrunktxdavcaldavdatastoreschedulingtesttest_itippy">CalendarServer/trunk/txdav/caldav/datastore/scheduling/test/test_itip.py</a></li>
<li><a href="#CalendarServertrunktxdavcaldavdatastoreschedulingtesttest_workpy">CalendarServer/trunk/txdav/caldav/datastore/scheduling/test/test_work.py</a></li>
<li><a href="#CalendarServertrunktxdavcaldavdatastoreschedulingworkpy">CalendarServer/trunk/txdav/caldav/datastore/scheduling/work.py</a></li>
<li><a href="#CalendarServertrunktxdavcommondatastoresql_dumppy">CalendarServer/trunk/txdav/common/datastore/sql_dump.py</a></li>
<li><a href="#CalendarServertrunktxdavcommondatastoresql_schemacurrentoracledialectsql">CalendarServer/trunk/txdav/common/datastore/sql_schema/current-oracle-dialect.sql</a></li>
<li><a href="#CalendarServertrunktxdavcommondatastoresql_schemacurrentsql">CalendarServer/trunk/txdav/common/datastore/sql_schema/current.sql</a></li>
<li><a href="#CalendarServertrunktxdavcommondatastoretesttest_sql_schema_filespy">CalendarServer/trunk/txdav/common/datastore/test/test_sql_schema_files.py</a></li>
<li><a href="#CalendarServertrunktxdavcommondatastoreupgradesqltesttest_upgradepy">CalendarServer/trunk/txdav/common/datastore/upgrade/sql/test/test_upgrade.py</a></li>
<li><a href="#CalendarServertrunktxdavwhocachepy">CalendarServer/trunk/txdav/who/cache.py</a></li>
<li><a href="#CalendarServertrunktxdavwhotesttest_group_attendeespy">CalendarServer/trunk/txdav/who/test/test_group_attendees.py</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#CalendarServertrunktxdavcommondatastoresql_schemaoldoracledialectv49sql">CalendarServer/trunk/txdav/common/datastore/sql_schema/old/oracle-dialect/v49.sql</a></li>
<li><a href="#CalendarServertrunktxdavcommondatastoresql_schemaoldpostgresdialectv49sql">CalendarServer/trunk/txdav/common/datastore/sql_schema/old/postgres-dialect/v49.sql</a></li>
<li><a href="#CalendarServertrunktxdavcommondatastoresql_schemaupgradesoracledialectupgrade_from_49_to_50sql">CalendarServer/trunk/txdav/common/datastore/sql_schema/upgrades/oracle-dialect/upgrade_from_49_to_50.sql</a></li>
<li><a href="#CalendarServertrunktxdavcommondatastoresql_schemaupgradespostgresdialectupgrade_from_49_to_50sql">CalendarServer/trunk/txdav/common/datastore/sql_schema/upgrades/postgres-dialect/upgrade_from_49_to_50.sql</a></li>
<li><a href="#CalendarServertrunktxdavcommondatastoretesttest_sql_dumppy">CalendarServer/trunk/txdav/common/datastore/test/test_sql_dump.py</a></li>
<li><a href="#CalendarServertrunktxdavcommondatastoreupgradesqltesttest_upgrade_with_datapy">CalendarServer/trunk/txdav/common/datastore/upgrade/sql/test/test_upgrade_with_data.py</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServertrunkcalendarservertaputilpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/calendarserver/tap/util.py (14246 => 14247)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/calendarserver/tap/util.py        2015-01-06 16:42:48 UTC (rev 14246)
+++ CalendarServer/trunk/calendarserver/tap/util.py        2015-01-06 16:44:21 UTC (rev 14247)
</span><span class="lines">@@ -580,8 +580,8 @@
</span><span class="cx">         )
</span><span class="cx">         root.putChild(&quot;.well-known&quot;, wellKnownResource)
</span><span class="cx">         for enabled, wellknown_name, redirected_to in (
</span><del>-            (config.EnableCalDAV, &quot;caldav&quot;, &quot;/&quot;,),
-            (config.EnableCardDAV, &quot;carddav&quot;, &quot;/&quot;,),
</del><ins>+            (config.EnableCalDAV, &quot;caldav&quot;, &quot;/principals&quot;,),
+            (config.EnableCardDAV, &quot;carddav&quot;, &quot;/principals&quot;,),
</ins><span class="cx">             (config.TimezoneService.Enabled, &quot;timezone&quot;, &quot;/stdtimezones&quot;,),
</span><span class="cx">             (config.Scheduling.iSchedule.Enabled, &quot;ischedule&quot;, &quot;/ischedule&quot;),
</span><span class="cx">         ):
</span></span></pre></div>
<a id="CalendarServertrunkcalendarservertoolscalverifypy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/calendarserver/tools/calverify.py (14246 => 14247)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/calendarserver/tools/calverify.py        2015-01-06 16:42:48 UTC (rev 14246)
+++ CalendarServer/trunk/calendarserver/tools/calverify.py        2015-01-06 16:44:21 UTC (rev 14247)
</span><span class="lines">@@ -61,10 +61,7 @@
</span><span class="cx"> from twisted.python.usage import Options
</span><span class="cx"> from twistedcaldav.datafilters.peruserdata import PerUserDataFilter
</span><span class="cx"> from twistedcaldav.dateops import pyCalendarTodatetime
</span><del>-from twistedcaldav.ical import (
-    Component, ignoredComponents,
-    InvalidICalendarDataError, Property, PERUSER_COMPONENT
-)
</del><ins>+from twistedcaldav.ical import Component, InvalidICalendarDataError, Property, PERUSER_COMPONENT
</ins><span class="cx"> from twistedcaldav.stdconfig import DEFAULT_CONFIG_FILE
</span><span class="cx"> from twistedcaldav.timezones import TimezoneCache
</span><span class="cx"> from txdav.caldav.datastore.scheduling.icalsplitter import iCalSplitter
</span><span class="lines">@@ -1166,9 +1163,7 @@
</span><span class="cx">             self.cuaCache[cuaddr] = result
</span><span class="cx">             returnValue(result)
</span><span class="cx"> 
</span><del>-        for subcomponent in component.subcomponents():
-            if subcomponent.name() in ignoredComponents:
-                continue
</del><ins>+        for subcomponent in component.subcomponents(ignore=True):
</ins><span class="cx">             organizer = subcomponent.getProperty(&quot;ORGANIZER&quot;)
</span><span class="cx">             if organizer:
</span><span class="cx">                 cuaddr = organizer.value()
</span><span class="lines">@@ -2016,9 +2011,7 @@
</span><span class="cx">         Set the TRANSP property based on the PARTSTAT value on matching ATTENDEE properties
</span><span class="cx">         in each component.
</span><span class="cx">         &quot;&quot;&quot;
</span><del>-        for component in calendar.subcomponents():
-            if component.name() in ignoredComponents:
-                continue
</del><ins>+        for component in calendar.subcomponents(ignore=True):
</ins><span class="cx">             prop = component.getAttendeeProperty(attendee)
</span><span class="cx">             addTransp = False
</span><span class="cx">             if prop:
</span></span></pre></div>
<a id="CalendarServertrunkcalendarservertoolspurgepy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/calendarserver/tools/purge.py (14246 => 14247)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/calendarserver/tools/purge.py        2015-01-06 16:42:48 UTC (rev 14246)
+++ CalendarServer/trunk/calendarserver/tools/purge.py        2015-01-06 16:44:21 UTC (rev 14247)
</span><span class="lines">@@ -236,7 +236,6 @@
</span><span class="cx">         sow = schema.SCHEDULE_ORGANIZER_WORK
</span><span class="cx">         sosw = schema.SCHEDULE_ORGANIZER_SEND_WORK
</span><span class="cx">         srw = schema.SCHEDULE_REPLY_WORK
</span><del>-        srcw = schema.SCHEDULE_REPLY_CANCEL_WORK
</del><span class="cx">         rows = yield Select(
</span><span class="cx">             [sow.HOME_RESOURCE_ID],
</span><span class="cx">             From=sow,
</span><span class="lines">@@ -251,13 +250,6 @@
</span><span class="cx">                             [srw.HOME_RESOURCE_ID],
</span><span class="cx">                             From=srw,
</span><span class="cx">                             Where=(srw.HOME_RESOURCE_ID == self.homeResourceID),
</span><del>-                            SetExpression=Union(
-                                Select(
-                                    [srcw.HOME_RESOURCE_ID],
-                                    From=srcw,
-                                    Where=(srcw.HOME_RESOURCE_ID == self.homeResourceID),
-                                )
-                            ),
</del><span class="cx">                         )
</span><span class="cx">                     ),
</span><span class="cx">                 )
</span></span></pre></div>
<a id="CalendarServertrunkrequirementsstabletxt"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/requirements-stable.txt (14246 => 14247)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/requirements-stable.txt        2015-01-06 16:42:48 UTC (rev 14246)
+++ CalendarServer/trunk/requirements-stable.txt        2015-01-06 16:44:21 UTC (rev 14247)
</span><span class="lines">@@ -5,9 +5,9 @@
</span><span class="cx"> # For CalendarServer development, don't try to get these projects from PyPI; use svn.
</span><span class="cx"> 
</span><span class="cx"> -e .
</span><del>--e svn+http://svn.calendarserver.org/repository/calendarserver/twext/trunk@14228#egg=twextpy
</del><ins>+-e svn+http://svn.calendarserver.org/repository/calendarserver/twext/trunk@14246#egg=twextpy
</ins><span class="cx"> -e svn+http://svn.calendarserver.org/repository/calendarserver/PyKerberos/trunk@13420#egg=kerberos
</span><del>--e svn+http://svn.calendarserver.org/repository/calendarserver/PyCalendar/trunk@14234#egg=pycalendar
</del><ins>+-e svn+http://svn.calendarserver.org/repository/calendarserver/PyCalendar/trunk@14245#egg=pycalendar
</ins><span class="cx"> 
</span><span class="cx"> # Specify specific versions of our dependencies so that we're all testing the same config.
</span><span class="cx"> 
</span></span></pre></div>
<a id="CalendarServertrunktwistedcaldavdatafiltershiddeninstancepy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/twistedcaldav/datafilters/hiddeninstance.py (14246 => 14247)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/twistedcaldav/datafilters/hiddeninstance.py        2015-01-06 16:42:48 UTC (rev 14246)
+++ CalendarServer/trunk/twistedcaldav/datafilters/hiddeninstance.py        2015-01-06 16:44:21 UTC (rev 14247)
</span><span class="lines">@@ -15,7 +15,7 @@
</span><span class="cx"> ##
</span><span class="cx"> 
</span><span class="cx"> from twistedcaldav.datafilters.filter import CalendarFilter
</span><del>-from twistedcaldav.ical import Component, ignoredComponents
</del><ins>+from twistedcaldav.ical import Component
</ins><span class="cx"> 
</span><span class="cx"> __all__ = [
</span><span class="cx">     &quot;HiddenInstanceFilter&quot;,
</span><span class="lines">@@ -38,9 +38,7 @@
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx"> 
</span><span class="cx">         master = ical.masterComponent()
</span><del>-        for component in tuple(ical.subcomponents()):
-            if component.name() in ignoredComponents:
-                continue
</del><ins>+        for component in tuple(ical.subcomponents(ignore=True)):
</ins><span class="cx">             rid = component.getRecurrenceIDUTC()
</span><span class="cx">             if rid is None:
</span><span class="cx">                 continue
</span></span></pre></div>
<a id="CalendarServertrunktwistedcaldavicalpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/twistedcaldav/ical.py (14246 => 14247)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/twistedcaldav/ical.py        2015-01-06 16:42:48 UTC (rev 14246)
+++ CalendarServer/trunk/twistedcaldav/ical.py        2015-01-06 16:44:21 UTC (rev 14247)
</span><span class="lines">@@ -712,6 +712,14 @@
</span><span class="cx">         return self._pycalendar.getType()
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    def ignored(self):
+        &quot;&quot;&quot;
+        @return: where this component is one of the L{ignoredComponents}.
+        @rtype: L{bool}
+        &quot;&quot;&quot;
+        return self.name() in ignoredComponents
+
+
</ins><span class="cx">     def mainType(self):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Determine the primary type of iCal component in this calendar.
</span><span class="lines">@@ -721,10 +729,8 @@
</span><span class="cx">         assert self.name() == &quot;VCALENDAR&quot;, &quot;Must be a VCALENDAR: {0!r}&quot;.format(self,)
</span><span class="cx"> 
</span><span class="cx">         mtype = None
</span><del>-        for component in self.subcomponents():
-            if component.name() in ignoredComponents:
-                continue
-            elif mtype and (mtype != component.name()):
</del><ins>+        for component in self.subcomponents(ignore=True):
+            if mtype and (mtype != component.name()):
</ins><span class="cx">                 raise InvalidICalendarDataError(&quot;Component contains more than one type of primary type: {0!r}&quot;.format(self,))
</span><span class="cx">             else:
</span><span class="cx">                 mtype = component.name()
</span><span class="lines">@@ -742,9 +748,7 @@
</span><span class="cx">         assert self.name() == &quot;VCALENDAR&quot;, &quot;Must be a VCALENDAR: {0!r}&quot;.format(self,)
</span><span class="cx"> 
</span><span class="cx">         result = None
</span><del>-        for component in self.subcomponents():
-            if component.name() in ignoredComponents:
-                continue
</del><ins>+        for component in self.subcomponents(ignore=True):
</ins><span class="cx">             if not component.hasProperty(&quot;RECURRENCE-ID&quot;):
</span><span class="cx">                 return component
</span><span class="cx">             elif result is None:
</span><span class="lines">@@ -761,9 +765,7 @@
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         assert self.name() == &quot;VCALENDAR&quot;, &quot;Must be a VCALENDAR: {0!r}&quot;.format(self,)
</span><span class="cx"> 
</span><del>-        for component in self.subcomponents():
-            if component.name() in ignoredComponents:
-                continue
</del><ins>+        for component in self.subcomponents(ignore=True):
</ins><span class="cx">             if not component.hasProperty(&quot;RECURRENCE-ID&quot;):
</span><span class="cx">                 return component
</span><span class="cx"> 
</span><span class="lines">@@ -785,9 +787,7 @@
</span><span class="cx">         if isinstance(recurrence_id, str):
</span><span class="cx">             recurrence_id = DateTime.parseText(recurrence_id) if recurrence_id else None
</span><span class="cx"> 
</span><del>-        for component in self.subcomponents():
-            if component.name() in ignoredComponents:
-                continue
</del><ins>+        for component in self.subcomponents(ignore=True):
</ins><span class="cx">             rid = component.getRecurrenceIDUTC()
</span><span class="cx">             if rid and recurrence_id and rid == recurrence_id:
</span><span class="cx">                 return component
</span><span class="lines">@@ -821,7 +821,7 @@
</span><span class="cx">         return result
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-    def subcomponents(self):
</del><ins>+    def subcomponents(self, ignore=False):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         @return: an iterable of L{Component} objects, one for each subcomponent
</span><span class="cx">             of this component.
</span><span class="lines">@@ -829,6 +829,7 @@
</span><span class="cx">         return (
</span><span class="cx">             Component(None, pycalendar=c, parent=self)
</span><span class="cx">             for c in self._pycalendar.getComponents()
</span><ins>+            if not ignore or (c.getType() not in ignoredComponents)
</ins><span class="cx">         )
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -895,13 +896,13 @@
</span><span class="cx">         )
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-    def propertyValue(self, name):
</del><ins>+    def propertyValue(self, name, default=None):
</ins><span class="cx">         properties = tuple(self.properties(name))
</span><span class="cx">         if len(properties) == 1:
</span><span class="cx">             return properties[0].value()
</span><span class="cx">         if len(properties) &gt; 1:
</span><span class="cx">             raise InvalidICalendarDataError(&quot;More than one {0} property in component {1!r}&quot;.format(name, self))
</span><del>-        return None
</del><ins>+        return default
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def getStartDateUTC(self):
</span><span class="lines">@@ -1269,9 +1270,7 @@
</span><span class="cx">                     master.removeProperty(property)
</span><span class="cx"> 
</span><span class="cx">         # Remove overrides in the future
</span><del>-        for component in list(self.subcomponents()):
-            if component.name() in ignoredComponents:
-                continue
</del><ins>+        for component in list(self.subcomponents(ignore=True)):
</ins><span class="cx">             c_rid = component.getRecurrenceIDUTC()
</span><span class="cx">             if c_rid is not None and c_rid &gt;= rid:
</span><span class="cx">                 self.removeComponent(component)
</span><span class="lines">@@ -1375,9 +1374,7 @@
</span><span class="cx"> 
</span><span class="cx">         # Remove overrides in the past - but do not remove any override matching
</span><span class="cx">         # the cut-off as that is still a valid override after &quot;re-basing&quot; the master.
</span><del>-        for component in list(self.subcomponents()):
-            if component.name() in ignoredComponents:
-                continue
</del><ins>+        for component in list(self.subcomponents(ignore=True)):
</ins><span class="cx">             c_rid = component.getRecurrenceIDUTC()
</span><span class="cx">             if c_rid is not None and c_rid &lt; rid:
</span><span class="cx">                 self.removeComponent(component)
</span><span class="lines">@@ -1570,9 +1567,8 @@
</span><span class="cx">         # Extract appropriate sub-component if this is a VCALENDAR
</span><span class="cx">         if self.name() == &quot;VCALENDAR&quot;:
</span><span class="cx">             result = ()
</span><del>-            for component in self.subcomponents():
-                if component.name() not in ignoredComponents:
-                    result += component.getComponentInstances()
</del><ins>+            for component in self.subcomponents(ignore=True):
+                result += component.getComponentInstances()
</ins><span class="cx">             return result
</span><span class="cx">         else:
</span><span class="cx">             rid = self.getRecurrenceIDUTC()
</span><span class="lines">@@ -1586,8 +1582,8 @@
</span><span class="cx"> 
</span><span class="cx">         # Extract appropriate sub-component if this is a VCALENDAR
</span><span class="cx">         if self.name() == &quot;VCALENDAR&quot;:
</span><del>-            for component in self.subcomponents():
-                if component.name() not in ignoredComponents and component.isRecurring():
</del><ins>+            for component in self.subcomponents(ignore=True):
+                if component.isRecurring():
</ins><span class="cx">                     return True
</span><span class="cx">         else:
</span><span class="cx">             for propname in (&quot;RRULE&quot;, &quot;RDATE&quot;, &quot;EXDATE&quot;, &quot;RECURRENCE-ID&quot;,):
</span><span class="lines">@@ -1829,10 +1825,9 @@
</span><span class="cx">         assert self.name() == &quot;VCALENDAR&quot;, &quot;Not a calendar: {0!r}&quot;.format(self,)
</span><span class="cx"> 
</span><span class="cx">         if not hasattr(self, &quot;_resource_uid&quot;):
</span><del>-            for subcomponent in self.subcomponents():
-                if subcomponent.name() not in ignoredComponents:
-                    self._resource_uid = subcomponent.propertyValue(&quot;UID&quot;)
-                    break
</del><ins>+            for subcomponent in self.subcomponents(ignore=True):
+                self._resource_uid = subcomponent.propertyValue(&quot;UID&quot;)
+                break
</ins><span class="cx">             else:
</span><span class="cx">                 self._resource_uid = None
</span><span class="cx"> 
</span><span class="lines">@@ -1866,7 +1861,7 @@
</span><span class="cx">                 name = subcomponent.name()
</span><span class="cx">                 if name == &quot;VTIMEZONE&quot;:
</span><span class="cx">                     has_timezone = True
</span><del>-                elif subcomponent.name() in ignoredComponents:
</del><ins>+                elif subcomponent.ignored():
</ins><span class="cx">                     continue
</span><span class="cx">                 else:
</span><span class="cx">                     self._resource_type = name
</span><span class="lines">@@ -2044,7 +2039,7 @@
</span><span class="cx">         for subcomponent in self.subcomponents():
</span><span class="cx">             if subcomponent.name() == &quot;VTIMEZONE&quot;:
</span><span class="cx">                 timezones.add(subcomponent.propertyValue(&quot;TZID&quot;))
</span><del>-            elif subcomponent.name() in ignoredComponents:
</del><ins>+            elif subcomponent.ignored():
</ins><span class="cx">                 continue
</span><span class="cx">             else:
</span><span class="cx">                 if ctype is None:
</span><span class="lines">@@ -2264,9 +2259,8 @@
</span><span class="cx"> 
</span><span class="cx">         # Extract appropriate sub-component if this is a VCALENDAR
</span><span class="cx">         if self.name() == &quot;VCALENDAR&quot;:
</span><del>-            for component in self.subcomponents():
-                if component.name() not in ignoredComponents:
-                    return component.getOrganizer()
</del><ins>+            for component in self.subcomponents(ignore=True):
+                return component.getOrganizer()
</ins><span class="cx">         else:
</span><span class="cx">             try:
</span><span class="cx">                 # Find the primary subcomponent
</span><span class="lines">@@ -2287,9 +2281,8 @@
</span><span class="cx">         # Extract appropriate sub-component if this is a VCALENDAR
</span><span class="cx">         if self.name() == &quot;VCALENDAR&quot;:
</span><span class="cx">             result = ()
</span><del>-            for component in self.subcomponents():
-                if component.name() not in ignoredComponents:
-                    result += component.getOrganizersByInstance()
</del><ins>+            for component in self.subcomponents(ignore=True):
+                result += component.getOrganizersByInstance()
</ins><span class="cx">             return result
</span><span class="cx">         else:
</span><span class="cx">             try:
</span><span class="lines">@@ -2312,9 +2305,8 @@
</span><span class="cx"> 
</span><span class="cx">         # Extract appropriate sub-component if this is a VCALENDAR
</span><span class="cx">         if self.name() == &quot;VCALENDAR&quot;:
</span><del>-            for component in self.subcomponents():
-                if component.name() not in ignoredComponents:
-                    return component.getOrganizerProperty()
</del><ins>+            for component in self.subcomponents(ignore=True):
+                return component.getOrganizerProperty()
</ins><span class="cx">         else:
</span><span class="cx">             try:
</span><span class="cx">                 # Find the primary subcomponent
</span><span class="lines">@@ -2346,10 +2338,7 @@
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx"> 
</span><span class="cx">         changed = False
</span><del>-        for component in tuple(self.subcomponents()):
-            if component.name() in ignoredComponents:
-                continue
-
</del><ins>+        for component in tuple(self.subcomponents(ignore=True)):
</ins><span class="cx">             organizerProp = component.getOrganizerProperty()
</span><span class="cx">             if organizerProp is not None:
</span><span class="cx">                 if organizerProp.parameterValue(&quot;SCHEDULE-AGENT&quot;, &quot;SERVER&quot;) != &quot;SERVER&quot;:
</span><span class="lines">@@ -2373,9 +2362,8 @@
</span><span class="cx"> 
</span><span class="cx">         # Extract appropriate sub-component if this is a VCALENDAR
</span><span class="cx">         if self.name() == &quot;VCALENDAR&quot;:
</span><del>-            for component in self.subcomponents():
-                if component.name() not in ignoredComponents:
-                    return component.getAttendees()
</del><ins>+            for component in self.subcomponents(ignore=True):
+                return component.getAttendees()
</ins><span class="cx">         else:
</span><span class="cx">             # Find the property values
</span><span class="cx">             return [p.value() for p in self.properties(self.recipientPropertyName())]
</span><span class="lines">@@ -2397,9 +2385,8 @@
</span><span class="cx">         # Extract appropriate sub-component if this is a VCALENDAR
</span><span class="cx">         if self.name() == &quot;VCALENDAR&quot;:
</span><span class="cx">             result = ()
</span><del>-            for component in self.subcomponents():
-                if component.name() not in ignoredComponents:
-                    result += component.getAttendeesByInstance(makeUnique, onlyScheduleAgentServer)
</del><ins>+            for component in self.subcomponents(ignore=True):
+                result += component.getAttendeesByInstance(makeUnique, onlyScheduleAgentServer)
</ins><span class="cx">             return result
</span><span class="cx">         else:
</span><span class="cx">             result = ()
</span><span class="lines">@@ -2457,11 +2444,10 @@
</span><span class="cx"> 
</span><span class="cx">         # Extract appropriate sub-component if this is a VCALENDAR
</span><span class="cx">         if self.name() == &quot;VCALENDAR&quot;:
</span><del>-            for component in self.subcomponents():
-                if component.name() not in ignoredComponents:
-                    attendee = component.getAttendeeProperty(match)
-                    if attendee is not None:
-                        return attendee
</del><ins>+            for component in self.subcomponents(ignore=True):
+                attendee = component.getAttendeeProperty(match)
+                if attendee is not None:
+                    return attendee
</ins><span class="cx">         else:
</span><span class="cx">             # Find the primary subcomponent
</span><span class="cx">             for attendee in self.properties(self.recipientPropertyName()):
</span><span class="lines">@@ -2483,11 +2469,10 @@
</span><span class="cx"> 
</span><span class="cx">         # Extract appropriate sub-component if this is a VCALENDAR
</span><span class="cx">         results = []
</span><del>-        for component in self.subcomponents():
-            if component.name() not in ignoredComponents:
-                attendee = component.getAttendeeProperty(match)
-                if attendee:
-                    results.append(attendee)
</del><ins>+        for component in self.subcomponents(ignore=True):
+            attendee = component.getAttendeeProperty(match)
+            if attendee:
+                results.append(attendee)
</ins><span class="cx"> 
</span><span class="cx">         return results
</span><span class="cx"> 
</span><span class="lines">@@ -2501,10 +2486,9 @@
</span><span class="cx"> 
</span><span class="cx">         # Extract appropriate sub-component if this is a VCALENDAR
</span><span class="cx">         if self.name() == &quot;VCALENDAR&quot;:
</span><del>-            for component in self.subcomponents():
-                if component.name() not in ignoredComponents:
-                    for attendee in component.getAllAttendeeProperties():
-                        yield attendee
</del><ins>+            for component in self.subcomponents(ignore=True):
+                for attendee in component.getAllAttendeeProperties():
+                    yield attendee
</ins><span class="cx">         else:
</span><span class="cx">             # Find the primary subcomponent
</span><span class="cx">             for attendee in self.properties(self.recipientPropertyName()):
</span><span class="lines">@@ -2528,9 +2512,8 @@
</span><span class="cx"> 
</span><span class="cx">         # Extract appropriate sub-component if this is a VCALENDAR
</span><span class="cx">         if self.name() == &quot;VCALENDAR&quot;:
</span><del>-            for component in self.subcomponents():
-                if component.name() not in ignoredComponents:
-                    return component.getMaskUID()
</del><ins>+            for component in self.subcomponents(ignore=True):
+                return component.getMaskUID()
</ins><span class="cx">         else:
</span><span class="cx">             try:
</span><span class="cx">                 # Find the primary subcomponent
</span><span class="lines">@@ -2550,9 +2533,8 @@
</span><span class="cx"> 
</span><span class="cx">         # Extract appropriate sub-component if this is a VCALENDAR
</span><span class="cx">         if self.name() == &quot;VCALENDAR&quot;:
</span><del>-            for component in self.subcomponents():
-                if component.name() not in ignoredComponents:
-                    return component.getExtendedFreeBusy()
</del><ins>+            for component in self.subcomponents(ignore=True):
+                return component.getExtendedFreeBusy()
</ins><span class="cx">         else:
</span><span class="cx">             try:
</span><span class="cx">                 # Find the primary subcomponent
</span><span class="lines">@@ -2599,9 +2581,7 @@
</span><span class="cx">         @type propvalue: C{str} or C{None}
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx"> 
</span><del>-        for component in self.subcomponents():
-            if component.name() in ignoredComponents:
-                continue
</del><ins>+        for component in self.subcomponents(ignore=True):
</ins><span class="cx">             for property in component.properties(propname):
</span><span class="cx">                 if propvalue is None or property.value() == propvalue:
</span><span class="cx">                     for paramname, paramvalue in params.items():
</span><span class="lines">@@ -2695,9 +2675,7 @@
</span><span class="cx">         @type property: L{Property}
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx"> 
</span><del>-        for component in self.subcomponents():
-            if component.name() in ignoredComponents:
-                continue
</del><ins>+        for component in self.subcomponents(ignore=True):
</ins><span class="cx">             found = component.getProperty(property.name())
</span><span class="cx">             if not found or found.value() != property.value():
</span><span class="cx">                 return False
</span><span class="lines">@@ -2713,9 +2691,7 @@
</span><span class="cx">         @type property: L{Property}
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx"> 
</span><del>-        for component in self.subcomponents():
-            if component.name() in ignoredComponents:
-                continue
</del><ins>+        for component in self.subcomponents(ignore=True):
</ins><span class="cx">             component.addProperty(property)
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -2725,9 +2701,7 @@
</span><span class="cx">         @param property: the L{Property} to replace in this component.
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx"> 
</span><del>-        for component in self.subcomponents():
-            if component.name() in ignoredComponents:
-                continue
</del><ins>+        for component in self.subcomponents(ignore=True):
</ins><span class="cx">             component.replaceProperty(property)
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -2747,9 +2721,7 @@
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx"> 
</span><span class="cx">         if self.name() == &quot;VCALENDAR&quot;:
</span><del>-            for component in self.subcomponents():
-                if component.name() in ignoredComponents:
-                    continue
</del><ins>+            for component in self.subcomponents(ignore=True):
</ins><span class="cx">                 if component.hasPropertyWithParameterMatch(propname, param_name, param_value, param_value_is_default):
</span><span class="cx">                     return True
</span><span class="cx">         else:
</span><span class="lines">@@ -2773,9 +2745,7 @@
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx"> 
</span><span class="cx">         if self.name() == &quot;VCALENDAR&quot;:
</span><del>-            for component in self.subcomponents():
-                if component.name() in ignoredComponents:
-                    continue
</del><ins>+            for component in self.subcomponents(ignore=True):
</ins><span class="cx">                 component.replaceAllPropertiesWithParameterMatch(property, param_name, param_value, param_value_is_default)
</span><span class="cx">         else:
</span><span class="cx">             for oldprop in tuple(self.properties(property.name())):
</span><span class="lines">@@ -2791,9 +2761,7 @@
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx"> 
</span><span class="cx">         if self.name() == &quot;VCALENDAR&quot;:
</span><del>-            for component in self.subcomponents():
-                if component.name() in ignoredComponents:
-                    continue
</del><ins>+            for component in self.subcomponents(ignore=True):
</ins><span class="cx">                 component.removeAllPropertiesWithParameterMatch(propname, param_name, param_value, param_value_is_default)
</span><span class="cx">         else:
</span><span class="cx">             for oldprop in tuple(self.properties(propname)):
</span><span class="lines">@@ -2816,9 +2784,7 @@
</span><span class="cx">         assert from_calendar.name() == &quot;VCALENDAR&quot;, &quot;Not a calendar: {0!r}&quot;.format(self,)
</span><span class="cx"> 
</span><span class="cx">         if self.name() == &quot;VCALENDAR&quot;:
</span><del>-            for component in self.subcomponents():
-                if component.name() in ignoredComponents:
-                    continue
</del><ins>+            for component in self.subcomponents(ignore=True):
</ins><span class="cx">                 component.transferProperties(from_calendar, properties)
</span><span class="cx">         else:
</span><span class="cx">             # Is there a matching component
</span><span class="lines">@@ -2847,9 +2813,7 @@
</span><span class="cx">         remove_components = []
</span><span class="cx">         master_component = None
</span><span class="cx">         removed_master = False
</span><del>-        for component in self.subcomponents():
-            if component.name() in ignoredComponents:
-                continue
</del><ins>+        for component in self.subcomponents(ignore=True):
</ins><span class="cx">             found_all_attendees = True
</span><span class="cx">             for attendee in attendees:
</span><span class="cx">                 foundAttendee = component.getAttendeeProperty((attendee,))
</span><span class="lines">@@ -2890,12 +2854,9 @@
</span><span class="cx">         assert self.name() == &quot;VCALENDAR&quot;, &quot;Not a calendar: {0!r}&quot;.format(self,)
</span><span class="cx"> 
</span><span class="cx">         # Remove components not in the list
</span><del>-        components = tuple(self.subcomponents())
</del><ins>+        components = tuple(self.subcomponents(ignore=True))
</ins><span class="cx">         remaining = len(components)
</span><span class="cx">         for component in components:
</span><del>-            if component.name() in ignoredComponents:
-                remaining -= 1
-                continue
</del><span class="cx">             rid = component.getRecurrenceIDUTC()
</span><span class="cx">             if rid not in rids:
</span><span class="cx">                 self.removeComponent(component)
</span><span class="lines">@@ -2911,9 +2872,7 @@
</span><span class="cx"> 
</span><span class="cx">         assert self.name() == &quot;VCALENDAR&quot;, &quot;Not a calendar: {0!r}&quot;.format(self,)
</span><span class="cx"> 
</span><del>-        for component in self.subcomponents():
-            if component.name() in ignoredComponents:
-                continue
</del><ins>+        for component in self.subcomponents(ignore=True):
</ins><span class="cx">             [component.removeProperty(p) for p in tuple(component.properties(component.recipientPropertyName())) if p.value().lower() != attendee.lower()]
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -2926,9 +2885,7 @@
</span><span class="cx"> 
</span><span class="cx">         attendees = set([attendee.lower() for attendee in attendees])
</span><span class="cx"> 
</span><del>-        for component in self.subcomponents():
-            if component.name() in ignoredComponents:
-                continue
</del><ins>+        for component in self.subcomponents(ignore=True):
</ins><span class="cx">             [component.removeProperty(p) for p in tuple(component.properties(component.recipientPropertyName())) if p.value().lower() not in attendees]
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -3008,9 +2965,7 @@
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx"> 
</span><span class="cx">         if self.name() == &quot;VCALENDAR&quot;:
</span><del>-            for component in self.subcomponents():
-                if component.name() in ignoredComponents:
-                    continue
</del><ins>+            for component in self.subcomponents(ignore=True):
</ins><span class="cx">                 component.removeAlarms()
</span><span class="cx">         else:
</span><span class="cx">             for component in tuple(self.subcomponents()):
</span><span class="lines">@@ -3051,7 +3006,7 @@
</span><span class="cx">             for component in self.subcomponents():
</span><span class="cx">                 component.filterProperties(remove, keep, do_subcomponents=False)
</span><span class="cx">         else:
</span><del>-            if self.name() in ignoredComponents:
</del><ins>+            if self.ignored():
</ins><span class="cx">                 return
</span><span class="cx"> 
</span><span class="cx">             for p in tuple(self.properties()):
</span><span class="lines">@@ -3069,24 +3024,25 @@
</span><span class="cx">                 self.removeComponent(component)
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-    def removeXProperties(self, keep_properties=(), remove_x_parameters=True, do_subcomponents=True):
</del><ins>+    def removeXProperties(self, keep_properties=(), keep_parameters={}, remove_x_parameters=True, do_subcomponents=True):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Remove all X- properties except the specified ones
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx"> 
</span><span class="cx">         if do_subcomponents and self.name() == &quot;VCALENDAR&quot;:
</span><span class="cx">             for component in self.subcomponents():
</span><del>-                component.removeXProperties(keep_properties, remove_x_parameters, do_subcomponents=False)
</del><ins>+                component.removeXProperties(keep_properties, keep_parameters, remove_x_parameters, do_subcomponents=False)
</ins><span class="cx">         else:
</span><del>-            if self.name() in ignoredComponents:
</del><ins>+            if self.ignored():
</ins><span class="cx">                 return
</span><span class="cx">             for p in tuple(self.properties()):
</span><span class="cx">                 xpname = p.name().startswith(&quot;X-&quot;)
</span><span class="cx">                 if xpname and p.name() not in keep_properties:
</span><span class="cx">                     self.removeProperty(p)
</span><span class="cx">                 elif not xpname and remove_x_parameters:
</span><ins>+                    preserve = keep_parameters.get(p.name(), set())
</ins><span class="cx">                     for paramname in p.parameterNames():
</span><del>-                        if paramname.startswith(&quot;X-&quot;):
</del><ins>+                        if paramname.startswith(&quot;X-&quot;) and paramname not in preserve:
</ins><span class="cx">                             p.removeParameter(paramname)
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -3096,9 +3052,7 @@
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx"> 
</span><span class="cx">         if self.name() == &quot;VCALENDAR&quot;:
</span><del>-            for component in self.subcomponents():
-                if component.name() in ignoredComponents:
-                    continue
</del><ins>+            for component in self.subcomponents(ignore=True):
</ins><span class="cx">                 component.removePropertyParameters(property, params)
</span><span class="cx">         else:
</span><span class="cx">             props = self.properties(property)
</span><span class="lines">@@ -3113,9 +3067,7 @@
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx"> 
</span><span class="cx">         if self.name() == &quot;VCALENDAR&quot;:
</span><del>-            for component in self.subcomponents():
-                if component.name() in ignoredComponents:
-                    continue
</del><ins>+            for component in self.subcomponents(ignore=True):
</ins><span class="cx">                 component.removePropertyParametersByValue(property, paramvalues)
</span><span class="cx">         else:
</span><span class="cx">             props = self.properties(property)
</span><span class="lines">@@ -3133,9 +3085,7 @@
</span><span class="cx">         try:
</span><span class="cx">             # Extract items from component
</span><span class="cx">             uid = self.propertyValue(&quot;UID&quot;)
</span><del>-            seq = self.propertyValue(&quot;SEQUENCE&quot;)
-            if seq:
-                seq = int(seq)
</del><ins>+            seq = self.propertyValue(&quot;SEQUENCE&quot;, 0)
</ins><span class="cx">             dtstamp = self.propertyValue(&quot;DTSTAMP&quot;)
</span><span class="cx">             rid = self.propertyValue(&quot;RECURRENCE-ID&quot;)
</span><span class="cx"> 
</span><span class="lines">@@ -3181,14 +3131,9 @@
</span><span class="cx">         assert uid1 == uid2
</span><span class="cx"> 
</span><span class="cx">         # Look for sequence
</span><del>-        if (seq1 is not None) and (seq2 is not None):
-            if seq1 &gt; seq2:
-                return 1
-            if seq1 &lt; seq2:
-                return -1
-        elif (seq1 is not None) and (seq2 is None):
</del><ins>+        if seq1 &gt; seq2:
</ins><span class="cx">             return 1
</span><del>-        elif (seq1 is None) and (seq2 is not None):
</del><ins>+        if seq1 &lt; seq2:
</ins><span class="cx">             return -1
</span><span class="cx"> 
</span><span class="cx">         # Look for DTSTAMP
</span><span class="lines">@@ -3212,20 +3157,14 @@
</span><span class="cx">         that is always greater than the old.
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx"> 
</span><del>-        for component in self.subcomponents():
-            if component.name() in ignoredComponents:
-                continue
</del><ins>+        for component in self.subcomponents(ignore=True):
</ins><span class="cx">             oldcomponent = oldcalendar.overriddenComponent(component.getRecurrenceIDUTC())
</span><span class="cx">             if oldcomponent is None:
</span><span class="cx">                 oldcomponent = oldcalendar.masterComponent()
</span><span class="cx">                 if oldcomponent is None:
</span><span class="cx">                     continue
</span><del>-            newseq = component.propertyValue(&quot;SEQUENCE&quot;)
-            if newseq is None:
-                newseq = 0
-            oldseq = oldcomponent.propertyValue(&quot;SEQUENCE&quot;)
-            if oldseq is None:
-                oldseq = 0
</del><ins>+            newseq = component.propertyValue(&quot;SEQUENCE&quot;, 0)
+            oldseq = oldcomponent.propertyValue(&quot;SEQUENCE&quot;, 0)
</ins><span class="cx">             if newseq &lt;= oldseq:
</span><span class="cx">                 return True
</span><span class="cx"> 
</span><span class="lines">@@ -3389,9 +3328,7 @@
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx"> 
</span><span class="cx">         if self.name() == &quot;VCALENDAR&quot;:
</span><del>-            for component in self.subcomponents():
-                if component.name() in ignoredComponents:
-                    continue
</del><ins>+            for component in self.subcomponents(ignore=True):
</ins><span class="cx">                 component.normalizePropertyValueLists(propname)
</span><span class="cx">         else:
</span><span class="cx">             for prop in tuple(self.properties(propname)):
</span><span class="lines">@@ -3407,9 +3344,7 @@
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx"> 
</span><span class="cx">         if self.name() == &quot;VCALENDAR&quot;:
</span><del>-            for component in self.subcomponents():
-                if component.name() in ignoredComponents:
-                    continue
</del><ins>+            for component in self.subcomponents(ignore=True):
</ins><span class="cx">                 component.normalizeAttachments()
</span><span class="cx">         else:
</span><span class="cx">             dropboxPrefix = self.propertyValue(&quot;X-APPLE-DROPBOX&quot;)
</span><span class="lines">@@ -3441,9 +3376,11 @@
</span><span class="cx">         @type toCanonical: L{bool}
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx"> 
</span><del>-        for component in self.subcomponents():
-            if component.name() in ignoredComponents:
-                continue
</del><ins>+        # Keep a cache of records because events with lots of recurrence overrides can contain
+        # the same attendee cu-address multuiple times
+        cache = {}
+
+        for component in self.subcomponents(ignore=True):
</ins><span class="cx">             for prop in itertools.chain(
</span><span class="cx">                 component.properties(&quot;ORGANIZER&quot;),
</span><span class="cx">                 component.properties(&quot;ATTENDEE&quot;),
</span><span class="lines">@@ -3453,7 +3390,11 @@
</span><span class="cx">                 # Check that we can lookup this calendar user address - if not
</span><span class="cx">                 # we cannot do anything with it
</span><span class="cx">                 cuaddr = normalizeCUAddr(prop.value())
</span><del>-                name, uid, cutype, cuaddrs = yield lookupFunction(cuaddr, recordFunction, config)
</del><ins>+                if cuaddr not in cache:
+                    result = yield lookupFunction(cuaddr, recordFunction, config)
+                    cache[cuaddr] = result
+
+                name, uid, cutype, cuaddrs = cache[cuaddr]
</ins><span class="cx">                 if uid is None:
</span><span class="cx">                     continue
</span><span class="cx"> 
</span><span class="lines">@@ -3563,10 +3504,7 @@
</span><span class="cx">     def _reconcileGroupAttendee(self, groupCUA, memberAttendeeProps):
</span><span class="cx"> 
</span><span class="cx">         changed = False
</span><del>-        for component in self.subcomponents():
-            if component.name() in ignoredComponents:
-                continue
-
</del><ins>+        for component in self.subcomponents(ignore=True):
</ins><span class="cx">             oldAttendeeProps = tuple(component.properties(&quot;ATTENDEE&quot;))
</span><span class="cx">             oldAttendeeCUAs = set([attendeeProp.value() for attendeeProp in oldAttendeeProps])
</span><span class="cx"> 
</span><span class="lines">@@ -3611,10 +3549,7 @@
</span><span class="cx">                 nonemptyGroupCUAs.add(groupCUA)
</span><span class="cx"> 
</span><span class="cx">         # remove orphans
</span><del>-        for component in self.subcomponents():
-            if component.name() in ignoredComponents:
-                continue
-
</del><ins>+        for component in self.subcomponents(ignore=True):
</ins><span class="cx">             for attendeeProp in tuple(component.properties(&quot;ATTENDEE&quot;)):
</span><span class="cx">                 if attendeeProp.hasParameter(&quot;MEMBER&quot;):
</span><span class="cx">                     attendeeCUA = attendeeProp.value()
</span><span class="lines">@@ -3673,7 +3608,7 @@
</span><span class="cx">                             adjusted_start = subcomponent.propertyValue(&quot;X-APPLE-TRAVEL-DURATION&quot;)
</span><span class="cx">                             adjusted_end = subcomponent.propertyValue(&quot;X-APPLE-TRAVEL-RETURN-DURATION&quot;)
</span><span class="cx">                             self._perUserData.setdefault(uid, {})[instancerid] = (transp, adjusted_start, adjusted_end,)
</span><del>-                elif component.name() not in ignoredComponents:
</del><ins>+                elif not component.ignored():
</ins><span class="cx">                     instancerid = component.propertyValue(&quot;RECURRENCE-ID&quot;)
</span><span class="cx">                     transp = component.propertyValue(&quot;TRANSP&quot;) == &quot;TRANSPARENT&quot;
</span><span class="cx">                     self._perUserData.setdefault(&quot;&quot;, {})[instancerid] = (transp, None, None,)
</span><span class="lines">@@ -3940,7 +3875,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-def normalize_iCalStr(icalstr):
</del><ins>+def normalize_iCalStr(icalstr, filter_params=(&quot;ATTENDEE;X-CALENDARSERVER-DTSTAMP&quot;, &quot;ATTENDEE;X-CALENDARSERVER-RESET-PARTSTAT&quot;,)):
</ins><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     Normalize a string representation of ical data for easy test comparison.
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="lines">@@ -3948,10 +3883,17 @@
</span><span class="cx">     icalstr = str(icalstr).replace(&quot;\r\n &quot;, &quot;&quot;)
</span><span class="cx">     icalstr = icalstr.replace(&quot;\n &quot;, &quot;&quot;)
</span><span class="cx">     lines = [line for line in icalstr.splitlines() if not line.startswith(&quot;DTSTAMP&quot;)]
</span><del>-    for ctr, line in enumerate(lines[:]):
-        pos = line.find(&quot;;X-CALENDARSERVER-DTSTAMP=&quot;)
-        if pos != -1:
-            lines[ctr] = line[:pos] + line[pos + len(&quot;;X-CALENDARSERVER-DTSTAMP=&quot;) + 16:]
</del><ins>+    for param in filter_params:
+        propname, paramname = param.split(&quot;;&quot;)
+        for ctr, line in enumerate(lines[:]):
+            if line.startswith(propname + &quot;;&quot;):
+                pos = line.find(&quot;;{}=&quot;.format(paramname))
+                if pos != -1:
+                    next_segment = line[pos + len(paramname) + 2:]
+                    end_pos = next_segment.find(&quot;;&quot;)
+                    if end_pos == -1:
+                        end_pos = next_segment.find(&quot;:&quot;)
+                    lines[ctr] = line[:pos] + line[pos + len(paramname) + 2 + end_pos:]
</ins><span class="cx">     icalstr = &quot;\r\n&quot;.join(lines)
</span><span class="cx">     return icalstr + &quot;\r\n&quot;
</span><span class="cx"> 
</span></span></pre></div>
<a id="CalendarServertrunktxdavcaldavdatastoreschedulingicaldiffpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/caldav/datastore/scheduling/icaldiff.py (14246 => 14247)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/caldav/datastore/scheduling/icaldiff.py        2015-01-06 16:42:48 UTC (rev 14246)
+++ CalendarServer/trunk/txdav/caldav/datastore/scheduling/icaldiff.py        2015-01-06 16:44:21 UTC (rev 14247)
</span><span class="lines">@@ -772,6 +772,7 @@
</span><span class="cx">             return map
</span><span class="cx"> 
</span><span class="cx">         rids = {}
</span><ins>+        needs_action_changes = {}
</ins><span class="cx"> 
</span><span class="cx">         oldmap = mapComponents(self.oldcalendar)
</span><span class="cx">         oldset = set(oldmap.keys())
</span><span class="lines">@@ -782,7 +783,7 @@
</span><span class="cx">         for key in (oldset &amp; newset):
</span><span class="cx">             component1 = oldmap[key]
</span><span class="cx">             component2 = newmap[key]
</span><del>-            self._diffComponents(component1, component2, rids, isiTip)
</del><ins>+            self._diffComponents(component1, component2, rids, needs_action_changes, isiTip)
</ins><span class="cx"> 
</span><span class="cx">         # Now verify that each additional component in oldset matches a derived component in newset
</span><span class="cx">         for key in oldset - newset:
</span><span class="lines">@@ -796,7 +797,7 @@
</span><span class="cx">                 if not isiTip:
</span><span class="cx">                     rids[rid.getText() if rid is not None else &quot;&quot;] = {&quot;DTSTART&quot;: set()}
</span><span class="cx">                 continue
</span><del>-            self._diffComponents(oldcomponent, newcomponent, rids, isiTip)
</del><ins>+            self._diffComponents(oldcomponent, newcomponent, rids, needs_action_changes, isiTip)
</ins><span class="cx"> 
</span><span class="cx">         # Now verify that each additional component in oldset matches a derived component in newset
</span><span class="cx">         for key in newset - oldset:
</span><span class="lines">@@ -810,9 +811,9 @@
</span><span class="cx">                     rids[rid.getText() if rid is not None else &quot;&quot;] = {&quot;DTSTART&quot;: set()}
</span><span class="cx">                 continue
</span><span class="cx">             newcomponent = newmap[key]
</span><del>-            self._diffComponents(oldcomponent, newcomponent, rids, isiTip)
</del><ins>+            self._diffComponents(oldcomponent, newcomponent, rids, needs_action_changes, isiTip)
</ins><span class="cx"> 
</span><del>-        return rids
</del><ins>+        return (rids, needs_action_changes,)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     TRPROPS = frozenset((
</span><span class="lines">@@ -839,7 +840,8 @@
</span><span class="cx">         @rtype: L{bool}
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx"> 
</span><del>-        for props in self.whatIsDifferent(isiTip=False).values():
</del><ins>+        rids, _ignore_changes = self.whatIsDifferent(isiTip=False)
+        for props in rids.values():
</ins><span class="cx">             props = frozenset(props.keys())
</span><span class="cx">             if props &amp; self.TRPROPS:
</span><span class="cx">                 return True
</span><span class="lines">@@ -930,7 +932,7 @@
</span><span class="cx">         return comp
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-    def _diffComponents(self, comp1, comp2, rids, isiTip=True):
</del><ins>+    def _diffComponents(self, comp1, comp2, rids, needs_action_rids, isiTip=True):
</ins><span class="cx"> 
</span><span class="cx">         assert isinstance(comp1, Component) and isinstance(comp2, Component)
</span><span class="cx"> 
</span><span class="lines">@@ -945,6 +947,7 @@
</span><span class="cx">         # Diff all the properties
</span><span class="cx">         propdiff = set(comp1.properties()) ^ set(comp2.properties())
</span><span class="cx">         addedChanges = False
</span><ins>+        attendeeChanges = False
</ins><span class="cx"> 
</span><span class="cx">         propsChanged = {}
</span><span class="cx">         for prop in propdiff:
</span><span class="lines">@@ -955,6 +958,8 @@
</span><span class="cx">                 &quot;X-CALENDARSERVER-PRIVATE-COMMENT&quot;,
</span><span class="cx">             ):
</span><span class="cx">                 continue
</span><ins>+            if prop.name() == &quot;ATTENDEE&quot;:
+                attendeeChanges = True
</ins><span class="cx">             propsChanged.setdefault(prop.name(), set())
</span><span class="cx">             addedChanges = True
</span><span class="cx">             prop1s = tuple(comp1.properties(prop.name()))
</span><span class="lines">@@ -972,7 +977,30 @@
</span><span class="cx">             rid = comp1.getRecurrenceIDUTC()
</span><span class="cx">             rids[rid] = propsChanged
</span><span class="cx"> 
</span><ins>+        if attendeeChanges:
+            self._diffNeedsAction(comp1, comp2, needs_action_rids)
</ins><span class="cx"> 
</span><ins>+
+    def _diffNeedsAction(self, comp1, comp2, needs_action_rids):
+
+        rid = comp1.getRecurrenceIDUTC()
+
+        # Get all the properties
+        attendees1 = comp1.getAllAttendeeProperties()
+        attendees2 = comp2.getAllAttendeeProperties()
+
+        # Invert
+        attendees1ByValue = dict([(attendee.value(), attendee) for attendee in attendees1])
+        attendees2ByValue = dict([(attendee.value(), attendee) for attendee in attendees2])
+
+        for attendee in attendees2ByValue.keys():
+            if attendee not in attendees1ByValue or (
+                attendees2ByValue[attendee].parameterValue(&quot;PARTSTAT&quot;, &quot;NEEDS-ACTION&quot;) == &quot;NEEDS-ACTION&quot; and
+                attendees1ByValue[attendee].parameterValue(&quot;PARTSTAT&quot;, &quot;NEEDS-ACTION&quot;) != &quot;NEEDS-ACTION&quot;
+            ):
+                needs_action_rids.setdefault(rid, set()).add(attendee)
+
+
</ins><span class="cx">     def _logDiffError(self, title):
</span><span class="cx"> 
</span><span class="cx">         strcal1 = str(self.oldcalendar)
</span></span></pre></div>
<a id="CalendarServertrunktxdavcaldavdatastoreschedulingimplicitpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/caldav/datastore/scheduling/implicit.py (14246 => 14247)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/caldav/datastore/scheduling/implicit.py        2015-01-06 16:42:48 UTC (rev 14246)
+++ CalendarServer/trunk/txdav/caldav/datastore/scheduling/implicit.py        2015-01-06 16:44:21 UTC (rev 14247)
</span><span class="lines">@@ -36,7 +36,7 @@
</span><span class="cx"> from txdav.caldav.datastore.scheduling.itip import iTipGenerator, iTIPRequestStatus
</span><span class="cx"> from txdav.caldav.datastore.scheduling.utils import getCalendarObjectForRecord
</span><span class="cx"> from txdav.caldav.datastore.scheduling.work import ScheduleReplyWork, \
</span><del>-    ScheduleReplyCancelWork, ScheduleOrganizerWork, ScheduleOrganizerSendWork
</del><ins>+    ScheduleOrganizerWork, ScheduleOrganizerSendWork
</ins><span class="cx"> from txdav.caldav.icalendarstore import SetComponentOptions
</span><span class="cx"> 
</span><span class="cx"> import collections
</span><span class="lines">@@ -668,10 +668,7 @@
</span><span class="cx">         self.changed_rids = None
</span><span class="cx">         self.cancelledAttendees = ()
</span><span class="cx">         self.reinvites = None
</span><del>-        self.needs_action_rids = None
</del><span class="cx"> 
</span><del>-        self.needs_sequence_change = False
-
</del><span class="cx">         self.coerceOrganizerScheduleAgent()
</span><span class="cx"> 
</span><span class="cx">         # Check for a delete
</span><span class="lines">@@ -683,8 +680,9 @@
</span><span class="cx">             # Cancel all attendees
</span><span class="cx">             self.cancelledAttendees = [(attendee, None) for attendee in self.attendees]
</span><span class="cx"> 
</span><del>-            # CANCEL always bumps sequence
-            self.needs_sequence_change = True
</del><ins>+            # CANCEL always bumps sequence (if queued, sequence has already changed)
+            if not queued:
+                self.calendar.bumpiTIPInfo(oldcalendar=self.oldcalendar, doSequence=True)
</ins><span class="cx"> 
</span><span class="cx">         # Check for a new resource or an update
</span><span class="cx">         elif self.action in (&quot;modify&quot;, &quot;modify-cancelled&quot;):
</span><span class="lines">@@ -701,7 +699,8 @@
</span><span class="cx">                 self.calendar.sequenceInSync(self.oldcalendar)
</span><span class="cx"> 
</span><span class="cx">             # Significant change
</span><del>-            no_change, self.changed_rids, self.needs_action_rids, reinvites, recurrence_reschedule, status_cancelled, only_status = self.isOrganizerChangeInsignificant()
</del><ins>+            no_change, self.changed_rids, needs_action_rids, needs_action_changed_rids, reinvites, \
+                recurrence_reschedule, status_cancelled, only_status = self.isOrganizerChangeInsignificant()
</ins><span class="cx">             if no_change:
</span><span class="cx">                 if reinvites:
</span><span class="cx">                     log.debug(&quot;Implicit - organizer '{organizer}' is re-inviting UID: '{uid}', attendees: {attendees}&quot;, organizer=self.organizer, uid=self.uid, attendees=&quot;, &quot;.join(reinvites))
</span><span class="lines">@@ -711,11 +710,21 @@
</span><span class="cx">                     log.debug(&quot;Implicit - organizer '{organizer}' is modifying UID: '{uid}' but change is not significant&quot;, organizer=self.organizer, uid=self.uid)
</span><span class="cx">                     returnValue(None)
</span><span class="cx">             else:
</span><del>-                # Do not change PARTSTATs for a split operation
</del><ins>+
+                # For now we always bump the sequence number on modifications because we cannot track DTSTAMP on
+                # the Attendee side. But we check the old and the new and only bump if the client did not already do it.
+                # Also, if queued, the sequence has already been changed
+                if not queued and self.calendar.needsiTIPSequenceChange(self.oldcalendar):
+                    self.calendar.bumpiTIPInfo(oldcalendar=self.oldcalendar, doSequence=True)
+
+                # Only change PARTSTATs for a non-split operation
</ins><span class="cx">                 if self.split_details is None:
</span><ins>+
+                    # Adjust ATTENDEE;PARTSTAT for instances that have changed such that a re-evaluation of partstat is needed
</ins><span class="cx">                     log.debug(&quot;Implicit - organizer '{organizer}' is modifying UID: '{uid}'&quot;, organizer=self.organizer, uid=self.uid)
</span><span class="cx"> 
</span><del>-                    for rid in self.needs_action_rids:
</del><ins>+                    # Look for changes to an instance that require all attendees of that instance to be reset
+                    for rid in needs_action_rids:
</ins><span class="cx">                         comp = self.calendar.overriddenComponent(rid)
</span><span class="cx">                         if comp is None:
</span><span class="cx">                             comp = self.calendar.deriveInstance(rid)
</span><span class="lines">@@ -723,16 +732,28 @@
</span><span class="cx">                                 self.calendar.addComponent(comp)
</span><span class="cx"> 
</span><span class="cx">                         for attendee in comp.getAllAttendeeProperties():
</span><ins>+                            if attendee.value() in self.organizerAddress.record.calendarUserAddresses:
+                                # If the attendee is the organizer then do not update
+                                # the PARTSTAT to NEEDS-ACTION.
+                                # The organizer is automatically ACCEPTED to the event.
+                                continue
</ins><span class="cx">                             if attendee.hasParameter(&quot;PARTSTAT&quot;):
</span><del>-                                cuaddr = attendee.value()
</del><ins>+                                attendee.setParameter(&quot;PARTSTAT&quot;, &quot;NEEDS-ACTION&quot;)
+                            seq = comp.propertyValue(&quot;SEQUENCE&quot;, 0)
+                            attendee.setParameter(&quot;X-CALENDARSERVER-RESET-PARTSTAT&quot;, str(seq))
</ins><span class="cx"> 
</span><del>-                                if cuaddr in self.organizerAddress.record.calendarUserAddresses:
-                                    # If the attendee is the organizer then do not update
-                                    # the PARTSTAT to NEEDS-ACTION.
-                                    # The organizer is automatically ACCEPTED to the event.
-                                    continue
</del><ins>+                    # Look for changes to a specific attendee within an instance
+                    for rid, attendees in needs_action_changed_rids.items():
+                        comp = self.calendar.overriddenComponent(rid)
+                        if comp is None:
+                            comp = self.calendar.deriveInstance(rid)
+                            if comp is not None:
+                                self.calendar.addComponent(comp)
</ins><span class="cx"> 
</span><del>-                                attendee.setParameter(&quot;PARTSTAT&quot;, &quot;NEEDS-ACTION&quot;)
</del><ins>+                        for attendee in comp.getAllAttendeeProperties():
+                            if attendee.value() in attendees:
+                                seq = comp.propertyValue(&quot;SEQUENCE&quot;, 0)
+                                attendee.setParameter(&quot;X-CALENDARSERVER-RESET-PARTSTAT&quot;, str(seq))
</ins><span class="cx">                 else:
</span><span class="cx">                     log.debug(&quot;Implicit - organizer '{organizer}' is splitting UID: '{uid}'&quot;, organizer=self.organizer, uid=self.uid)
</span><span class="cx"> 
</span><span class="lines">@@ -744,18 +765,23 @@
</span><span class="cx"> 
</span><span class="cx">                 self.checkStatusCancelled(status_cancelled, only_status)
</span><span class="cx"> 
</span><del>-                # For now we always bump the sequence number on modifications because we cannot track DTSTAMP on
-                # the Attendee side. But we check the old and the new and only bump if the client did not already do it.
-                self.needs_sequence_change = self.calendar.needsiTIPSequenceChange(self.oldcalendar)
-
</del><span class="cx">         elif self.action == &quot;create&quot;:
</span><span class="cx">             if self.split_details is None:
</span><span class="cx">                 log.debug(&quot;Implicit - organizer '{organizer}' is creating UID: '{uid}'&quot;, organizer=self.organizer, uid=self.uid)
</span><span class="cx">                 self.coerceAttendeesPartstatOnCreate()
</span><span class="cx"> 
</span><ins>+                # We need to handle the case where an organizer &quot;restores&quot; a previously delete event that has a sequence
+                # lower than the one used in the cancel that attendees may still have. In this case what we need to do
+                # is force the sequence to a new value that is significantly higher than the highest one present.
+                # Also, if queued, the sequence has already been changed
+                if not queued:
+                    seqs = map(lambda x: x.value(), self.calendar.getAllPropertiesInAnyComponent(&quot;SEQUENCE&quot;, depth=1))
+                    maxseq = max(seqs) if seqs else 0
+                    if maxseq != 0:
+                        self.calendar.replacePropertyInAllComponents(Property(&quot;SEQUENCE&quot;, maxseq + 1000))
+
</ins><span class="cx">             else:
</span><span class="cx">                 log.debug(&quot;Implicit - organizer '{organizer}' is creating a split UID: '{uid}'&quot;, organizer=self.organizer, uid=self.uid)
</span><del>-                self.needs_sequence_change = False
</del><span class="cx"> 
</span><span class="cx">         # Always set RSVP=TRUE for any NEEDS-ACTION
</span><span class="cx">         for attendee in self.calendar.getAllAttendeeProperties():
</span><span class="lines">@@ -768,20 +794,8 @@
</span><span class="cx">                 attendee.removeParameter(&quot;PARTSTAT&quot;)
</span><span class="cx"> 
</span><span class="cx">         # If processing a queue item, actually execute the scheduling operations, else queue it.
</span><del>-        # Note a split is always queued, so we do not need to re-queue
</del><ins>+        # Note a split is always a queued execution, so we do not need to re-queue
</ins><span class="cx">         if queued or not config.Scheduling.Options.WorkQueues.Enabled or self.split_details is not None:
</span><del>-            if self.action == &quot;create&quot;:
-                if self.split_details is None:
-                    # We need to handle the case where an organizer &quot;restores&quot; a previously delete event that has a sequence
-                    # lower than the one used in the cancel that attendees may still have. In this case what we need to do
-                    # is force the sequence to a new value that is significantly higher than the highest one present.
-                    seqs = map(lambda x: x.value(), self.calendar.getAllPropertiesInAnyComponent(&quot;SEQUENCE&quot;, depth=1))
-                    maxseq = max(seqs) if seqs else 0
-                    if maxseq != 0:
-                        self.calendar.replacePropertyInAllComponents(Property(&quot;SEQUENCE&quot;, maxseq + 1000))
-            elif self.needs_sequence_change:
-                self.calendar.bumpiTIPInfo(oldcalendar=self.oldcalendar, doSequence=True)
-
</del><span class="cx">             yield self.scheduleWithAttendees()
</span><span class="cx">         else:
</span><span class="cx">             yield self.queuedScheduleWithAttendees()
</span><span class="lines">@@ -795,9 +809,25 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def isOrganizerChangeInsignificant(self):
</span><ins>+        &quot;&quot;&quot;
+        Detect exactly how an organizer update has changed an event and report back the key items
+        needed for iTIP scheduling for those changes. These items are returned:
</ins><span class="cx"> 
</span><ins>+        L{rids} - the L{DateTime} for each instance that had any kind of change
+        L{date_changed_rids} - the L{DateTime} for each instance that had a scheduling
+            change that needs to reset every ATTENDEE;PARTSTAT to NEEDS-ACTION
+        L{needs_action_changed_rids} - the L{DateTime}:L{set} map for each instance
+            where an ATTENDEE property was reset to NEEDS-ACTION by the organizer
+        L{reinvites} - the L{set} of each attendee that has a SCHEDULE-FORCE-SEND
+        L{recurrence_reschedule} - whether or not an entire reschedule of an RRULE
+            has occurred
+        L{status_cancelled} - the L{DateTime} for each instance that now has STATUS:CANCELLED
+        L{only_status} - L{True} if the only change was a STATUS change
+        &quot;&quot;&quot;
+
</ins><span class="cx">         rids = None
</span><span class="cx">         date_changed_rids = None
</span><ins>+        needs_action_changed_rids = None
</ins><span class="cx">         reinvites = None
</span><span class="cx">         recurrence_reschedule = False
</span><span class="cx">         status_cancelled = set()
</span><span class="lines">@@ -806,11 +836,16 @@
</span><span class="cx">         no_change = differ.organizerDiff()
</span><span class="cx">         if not no_change:
</span><span class="cx">             # ORGANIZER change is absolutely not allowed!
</span><del>-            diffs = differ.whatIsDifferent()
</del><ins>+            diffs, needs_action_changed_rids = differ.whatIsDifferent()
</ins><span class="cx">             rids = set()
</span><span class="cx">             date_changed_rids = set()
</span><span class="cx">             checkOrganizerValue = False
</span><span class="cx">             for rid, props in diffs.iteritems():
</span><ins>+
+                # Ignore sequence only changes
+                if &quot;SEQUENCE&quot; in props and len(props) == 1:
+                    continue
+
</ins><span class="cx">                 if &quot;ORGANIZER&quot; in props:
</span><span class="cx">                     checkOrganizerValue = True
</span><span class="cx">                 rids.add(rid)
</span><span class="lines">@@ -904,7 +939,7 @@
</span><span class="cx">                     pass
</span><span class="cx"> 
</span><span class="cx">         return (
</span><del>-            no_change, rids, date_changed_rids, reinvites,
</del><ins>+            no_change, rids, date_changed_rids, needs_action_changed_rids, reinvites,
</ins><span class="cx">             recurrence_reschedule, status_cancelled, only_status
</span><span class="cx">         )
</span><span class="cx"> 
</span><span class="lines">@@ -1147,22 +1182,6 @@
</span><span class="cx">             self.do_smart_merge,
</span><span class="cx">         )
</span><span class="cx"> 
</span><del>-        # We bump the sequence AFTER storing the work item data to make sure that the sequence
-        # change does not cause unchanged components to be treated as changed when the work
-        # item executes.
-
-        if self.action == &quot;create&quot;:
-            # We need to handle the case where an organizer &quot;restores&quot; a previously delete event that has a sequence
-            # lower than the one used in the cancel that attendees may still have. In this case what we need to do
-            # is force the sequence to a new value that is significantly higher than the highest one present.
-            seqs = map(lambda x: x.value(), self.calendar.getAllPropertiesInAnyComponent(&quot;SEQUENCE&quot;, depth=1))
-            maxseq = max(seqs) if seqs else 0
-            if maxseq != 0:
-                self.calendar.replacePropertyInAllComponents(Property(&quot;SEQUENCE&quot;, maxseq + 1000))
-
-        elif self.needs_sequence_change:
-            self.calendar.bumpiTIPInfo(oldcalendar=self.oldcalendar, doSequence=True)
-
</del><span class="cx">         # First process cancelled attendees
</span><span class="cx">         total = (yield self.processCancels(queued=True))
</span><span class="cx"> 
</span><span class="lines">@@ -1701,6 +1720,7 @@
</span><span class="cx">         if self.logItems is not None:
</span><span class="cx">             self.logItems[&quot;itip.reply&quot;] = &quot;reply&quot;
</span><span class="cx"> 
</span><ins>+        itipmsg = iTipGenerator.generateAttendeeReply(self.calendar, self.attendee, changedRids=changedRids)
</ins><span class="cx">         if config.Scheduling.Options.WorkQueues.Enabled:
</span><span class="cx">             # Always make it look like scheduling succeeded when queuing
</span><span class="cx">             self.calendar.setParameterToValueForPropertyWithValue(
</span><span class="lines">@@ -1710,11 +1730,9 @@
</span><span class="cx">                 self.organizer,
</span><span class="cx">             )
</span><span class="cx"> 
</span><del>-            return ScheduleReplyWork.reply(self.txn, self.calendar_home, self.resource, changedRids, self.attendee)
</del><ins>+            return ScheduleReplyWork.reply(self.txn, self.calendar_home, self.resource, itipmsg, self.attendee)
</ins><span class="cx"> 
</span><span class="cx">         else:
</span><del>-            itipmsg = iTipGenerator.generateAttendeeReply(self.calendar, self.attendee, changedRids=changedRids)
-
</del><span class="cx">             # Send scheduling message
</span><span class="cx">             return self.sendToOrganizer(&quot;REPLY&quot;, itipmsg)
</span><span class="cx"> 
</span><span class="lines">@@ -1727,12 +1745,11 @@
</span><span class="cx">         if self.logItems is not None:
</span><span class="cx">             self.logItems[&quot;itip.reply&quot;] = &quot;cancel&quot;
</span><span class="cx"> 
</span><ins>+        itipmsg = iTipGenerator.generateAttendeeReply(self.calendar, self.attendee, force_decline=True)
+
</ins><span class="cx">         if config.Scheduling.Options.WorkQueues.Enabled:
</span><del>-            return ScheduleReplyCancelWork.replyCancel(self.txn, self.calendar_home, self.calendar, self.attendee)
-
</del><ins>+            return ScheduleReplyWork.reply(self.txn, self.calendar_home, None, itipmsg, self.attendee)
</ins><span class="cx">         else:
</span><del>-            itipmsg = iTipGenerator.generateAttendeeReply(self.calendar, self.attendee, force_decline=True)
-
</del><span class="cx">             # Send scheduling message
</span><span class="cx">             return self.sendToOrganizer(&quot;CANCEL&quot;, itipmsg)
</span><span class="cx"> 
</span></span></pre></div>
<a id="CalendarServertrunktxdavcaldavdatastoreschedulingitippy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/caldav/datastore/scheduling/itip.py (14246 => 14247)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/caldav/datastore/scheduling/itip.py        2015-01-06 16:42:48 UTC (rev 14246)
+++ CalendarServer/trunk/txdav/caldav/datastore/scheduling/itip.py        2015-01-06 16:44:21 UTC (rev 14247)
</span><span class="lines">@@ -17,21 +17,21 @@
</span><span class="cx"> &quot;&quot;&quot;
</span><span class="cx"> iTIP (RFC5546) scheduling message processing and generation.
</span><span class="cx"> 
</span><ins>+This modules takes an iTIP message, and a matching existing calendar object, and it
+applies the changes implied by the iTIP message to the existing data (or creates new
+data if needed).
</ins><span class="cx"> 
</span><del>-This is currently used for handling auto-replies to schedule requests arriving
-in an inbox. It is called in a delayed fashion via reactor.callLater.
-
</del><span class="cx"> We assume that all the components/calendars we deal with have been determined
</span><span class="cx"> as being 'valid for CalDAV/iTIP', i.e. they contain UIDs, single component
</span><span class="cx"> types, etc.
</span><span class="cx"> &quot;&quot;&quot;
</span><span class="cx"> 
</span><ins>+from collections import namedtuple
</ins><span class="cx"> 
</span><span class="cx"> from twext.python.log import Logger
</span><span class="cx"> 
</span><span class="cx"> from twistedcaldav.config import config
</span><del>-from twistedcaldav.ical import Property, iCalendarProductID, Component, \
-    ignoredComponents
</del><ins>+from twistedcaldav.ical import Property, iCalendarProductID, Component
</ins><span class="cx"> 
</span><span class="cx"> from pycalendar.datetime import DateTime
</span><span class="cx"> 
</span><span class="lines">@@ -45,7 +45,60 @@
</span><span class="cx"> 
</span><span class="cx"> class iTipProcessing(object):
</span><span class="cx"> 
</span><ins>+    # Information to be transferred from one component to another
+    TransferDetails = namedtuple(
+        &quot;TransferDetails&quot;,
+        [
+            &quot;valarms&quot;, &quot;private_comments&quot;, &quot;transps&quot;, &quot;completeds&quot;, &quot;organizer&quot;,
+            &quot;organizer_schedule_status&quot;, &quot;attendee&quot;, &quot;attendee_dtstamp&quot;, &quot;sequence&quot;,
+            &quot;other_props&quot;, &quot;recipient&quot;,
+        ]
+    )
+
</ins><span class="cx">     @staticmethod
</span><ins>+    def _transferDetails(component, recipient):
+        &quot;&quot;&quot;
+        Get the L{TransferDetails} from the specified component, which may be L{None}.
+
+        @param component: the component to extract details from
+        @type component: L{Component} or L{None}
+        @param recipient: the attendee whose iTIP message is being processed
+        @type recipient: L{str}
+        &quot;&quot;&quot;
+        if component:
+            valarms = [comp for comp in component.subcomponents() if comp.name() == &quot;VALARM&quot;]
+            private_comments = tuple(component.properties(&quot;X-CALENDARSERVER-PRIVATE-COMMENT&quot;))
+            transps = tuple(component.properties(&quot;TRANSP&quot;))
+            completeds = tuple(component.properties(&quot;COMPLETED&quot;))
+            organizer = component.getProperty(&quot;ORGANIZER&quot;)
+            organizer_schedule_status = organizer.parameterValue(&quot;SCHEDULE-STATUS&quot;, None) if organizer else None
+            attendee = component.getAttendeeProperty((recipient,))
+            attendee_dtstamp = attendee.parameterValue(&quot;X-CALENDARSERVER-DTSTAMP&quot;) if attendee else None
+            sequence = component.propertyValue(&quot;SEQUENCE&quot;, 0)
+            other_props = {}
+            for pname in config.Scheduling.CalDAV.PerAttendeeProperties:
+                props = tuple(component.properties(pname))
+                other_props[pname] = props
+        else:
+            valarms = ()
+            private_comments = ()
+            transps = ()
+            completeds = ()
+            organizer = None
+            organizer_schedule_status = None
+            attendee = None
+            attendee_dtstamp = None
+            sequence = 0,
+            other_props = {}
+
+        return iTipProcessing.TransferDetails(
+            valarms, private_comments, transps, completeds, organizer,
+            organizer_schedule_status, attendee, attendee_dtstamp, sequence,
+            other_props, recipient,
+        )
+
+
+    @staticmethod
</ins><span class="cx">     def processNewRequest(itip_message, recipient=None, creating=False):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Process a METHOD=REQUEST for a brand new calendar object (for creating set to C{True}. This is also
</span><span class="lines">@@ -72,10 +125,11 @@
</span><span class="cx">             # Check for incoming DECLINED
</span><span class="cx">             if creating:
</span><span class="cx">                 iTipProcessing.addTranspForNeedsAction(calendar.subcomponents(), recipient)
</span><ins>+                calendar.removePropertyParameters(&quot;ATTENDEE&quot;, (&quot;X-CALENDARSERVER-RESET-PARTSTAT&quot;,))
</ins><span class="cx"> 
</span><span class="cx">                 master = calendar.masterComponent()
</span><del>-                for component in tuple(calendar.subcomponents()):
-                    if component in ignoredComponents or component is master:
</del><ins>+                for component in tuple(calendar.subcomponents(ignore=True)):
+                    if component is master:
</ins><span class="cx">                         continue
</span><span class="cx">                     attendee = component.getAttendeeProperty((recipient,))
</span><span class="cx">                     if attendee and attendee.parameterValue(&quot;PARTSTAT&quot;, &quot;NEEDS-ACTION&quot;) == &quot;DECLINED&quot;:
</span><span class="lines">@@ -118,35 +172,14 @@
</span><span class="cx">         # Merge Organizer data with Attendee's own changes (VALARMs, Comment only for now).
</span><span class="cx">         from txdav.caldav.datastore.scheduling.icaldiff import iCalDiff
</span><span class="cx">         differ = iCalDiff(calendar, itip_message, False)
</span><del>-        rids = differ.whatIsDifferent()
</del><ins>+        rids, _ignore_changes = differ.whatIsDifferent()
</ins><span class="cx">         needs_action_rids, reschedule = differ.attendeeNeedsAction(rids)
</span><span class="cx"> 
</span><span class="cx">         # Different behavior depending on whether a master component is present or not
</span><span class="cx">         # Here we cache per-attendee data from the existing master that we need to use in any new
</span><span class="cx">         # overridden components that the organizer added
</span><span class="cx">         current_master = calendar.masterComponent()
</span><del>-        if current_master:
-            valarms = [comp for comp in current_master.subcomponents() if comp.name() == &quot;VALARM&quot;]
-            private_comments = tuple(current_master.properties(&quot;X-CALENDARSERVER-PRIVATE-COMMENT&quot;))
-            transps = tuple(current_master.properties(&quot;TRANSP&quot;))
-            completeds = tuple(current_master.properties(&quot;COMPLETED&quot;))
-            organizer = current_master.getProperty(&quot;ORGANIZER&quot;)
-            organizer_schedule_status = organizer.parameterValue(&quot;SCHEDULE-STATUS&quot;, None) if organizer else None
-            attendee = current_master.getAttendeeProperty((recipient,))
-            attendee_dtstamp = attendee.parameterValue(&quot;X-CALENDARSERVER-DTSTAMP&quot;) if attendee else None
-            other_props = {}
-            for pname in config.Scheduling.CalDAV.PerAttendeeProperties:
-                props = tuple(current_master.properties(pname))
-                other_props[pname] = props
-        else:
-            valarms = ()
-            private_comments = ()
-            transps = ()
-            completeds = ()
-            organizer_schedule_status = None
-            attendee = None
-            attendee_dtstamp = None
-            other_props = {}
</del><ins>+        details = iTipProcessing._transferDetails(current_master, recipient)
</ins><span class="cx"> 
</span><span class="cx">         if itip_message.masterComponent() is not None:
</span><span class="cx"> 
</span><span class="lines">@@ -156,13 +189,12 @@
</span><span class="cx">             # Copy over master alarms, comments etc
</span><span class="cx">             master_component = new_calendar.masterComponent()
</span><span class="cx">             transfer_partstat = None not in needs_action_rids and not reschedule
</span><del>-            seq_change = Component.compareComponentsForITIP(master_component, current_master, use_dtstamp=False) &lt;= 0 if current_master is not None else False
-            iTipProcessing._transferItems(master_component, transfer_partstat and seq_change, valarms, private_comments, transps, completeds, organizer_schedule_status, attendee, attendee_dtstamp, other_props, recipient)
</del><ins>+            iTipProcessing._transferItems(master_component, transfer_partstat, details)
</ins><span class="cx"> 
</span><span class="cx">             # Now try to match recurrences in the new calendar
</span><span class="cx">             for component in tuple(new_calendar.subcomponents()):
</span><span class="cx">                 if component.name() != &quot;VTIMEZONE&quot; and component.getRecurrenceIDUTC() is not None:
</span><del>-                    iTipProcessing.transferItems(calendar, component, needs_action_rids, reschedule, valarms, private_comments, transps, completeds, organizer_schedule_status, attendee, attendee_dtstamp, other_props, recipient)
</del><ins>+                    iTipProcessing.transferItems(calendar, component, needs_action_rids, reschedule, details)
</ins><span class="cx"> 
</span><span class="cx">             # Now try to match recurrences from the old calendar
</span><span class="cx">             for component in calendar.subcomponents():
</span><span class="lines">@@ -181,11 +213,12 @@
</span><span class="cx">                                 new_calendar.addComponent(component.duplicate())
</span><span class="cx">                             else:
</span><span class="cx">                                 new_calendar.addComponent(new_component)
</span><del>-                                iTipProcessing.transferItems(calendar, new_component, needs_action_rids, reschedule, valarms, private_comments, transps, completeds, organizer_schedule_status, attendee, attendee_dtstamp, other_props, recipient)
</del><ins>+                                iTipProcessing.transferItems(calendar, new_component, needs_action_rids, reschedule, details)
</ins><span class="cx">                                 if hidden:
</span><span class="cx">                                     new_component.addProperty(Property(Component.HIDDEN_INSTANCE_PROPERTY, &quot;T&quot;))
</span><span class="cx"> 
</span><span class="cx">             iTipProcessing.addTranspForNeedsAction(new_calendar.subcomponents(), recipient)
</span><ins>+            new_calendar.removePropertyParameters(&quot;ATTENDEE&quot;, (&quot;X-CALENDARSERVER-RESET-PARTSTAT&quot;,))
</ins><span class="cx"> 
</span><span class="cx">             # Replace the entire object
</span><span class="cx">             return new_calendar, rids
</span><span class="lines">@@ -202,7 +235,7 @@
</span><span class="cx">                         calendar.addComponent(component)
</span><span class="cx">                 else:
</span><span class="cx">                     component = component.duplicate()
</span><del>-                    missingDeclined = iTipProcessing.transferItems(calendar, component, needs_action_rids, reschedule, valarms, private_comments, transps, completeds, organizer_schedule_status, attendee, attendee_dtstamp, other_props, recipient, remove_matched=True)
</del><ins>+                    missingDeclined = iTipProcessing.transferItems(calendar, component, needs_action_rids, reschedule, details, remove_matched=True)
</ins><span class="cx">                     if not missingDeclined:
</span><span class="cx">                         # Add the component and make sure to remove any matching EXDATE
</span><span class="cx">                         calendar.addComponent(component)
</span><span class="lines">@@ -210,6 +243,7 @@
</span><span class="cx">                             current_master.removeExdate(component.getRecurrenceIDUTC())
</span><span class="cx"> 
</span><span class="cx">             iTipProcessing.addTranspForNeedsAction(calendar.subcomponents(), recipient)
</span><ins>+            calendar.removePropertyParameters(&quot;ATTENDEE&quot;, (&quot;X-CALENDARSERVER-RESET-PARTSTAT&quot;,))
</ins><span class="cx"> 
</span><span class="cx">             # Write back the modified object
</span><span class="cx">             return calendar, rids
</span><span class="lines">@@ -251,7 +285,7 @@
</span><span class="cx">             else:
</span><span class="cx">                 # Cancel every instance in the existing event and sync over SEQUENCE
</span><span class="cx">                 calendar.replacePropertyInAllComponents(Property(&quot;STATUS&quot;, &quot;CANCELLED&quot;))
</span><del>-                newseq = itip_message.masterComponent().propertyValue(&quot;SEQUENCE&quot;)
</del><ins>+                newseq = itip_message.masterComponent().propertyValue(&quot;SEQUENCE&quot;, 0)
</ins><span class="cx">                 calendar.replacePropertyInAllComponents(Property(&quot;SEQUENCE&quot;, newseq))
</span><span class="cx">                 return True, False, None
</span><span class="cx"> 
</span><span class="lines">@@ -291,7 +325,7 @@
</span><span class="cx">                 else:
</span><span class="cx">                     # Existing component is cancelled.
</span><span class="cx">                     overridden.replaceProperty(Property(&quot;STATUS&quot;, &quot;CANCELLED&quot;))
</span><del>-                    newseq = component.propertyValue(&quot;SEQUENCE&quot;)
</del><ins>+                    newseq = component.propertyValue(&quot;SEQUENCE&quot;, 0)
</ins><span class="cx">                     overridden.replaceProperty(Property(&quot;SEQUENCE&quot;, newseq))
</span><span class="cx"> 
</span><span class="cx">             elif calendar_master:
</span><span class="lines">@@ -306,7 +340,7 @@
</span><span class="cx">                     if overridden is not None:
</span><span class="cx">                         overridden.replaceProperty(Property(&quot;STATUS&quot;, &quot;CANCELLED&quot;))
</span><span class="cx">                         calendar.addComponent(overridden)
</span><del>-                        newseq = component.propertyValue(&quot;SEQUENCE&quot;)
</del><ins>+                        newseq = component.propertyValue(&quot;SEQUENCE&quot;, 0)
</ins><span class="cx">                         overridden.replaceProperty(Property(&quot;SEQUENCE&quot;, newseq))
</span><span class="cx"> 
</span><span class="cx">         # If we have any EXDATEs lets add them to the existing calendar object.
</span><span class="lines">@@ -355,7 +389,7 @@
</span><span class="cx">         attendees = set()
</span><span class="cx">         rids = set()
</span><span class="cx">         if new_master is not None and old_master is not None:
</span><del>-            attendee, partstat, private_comment = iTipProcessing.updateAttendeeData(new_master, old_master)
</del><ins>+            attendee, partstat, private_comment = iTipProcessing.updateAttendeeDataFromReply(new_master, old_master)
</ins><span class="cx">             if attendee:
</span><span class="cx">                 attendees.add(attendee)
</span><span class="cx">                 if partstat or private_comment:
</span><span class="lines">@@ -405,7 +439,7 @@
</span><span class="cx">                     log.error(&quot;Ignoring instance: %s in iTIP REPLY for: %s&quot; % (rid, itip_message.resourceUID()))
</span><span class="cx">                     continue
</span><span class="cx"> 
</span><del>-            attendee, partstat, private_comment = iTipProcessing.updateAttendeeData(itip_component, match_component)
</del><ins>+            attendee, partstat, private_comment = iTipProcessing.updateAttendeeDataFromReply(itip_component, match_component)
</ins><span class="cx">             if attendee:
</span><span class="cx">                 attendees.add(attendee)
</span><span class="cx">                 if rids is not None and (partstat or private_comment):
</span><span class="lines">@@ -423,20 +457,20 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @staticmethod
</span><del>-    def updateAttendeeData(from_component, to_component):
</del><ins>+    def updateAttendeeDataFromReply(reply_component, organizer_component):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Called when processing a REPLY only.
</span><span class="cx"> 
</span><del>-        Copy the PARTSTAT of the Attendee in the from_component to the matching ATTENDEE
-        in the to_component. Ignore if no match found. Also update the private comments.
</del><ins>+        Copy the PARTSTAT of the Attendee in the reply_component to the matching ATTENDEE
+        in the organizer_component. Ignore if no match found. Also update the private comments.
</ins><span class="cx"> 
</span><span class="cx">         For VPOLL we need to copy POLL-ITEM-ID response values into the actual matching
</span><span class="cx">         polled sub-components as VOTER properties.
</span><span class="cx"> 
</span><del>-        @param from_component: component to copy from
-        @type from_component: L{Component}
-        @param to_component: component to copy to
-        @type to_component: L{Component}
</del><ins>+        @param reply_component: component to copy from
+        @type reply_component: L{Component}
+        @param organizer_component: component to copy to
+        @type organizer_component: L{Component}
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx"> 
</span><span class="cx">         # Track what changed
</span><span class="lines">@@ -444,24 +478,28 @@
</span><span class="cx">         private_comment_changed = False
</span><span class="cx"> 
</span><span class="cx">         # Get REQUEST-STATUS as we need to write that into the saved ATTENDEE property
</span><del>-        reqstatus = tuple(from_component.properties(&quot;REQUEST-STATUS&quot;))
</del><ins>+        reqstatus = tuple(reply_component.properties(&quot;REQUEST-STATUS&quot;))
</ins><span class="cx">         if reqstatus:
</span><span class="cx">             reqstatus = &quot;,&quot;.join(status.value()[0] for status in reqstatus)
</span><span class="cx">         else:
</span><span class="cx">             reqstatus = &quot;2.0&quot;
</span><span class="cx"> 
</span><del>-        # Get attendee in from_component - there MUST be only one
-        attendees = tuple(from_component.properties(from_component.recipientPropertyName()))
</del><ins>+        # Get attendee in reply_component - there MUST be only one
+        attendees = tuple(reply_component.properties(reply_component.recipientPropertyName()))
</ins><span class="cx">         if len(attendees) != 1:
</span><del>-            log.error(&quot;There must be one and only one ATTENDEE property in a REPLY\n%s&quot; % (str(from_component),))
</del><ins>+            log.error(&quot;There must be one and only one ATTENDEE property in a REPLY\n%s&quot; % (str(reply_component),))
</ins><span class="cx">             return None, False, False
</span><span class="cx"> 
</span><span class="cx">         attendee = attendees[0]
</span><span class="cx">         partstat = attendee.parameterValue(&quot;PARTSTAT&quot;, &quot;NEEDS-ACTION&quot;)
</span><ins>+        reply_sequence = reply_component.propertyValue(&quot;SEQUENCE&quot;, 0)
</ins><span class="cx"> 
</span><del>-        # Now find matching ATTENDEE in to_component
-        existing_attendee = to_component.getAttendeeProperty((attendee.value(),))
-        if existing_attendee:
</del><ins>+        # Now find matching ATTENDEE in organizer_component
+        existing_attendee = organizer_component.getAttendeeProperty((attendee.value(),))
+        existing_reset_sequence = int(existing_attendee.parameterValue(&quot;X-CALENDARSERVER-RESET-PARTSTAT&quot;, &quot;0&quot;)) if existing_attendee else 0
+
+        # Only process the change for this component if it was made after the last partstat reset
+        if existing_attendee and reply_sequence &gt;= existing_reset_sequence:
</ins><span class="cx">             oldpartstat = existing_attendee.parameterValue(&quot;PARTSTAT&quot;, &quot;NEEDS-ACTION&quot;)
</span><span class="cx">             existing_attendee.setParameter(&quot;PARTSTAT&quot;, partstat)
</span><span class="cx">             existing_attendee.setParameter(&quot;SCHEDULE-STATUS&quot;, reqstatus)
</span><span class="lines">@@ -477,11 +515,11 @@
</span><span class="cx">             # Handle attendee comments
</span><span class="cx">             if config.Scheduling.CalDAV.get(&quot;EnablePrivateComments&quot;, True):
</span><span class="cx">                 # Look for X-CALENDARSERVER-PRIVATE-COMMENT property in iTIP component (State 1 in spec)
</span><del>-                attendee_comment = tuple(from_component.properties(&quot;X-CALENDARSERVER-PRIVATE-COMMENT&quot;))
</del><ins>+                attendee_comment = tuple(reply_component.properties(&quot;X-CALENDARSERVER-PRIVATE-COMMENT&quot;))
</ins><span class="cx">                 attendee_comment = attendee_comment[0] if len(attendee_comment) else None
</span><span class="cx"> 
</span><span class="cx">                 # Look for matching X-CALENDARSERVER-ATTENDEE-COMMENT property in existing data (State 2 in spec)
</span><del>-                private_comments = tuple(to_component.properties(&quot;X-CALENDARSERVER-ATTENDEE-COMMENT&quot;))
</del><ins>+                private_comments = tuple(organizer_component.properties(&quot;X-CALENDARSERVER-ATTENDEE-COMMENT&quot;))
</ins><span class="cx">                 for comment in private_comments:
</span><span class="cx">                     attendeeref = comment.parameterValue(&quot;X-CALENDARSERVER-ATTENDEE-REF&quot;)
</span><span class="cx">                     if attendeeref == attendee.value():
</span><span class="lines">@@ -500,7 +538,7 @@
</span><span class="cx"> 
</span><span class="cx">             elif attendee_comment is None and private_comment is not None:
</span><span class="cx">                 # We now remove the private comment on the organizer's side if the attendee removed it
</span><del>-                to_component.removeProperty(private_comment)
</del><ins>+                organizer_component.removeProperty(private_comment)
</ins><span class="cx"> 
</span><span class="cx">                 private_comment_changed = True
</span><span class="cx"> 
</span><span class="lines">@@ -515,7 +553,7 @@
</span><span class="cx">                         &quot;X-CALENDARSERVER-DTSTAMP&quot;: DateTime.getNowUTC().getText(),
</span><span class="cx">                     }
</span><span class="cx">                 )
</span><del>-                to_component.addProperty(private_comment)
</del><ins>+                organizer_component.addProperty(private_comment)
</ins><span class="cx"> 
</span><span class="cx">                 private_comment_changed = True
</span><span class="cx"> 
</span><span class="lines">@@ -535,33 +573,31 @@
</span><span class="cx">                     private_comment_changed = True
</span><span class="cx"> 
</span><span class="cx">             # Do VPOLL transfer
</span><del>-            if from_component.name() == &quot;VPOLL&quot;:
</del><ins>+            if reply_component.name() == &quot;VPOLL&quot;:
</ins><span class="cx">                 # TODO: figure out how to report changes back
</span><del>-                iTipProcessing.updateVPOLLData(from_component, to_component, attendee)
</del><ins>+                iTipProcessing.updateVPOLLDataFromReply(reply_component, organizer_component, attendee)
</ins><span class="cx"> 
</span><span class="cx">         return attendee.value(), partstat_changed, private_comment_changed
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @staticmethod
</span><del>-    def updateVPOLLData(from_component, to_component, attendee):
</del><ins>+    def updateVPOLLDataFromReply(reply_component, organizer_component, attendee):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Update VPOLL sub-components with voter's response.
</span><span class="cx"> 
</span><del>-        @param from_component: component to copy from
-        @type from_component: L{Component}
-        @param to_component: component to copy to
-        @type to_component: L{Component}
</del><ins>+        @param reply_component: component to copy from
+        @type reply_component: L{Component}
+        @param organizer_component: component to copy to
+        @type organizer_component: L{Component}
</ins><span class="cx">         @param attendee: attendee being processed
</span><span class="cx">         @type attendee: L{Property}
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx"> 
</span><span class="cx">         responses = {}
</span><del>-        for prop in from_component.properties(&quot;POLL-ITEM-ID&quot;):
</del><ins>+        for prop in reply_component.properties(&quot;POLL-ITEM-ID&quot;):
</ins><span class="cx">             responses[prop.value()] = prop
</span><span class="cx"> 
</span><del>-        for component in to_component.subcomponents():
-            if component.name() in ignoredComponents:
-                continue
</del><ins>+        for component in organizer_component.subcomponents(ignore=True):
</ins><span class="cx">             poll_item_id = component.propertyValue(&quot;POLL-ITEM-ID&quot;)
</span><span class="cx">             if poll_item_id is None:
</span><span class="cx">                 continue
</span><span class="lines">@@ -581,7 +617,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @staticmethod
</span><del>-    def transferItems(from_calendar, to_component, needs_action_rids, reschedule, valarms, private_comments, transps, completeds, organizer_schedule_status, attendee, attendee_dtstamp, other_props, recipient, remove_matched=False):
</del><ins>+    def transferItems(from_calendar, to_component, needs_action_rids, reschedule, master_details, remove_matched=False):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Transfer properties from a calendar to a component by first trying to match the component in the original calendar and
</span><span class="cx">         use the properties from that, or use the values provided as arguments (which have been derived from the original calendar's
</span><span class="lines">@@ -591,22 +627,8 @@
</span><span class="cx">         @type from_calendar: L{Component}
</span><span class="cx">         @param to_component: the new component to transfer items to
</span><span class="cx">         @type to_component: L{Component}
</span><del>-        @param valarms: a C{list} of VALARM components from the old master to use
-        @type valarms: C{list}
-        @param private_comments: a C{list} of private comment properties from the old master to use
-        @type private_comments: C{list}
-        @param transps: a C{list} of TRANSP properties from the old master to use
-        @type transps: C{list}
-        @param completeds: a C{list} of COMPLETED properties from the old master to use
-        @type completeds: C{list}
-        @param organizer_schedule_status: a the SCHEDULE-STATUS value for the organizer from the old master to use
-        @type organizer_schedule_status: C{str}
-        @param attendee_dtstamp: an the ATTENDEE DTSTAMP parameter value from the old master to use
-        @type attendee_dtstamp: C{str}
-        @param other_props: other properties from the old master to use
-        @type other_props: C{list}
-        @param recipient: the calendar user address of the attendee whose data is being processed
-        @type recipient: C{str}
</del><ins>+        @param master_details: the L{TransferDetails} for the master component
+        @type master_details: L{TransferDetails}
</ins><span class="cx">         @param remove_matched: whether or not to remove the matching component rather than transfer items
</span><span class="cx">         @type remove_matched: C{bool}
</span><span class="cx"> 
</span><span class="lines">@@ -620,24 +642,13 @@
</span><span class="cx">         # Is there a matching component
</span><span class="cx">         matched = from_calendar.overriddenComponent(rid)
</span><span class="cx">         if matched:
</span><del>-            valarms = [comp for comp in matched.subcomponents() if comp.name() == &quot;VALARM&quot;]
-            private_comments = tuple(matched.properties(&quot;X-CALENDARSERVER-PRIVATE-COMMENT&quot;))
-            transps = tuple(matched.properties(&quot;TRANSP&quot;))
-            completeds = tuple(matched.properties(&quot;COMPLETED&quot;))
-            organizer = matched.getProperty(&quot;ORGANIZER&quot;)
-            organizer_schedule_status = organizer.parameterValue(&quot;SCHEDULE-STATUS&quot;, None) if organizer else None
-            attendee = matched.getAttendeeProperty((recipient,))
-            attendee_dtstamp = attendee.parameterValue(&quot;X-CALENDARSERVER-DTSTAMP&quot;) if attendee else None
-            other_props = {}
-            for pname in config.Scheduling.CalDAV.PerAttendeeProperties:
-                props = tuple(matched.properties(pname))
-                other_props[pname] = props
</del><span class="cx"> 
</span><del>-            seq_change = Component.compareComponentsForITIP(to_component, matched, use_dtstamp=False) &lt;= 0
-            iTipProcessing._transferItems(to_component, transfer_partstat and seq_change, valarms, private_comments, transps, completeds, organizer_schedule_status, attendee, attendee_dtstamp, other_props, recipient)
</del><ins>+            details = iTipProcessing._transferDetails(matched, master_details.recipient)
</ins><span class="cx"> 
</span><ins>+            iTipProcessing._transferItems(to_component, transfer_partstat, details)
+
</ins><span class="cx">             # Check for incoming DECLINED
</span><del>-            to_attendee = to_component.getAttendeeProperty((recipient,))
</del><ins>+            to_attendee = to_component.getAttendeeProperty((details.recipient,))
</ins><span class="cx">             if to_attendee and to_attendee.parameterValue(&quot;PARTSTAT&quot;, &quot;NEEDS-ACTION&quot;) == &quot;DECLINED&quot;:
</span><span class="cx">                 # If existing item has HIDDEN property copy that over
</span><span class="cx">                 if matched.hasProperty(Component.HIDDEN_INSTANCE_PROPERTY):
</span><span class="lines">@@ -649,16 +660,14 @@
</span><span class="cx"> 
</span><span class="cx">             # Check to see if the new component is cancelled as that could mean we are copying in the wrong attendee state
</span><span class="cx">             if to_component.propertyValue(&quot;STATUS&quot;) == &quot;CANCELLED&quot;:
</span><del>-                if attendee and to_attendee:
-                    to_attendee.setParameter(&quot;PARTSTAT&quot;, attendee.parameterValue(&quot;PARTSTAT&quot;, &quot;NEEDS-ACTION&quot;))
</del><ins>+                if details.attendee and to_attendee:
+                    to_attendee.setParameter(&quot;PARTSTAT&quot;, details.attendee.parameterValue(&quot;PARTSTAT&quot;, &quot;NEEDS-ACTION&quot;))
</ins><span class="cx"> 
</span><span class="cx">         else:
</span><del>-            master_component = from_calendar.masterComponent()
-            seq_change = (Component.compareComponentsForITIP(to_component, master_component, use_dtstamp=False) &lt;= 0) if master_component is not None else True
-            iTipProcessing._transferItems(to_component, transfer_partstat and seq_change, valarms, private_comments, transps, completeds, organizer_schedule_status, attendee, attendee_dtstamp, other_props, recipient)
</del><ins>+            iTipProcessing._transferItems(to_component, transfer_partstat, master_details)
</ins><span class="cx"> 
</span><span class="cx">             # Check for incoming DECLINED
</span><del>-            attendee = to_component.getAttendeeProperty((recipient,))
</del><ins>+            attendee = to_component.getAttendeeProperty((master_details.recipient,))
</ins><span class="cx">             if attendee and attendee.parameterValue(&quot;PARTSTAT&quot;, &quot;NEEDS-ACTION&quot;) == &quot;DECLINED&quot;:
</span><span class="cx">                 return True
</span><span class="cx"> 
</span><span class="lines">@@ -666,7 +675,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @staticmethod
</span><del>-    def _transferItems(to_component, transfer_partstat, valarms, private_comments, transps, completeds, organizer_schedule_status, old_attendee, attendee_dtstamp, other_props, recipient):
</del><ins>+    def _transferItems(to_component, transfer_partstat, details):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Transfer properties the key per-attendee properties from one component to another. Note that the key properties are pulled out into separate items, because they
</span><span class="cx">         may have been derived from the master.
</span><span class="lines">@@ -675,22 +684,8 @@
</span><span class="cx">         @type to_component: L{Component}
</span><span class="cx">         @param partstat_change: whether not to transfer the old PARTSTAT over
</span><span class="cx">         @type partstat_change: C{bool}
</span><del>-        @param valarms: a C{list} of VALARM components from the old master to use
-        @type valarms: C{list}
-        @param private_comments: a C{list} of private comment properties from the old master to use
-        @type private_comments: C{list}
-        @param transps: a C{list} of TRANSP properties from the old master to use
-        @type transps: C{list}
-        @param completeds: a C{list} of COMPLETED properties from the old master to use
-        @type completeds: C{list}
-        @param organizer_schedule_status: a the SCHEDULE-STATUS value for the organizer from the old master to use
-        @type organizer_schedule_status: C{str}
-        @param attendee_dtstamp: an the ATTENDEE DTSTAMP parameter value from the old master to use
-        @type attendee_dtstamp: C{str}
-        @param other_props: other properties from the old master to use
-        @type other_props: C{list}
-        @param recipient: the calendar user address of the attendee whose data is being processed
-        @type recipient: C{str}
</del><ins>+        @param details: the L{TransferDetails} for the master component
+        @type details: L{TransferDetails}
</ins><span class="cx"> 
</span><span class="cx">         @return: C{True} if an EXDATE match occurred requiring the incoming component to be removed.
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="lines">@@ -702,29 +697,37 @@
</span><span class="cx">         to_component.removeProperty(&quot;X-CALENDARSERVER-PRIVATE-COMMENT&quot;)
</span><span class="cx">         to_component.removeProperty(&quot;TRANSP&quot;)
</span><span class="cx">         to_component.removeProperty(&quot;COMPLETED&quot;)
</span><del>-        for propname in other_props.keys():
</del><ins>+        for propname in details.other_props.keys():
</ins><span class="cx">             to_component.removeProperty(propname)
</span><span class="cx"> 
</span><del>-        [to_component.addComponent(alarm) for alarm in valarms]
-        [to_component.addProperty(comment) for comment in private_comments]
-        [to_component.replaceProperty(transp) for transp in transps]
-        [to_component.replaceProperty(completed) for completed in completeds]
-        for props in other_props.values():
</del><ins>+        [to_component.addComponent(alarm) for alarm in details.valarms]
+        [to_component.addProperty(comment) for comment in details.private_comments]
+        [to_component.replaceProperty(transp) for transp in details.transps]
+        [to_component.replaceProperty(completed) for completed in details.completeds]
+        for props in details.other_props.values():
</ins><span class="cx">             [to_component.replaceProperty(prop) for prop in props]
</span><span class="cx"> 
</span><del>-        if organizer_schedule_status:
</del><ins>+        if details.organizer_schedule_status:
</ins><span class="cx">             organizer = to_component.getProperty(&quot;ORGANIZER&quot;)
</span><span class="cx">             if organizer:
</span><del>-                organizer.setParameter(&quot;SCHEDULE-STATUS&quot;, organizer_schedule_status)
</del><ins>+                organizer.setParameter(&quot;SCHEDULE-STATUS&quot;, details.organizer_schedule_status)
</ins><span class="cx"> 
</span><span class="cx">         # ATTENDEE property merge
</span><del>-        attendee = to_component.getAttendeeProperty((recipient,))
-        if old_attendee and attendee and transfer_partstat:
-            iTipProcessing.mergePartStat(old_attendee, attendee)
</del><ins>+        attendee = to_component.getAttendeeProperty((details.recipient,))
</ins><span class="cx"> 
</span><del>-        if attendee_dtstamp and attendee:
-            attendee.setParameter(&quot;X-CALENDARSERVER-DTSTAMP&quot;, attendee_dtstamp)
</del><ins>+        # Handle explicit PARTSTAT reset by checking for the X-CALENDARSERVER-RESET-PARTSTAT parameter and
+        # comparing it to the sequence of the original component
+        if attendee:
+            reset_sequence = int(attendee.parameterValue(&quot;X-CALENDARSERVER-RESET-PARTSTAT&quot;, &quot;0&quot;))
+            if details.sequence &lt; reset_sequence:
+                transfer_partstat = False
</ins><span class="cx"> 
</span><ins>+        if details.attendee and attendee and transfer_partstat:
+            iTipProcessing.mergePartStat(details.attendee, attendee)
+
+        if details.attendee_dtstamp and attendee:
+            attendee.setParameter(&quot;X-CALENDARSERVER-DTSTAMP&quot;, details.attendee_dtstamp)
+
</ins><span class="cx">         return False
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -789,9 +792,7 @@
</span><span class="cx"> 
</span><span class="cx">         # If master component exists, compare all in iTIP and update if any are new
</span><span class="cx">         if cal_master:
</span><del>-            for itip_component in itip.subcomponents():
-                if itip_component.name() in ignoredComponents:
-                    continue
</del><ins>+            for itip_component in itip.subcomponents(ignore=True):
</ins><span class="cx">                 cal_component = calendar.overriddenComponent(itip_component.getRecurrenceIDUTC())
</span><span class="cx">                 if cal_component is None:
</span><span class="cx">                     cal_component = cal_master
</span><span class="lines">@@ -806,9 +807,7 @@
</span><span class="cx">         elif itip_master:
</span><span class="cx"> 
</span><span class="cx">             # Do comparison of each appropriate component if any one is new, process the itip
</span><del>-            for cal_component in calendar.subcomponents():
-                if cal_component.name() in ignoredComponents:
-                    continue
</del><ins>+            for cal_component in calendar.subcomponents(ignore=True):
</ins><span class="cx">                 itip_component = itip.overriddenComponent(cal_component.getRecurrenceIDUTC())
</span><span class="cx">                 if itip_component is None:
</span><span class="cx">                     itip_component = itip_master
</span><span class="lines">@@ -826,14 +825,10 @@
</span><span class="cx">             # that has been removed. Not much we can do about it without additional tracking.
</span><span class="cx"> 
</span><span class="cx">             cal_rids = set()
</span><del>-            for cal_component in calendar.subcomponents():
-                if cal_component.name() in ignoredComponents:
-                    continue
</del><ins>+            for cal_component in calendar.subcomponents(ignore=True):
</ins><span class="cx">                 cal_rids.add(cal_component.getRecurrenceIDUTC())
</span><span class="cx">             itip_rids = set()
</span><del>-            for itip_component in itip.subcomponents():
-                if itip_component.name() in ignoredComponents:
-                    continue
</del><ins>+            for itip_component in itip.subcomponents(ignore=True):
</ins><span class="cx">                 itip_rids.add(itip_component.getRecurrenceIDUTC())
</span><span class="cx"> 
</span><span class="cx">             # Compare ones that match
</span><span class="lines">@@ -902,8 +897,8 @@
</span><span class="cx">             # Add some required properties extracted from the original
</span><span class="cx">             comp.addProperty(Property(&quot;DTSTAMP&quot;, instance.propertyValue(&quot;DTSTAMP&quot;)))
</span><span class="cx">             comp.addProperty(Property(&quot;UID&quot;, instance.propertyValue(&quot;UID&quot;)))
</span><del>-            seq = instance.propertyValue(&quot;SEQUENCE&quot;)
-            seq = int(seq) + 1 if seq else 1
</del><ins>+            seq = instance.propertyValue(&quot;SEQUENCE&quot;, 0)
+            seq = seq + 1
</ins><span class="cx">             comp.addProperty(Property(&quot;SEQUENCE&quot;, seq))
</span><span class="cx">             comp.addProperty(instance.getOrganizerProperty())
</span><span class="cx">             if instance_rid:
</span><span class="lines">@@ -1020,9 +1015,7 @@
</span><span class="cx">         itip.removeAllButOneAttendee(attendee)
</span><span class="cx"> 
</span><span class="cx">         # Remove all components which are missing the attendee
</span><del>-        for component in itip.subcomponents():
-            if component.name() in ignoredComponents:
-                continue
</del><ins>+        for component in itip.subcomponents(ignore=True):
</ins><span class="cx">             if not component.getAttendeeProperty((attendee,)):
</span><span class="cx">                 itip.removeComponent(component)
</span><span class="cx"> 
</span><span class="lines">@@ -1083,9 +1076,7 @@
</span><span class="cx">         @type attendee: C{str}
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx"> 
</span><del>-        for component in tuple(vpoll.subcomponents()):
-            if component.name() in ignoredComponents:
-                continue
</del><ins>+        for component in tuple(vpoll.subcomponents(ignore=True)):
</ins><span class="cx">             poll_item_id = component.propertyValue(&quot;POLL-ITEM-ID&quot;)
</span><span class="cx">             if poll_item_id is None:
</span><span class="cx">                 continue
</span><span class="lines">@@ -1117,7 +1108,10 @@
</span><span class="cx">         else:
</span><span class="cx">             # Attendee properties that need to go to the Organizer
</span><span class="cx">             keep_properties = (&quot;X-CALENDARSERVER-PRIVATE-COMMENT&quot;,)
</span><del>-        itip.removeXProperties(keep_properties=keep_properties)
</del><ins>+        keep_parameters = {
+            &quot;ATTENDEE&quot;: set((&quot;X-CALENDARSERVER-RESET-PARTSTAT&quot;,)),
+        }
+        itip.removeXProperties(keep_properties=keep_properties, keep_parameters=keep_parameters)
</ins><span class="cx"> 
</span><span class="cx">         # Property Parameters
</span><span class="cx">         itip.removePropertyParameters(&quot;ATTENDEE&quot;, (&quot;SCHEDULE-AGENT&quot;, &quot;SCHEDULE-STATUS&quot;, &quot;SCHEDULE-FORCE-SEND&quot;, &quot;X-CALENDARSERVER-DTSTAMP&quot;,))
</span></span></pre></div>
<a id="CalendarServertrunktxdavcaldavdatastoreschedulingprocessingpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/caldav/datastore/scheduling/processing.py (14246 => 14247)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/caldav/datastore/scheduling/processing.py        2015-01-06 16:42:48 UTC (rev 14246)
+++ CalendarServer/trunk/txdav/caldav/datastore/scheduling/processing.py        2015-01-06 16:44:21 UTC (rev 14247)
</span><span class="lines">@@ -348,7 +348,7 @@
</span><span class="cx">     @inlineCallbacks
</span><span class="cx">     def doImplicitAttendeeUpdate(self):
</span><span class="cx">         &quot;&quot;&quot;
</span><del>-        An iTIP message has been sent by to an attendee by the organizer. We need to update the attendee state
</del><ins>+        An iTIP message has been sent to an attendee by the organizer. We need to update the attendee state
</ins><span class="cx">         based on the nature of the iTIP message.
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx"> 
</span></span></pre></div>
<a id="CalendarServertrunktxdavcaldavdatastoreschedulingtesttest_icaldiffpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/caldav/datastore/scheduling/test/test_icaldiff.py (14246 => 14247)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/caldav/datastore/scheduling/test/test_icaldiff.py        2015-01-06 16:42:48 UTC (rev 14246)
+++ CalendarServer/trunk/txdav/caldav/datastore/scheduling/test/test_icaldiff.py        2015-01-06 16:44:21 UTC (rev 14247)
</span><span class="lines">@@ -3542,6 +3542,7 @@
</span><span class="cx"> END:VCALENDAR
</span><span class="cx"> &quot;&quot;&quot;,
</span><span class="cx">                 {},
</span><ins>+                {},
</ins><span class="cx">             ),
</span><span class="cx">             (
</span><span class="cx">                 &quot;#1.2 Simple component, one property change&quot;,
</span><span class="lines">@@ -3568,6 +3569,7 @@
</span><span class="cx"> END:VCALENDAR
</span><span class="cx"> &quot;&quot;&quot;,
</span><span class="cx">                 {&quot;&quot;: {&quot;SUMMARY&quot;: set(), }},
</span><ins>+                {},
</ins><span class="cx">             ),
</span><span class="cx">             (
</span><span class="cx">                 &quot;#1.3 Simple component, one property change, one addition, one removal&quot;,
</span><span class="lines">@@ -3596,6 +3598,7 @@
</span><span class="cx"> END:VCALENDAR
</span><span class="cx"> &quot;&quot;&quot;,
</span><span class="cx">                 {&quot;&quot;: {&quot;SUMMARY&quot;: set(), &quot;LOCATION&quot;: set(), &quot;DESCRIPTION&quot;: set(), }},
</span><ins>+                {},
</ins><span class="cx">             ),
</span><span class="cx">             (
</span><span class="cx">                 &quot;#1.4 Simple component, add attendee&quot;,
</span><span class="lines">@@ -3629,6 +3632,7 @@
</span><span class="cx"> END:VCALENDAR
</span><span class="cx"> &quot;&quot;&quot;,
</span><span class="cx">                 {&quot;&quot;: {&quot;ATTENDEE&quot;: set(), }},
</span><ins>+                {&quot;&quot;: set((&quot;mailto:user3@example.com&quot;,))},
</ins><span class="cx">             ),
</span><span class="cx">             (
</span><span class="cx">                 &quot;#1.5 Simple component, remove attendee&quot;,
</span><span class="lines">@@ -3660,6 +3664,7 @@
</span><span class="cx"> END:VCALENDAR
</span><span class="cx"> &quot;&quot;&quot;,
</span><span class="cx">                 {&quot;&quot;: {&quot;ATTENDEE&quot;: set(), }},
</span><ins>+                {},
</ins><span class="cx">             ),
</span><span class="cx">             (
</span><span class="cx">                 &quot;#1.6 Simple component, attendee PARTSTAT only&quot;,
</span><span class="lines">@@ -3692,8 +3697,42 @@
</span><span class="cx"> END:VCALENDAR
</span><span class="cx"> &quot;&quot;&quot;,
</span><span class="cx">                 {&quot;&quot;: {&quot;ATTENDEE&quot;: set(), }},
</span><ins>+                {},
</ins><span class="cx">             ),
</span><span class="cx">             (
</span><ins>+                &quot;#1.6a Simple component, attendee PARTSTAT-&gt;NEEDS-ACTION only&quot;,
+                &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890
+DTSTART:20080601T120000Z
+DTEND:20080601T130000Z
+SUMMARY:Test
+ORGANIZER;CN=&quot;User 01&quot;:mailto:user1@example.com
+ATTENDEE:mailto:user1@example.com
+ATTENDEE;PARTSTAT=&quot;ACCEPTED&quot;:mailto:user2@example.com
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;,
+                &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890
+DTSTART:20080601T120000Z
+DTEND:20080601T130000Z
+SUMMARY:Test
+ORGANIZER;CN=&quot;User 01&quot;:mailto:user1@example.com
+ATTENDEE:mailto:user1@example.com
+ATTENDEE:mailto:user2@example.com
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;,
+                {&quot;&quot;: {&quot;ATTENDEE&quot;: set(), }},
+                {&quot;&quot;: set((&quot;mailto:user2@example.com&quot;,))},
+            ),
+            (
</ins><span class="cx">                 &quot;#1.7 Simple component, attendee PARTSTAT and addition&quot;,
</span><span class="cx">                 &quot;&quot;&quot;BEGIN:VCALENDAR
</span><span class="cx"> VERSION:2.0
</span><span class="lines">@@ -3725,8 +3764,43 @@
</span><span class="cx"> END:VCALENDAR
</span><span class="cx"> &quot;&quot;&quot;,
</span><span class="cx">                 {&quot;&quot;: {&quot;ATTENDEE&quot;: set(), }},
</span><ins>+                {&quot;&quot;: set((&quot;mailto:user3@example.com&quot;,))},
</ins><span class="cx">             ),
</span><span class="cx">             (
</span><ins>+                &quot;#1.7a Simple component, attendee PARTSTAT-&gt;NEEDS-ACTION and addition&quot;,
+                &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890
+DTSTART:20080601T120000Z
+DTEND:20080601T130000Z
+SUMMARY:Test
+ORGANIZER;CN=&quot;User 01&quot;:mailto:user1@example.com
+ATTENDEE:mailto:user1@example.com
+ATTENDEE;PARTSTAT=&quot;ACCEPTED&quot;:mailto:user2@example.com
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;,
+                &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890
+DTSTART:20080601T120000Z
+DTEND:20080601T130000Z
+SUMMARY:Test
+ORGANIZER;CN=&quot;User 01&quot;:mailto:user1@example.com
+ATTENDEE:mailto:user1@example.com
+ATTENDEE:mailto:user2@example.com
+ATTENDEE:mailto:user3@example.com
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;,
+                {&quot;&quot;: {&quot;ATTENDEE&quot;: set(), }},
+                {&quot;&quot;: set((&quot;mailto:user2@example.com&quot;, &quot;mailto:user3@example.com&quot;,))},
+            ),
+            (
</ins><span class="cx">                 &quot;#1.8 Simple component, attendee RSVP only&quot;,
</span><span class="cx">                 &quot;&quot;&quot;BEGIN:VCALENDAR
</span><span class="cx"> VERSION:2.0
</span><span class="lines">@@ -3757,6 +3831,7 @@
</span><span class="cx"> END:VCALENDAR
</span><span class="cx"> &quot;&quot;&quot;,
</span><span class="cx">                 {&quot;&quot;: {&quot;ATTENDEE&quot;: set(), }},
</span><ins>+                {},
</ins><span class="cx">             ),
</span><span class="cx">             (
</span><span class="cx">                 &quot;#1.9 Simple component, DTSTART/DTEND VALUE&quot;,
</span><span class="lines">@@ -3789,6 +3864,7 @@
</span><span class="cx"> END:VCALENDAR
</span><span class="cx"> &quot;&quot;&quot;,
</span><span class="cx">                 {&quot;&quot;: {&quot;DTEND&quot;: set((&quot;VALUE&quot;,)), &quot;DTSTART&quot;: set((&quot;VALUE&quot;,)), }},
</span><ins>+                {},
</ins><span class="cx">             ),
</span><span class="cx">             (
</span><span class="cx">                 &quot;#1.10 Simple component, DTSTART/DTEND TZID&quot;,
</span><span class="lines">@@ -3857,6 +3933,7 @@
</span><span class="cx"> END:VCALENDAR
</span><span class="cx"> &quot;&quot;&quot;,
</span><span class="cx">                 {&quot;&quot;: {&quot;DTEND&quot;: set((&quot;TZID&quot;,)), &quot;DTSTART&quot;: set((&quot;TZID&quot;,)), }},
</span><ins>+                {},
</ins><span class="cx">             ),
</span><span class="cx">         )
</span><span class="cx"> 
</span><span class="lines">@@ -3894,6 +3971,7 @@
</span><span class="cx"> END:VCALENDAR
</span><span class="cx"> &quot;&quot;&quot;,
</span><span class="cx">                 {},
</span><ins>+                {},
</ins><span class="cx">             ),
</span><span class="cx">             (
</span><span class="cx">                 &quot;#2.2 Simple component, one property change&quot;,
</span><span class="lines">@@ -3922,6 +4000,7 @@
</span><span class="cx"> END:VCALENDAR
</span><span class="cx"> &quot;&quot;&quot;,
</span><span class="cx">                 {&quot;&quot;: {&quot;SUMMARY&quot;: set(), }},
</span><ins>+                {},
</ins><span class="cx">             ),
</span><span class="cx">             (
</span><span class="cx">                 &quot;#2.3 Simple component, one property change, one addition, one removal&quot;,
</span><span class="lines">@@ -3952,6 +4031,7 @@
</span><span class="cx"> END:VCALENDAR
</span><span class="cx"> &quot;&quot;&quot;,
</span><span class="cx">                 {&quot;&quot;: {&quot;SUMMARY&quot;: set(), &quot;LOCATION&quot;: set(), &quot;DESCRIPTION&quot;: set(), }},
</span><ins>+                {},
</ins><span class="cx">             ),
</span><span class="cx">             (
</span><span class="cx">                 &quot;#2.4 Simple component, add attendee&quot;,
</span><span class="lines">@@ -3987,6 +4067,7 @@
</span><span class="cx"> END:VCALENDAR
</span><span class="cx"> &quot;&quot;&quot;,
</span><span class="cx">                 {&quot;&quot;: {&quot;ATTENDEE&quot;: set(), }},
</span><ins>+                {&quot;&quot;: set((&quot;mailto:user3@example.com&quot;,))},
</ins><span class="cx">             ),
</span><span class="cx">             (
</span><span class="cx">                 &quot;#2.5 Simple component, remove attendee&quot;,
</span><span class="lines">@@ -4020,6 +4101,7 @@
</span><span class="cx"> END:VCALENDAR
</span><span class="cx"> &quot;&quot;&quot;,
</span><span class="cx">                 {&quot;&quot;: {&quot;ATTENDEE&quot;: set(), }},
</span><ins>+                {},
</ins><span class="cx">             ),
</span><span class="cx">             (
</span><span class="cx">                 &quot;#2.6 Simple component, attendee PARTSTAT only&quot;,
</span><span class="lines">@@ -4054,8 +4136,44 @@
</span><span class="cx"> END:VCALENDAR
</span><span class="cx"> &quot;&quot;&quot;,
</span><span class="cx">                 {&quot;&quot;: {&quot;ATTENDEE&quot;: set(), }},
</span><ins>+                {},
</ins><span class="cx">             ),
</span><span class="cx">             (
</span><ins>+                &quot;#2.6a Simple component, attendee PARTSTAT-&gt;NEEDS-ACTION only&quot;,
+                &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890
+DTSTART:20080601T120000Z
+DTEND:20080601T130000Z
+SUMMARY:Test
+ORGANIZER;CN=&quot;User 01&quot;:mailto:user1@example.com
+ATTENDEE:mailto:user1@example.com
+ATTENDEE;PARTSTAT=&quot;ACCEPTED&quot;:mailto:user2@example.com
+RRULE:COUNT=400;FREQ=DAILY
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;,
+                &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890
+DTSTART:20080601T120000Z
+DTEND:20080601T130000Z
+SUMMARY:Test
+ORGANIZER;CN=&quot;User 01&quot;:mailto:user1@example.com
+ATTENDEE:mailto:user1@example.com
+ATTENDEE:mailto:user2@example.com
+RRULE:COUNT=400;FREQ=DAILY
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;,
+                {&quot;&quot;: {&quot;ATTENDEE&quot;: set(), }},
+                {&quot;&quot;: set((&quot;mailto:user2@example.com&quot;,))},
+            ),
+            (
</ins><span class="cx">                 &quot;#2.7 Simple component, attendee PARTSTAT and addition&quot;,
</span><span class="cx">                 &quot;&quot;&quot;BEGIN:VCALENDAR
</span><span class="cx"> VERSION:2.0
</span><span class="lines">@@ -4089,8 +4207,45 @@
</span><span class="cx"> END:VCALENDAR
</span><span class="cx"> &quot;&quot;&quot;,
</span><span class="cx">                 {&quot;&quot;: {&quot;ATTENDEE&quot;: set(), }},
</span><ins>+                {&quot;&quot;: set((&quot;mailto:user3@example.com&quot;,))},
</ins><span class="cx">             ),
</span><span class="cx">             (
</span><ins>+                &quot;#2.7a Simple component, attendee PARTSTAT-&gt;NEEDS-ACTION and addition&quot;,
+                &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890
+DTSTART:20080601T120000Z
+DTEND:20080601T130000Z
+SUMMARY:Test
+ORGANIZER;CN=&quot;User 01&quot;:mailto:user1@example.com
+ATTENDEE:mailto:user1@example.com
+ATTENDEE;PARTSTAT=&quot;ACCEPTED&quot;:mailto:user2@example.com
+RRULE:COUNT=400;FREQ=DAILY
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;,
+                &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890
+DTSTART:20080601T120000Z
+DTEND:20080601T130000Z
+SUMMARY:Test
+ORGANIZER;CN=&quot;User 01&quot;:mailto:user1@example.com
+ATTENDEE:mailto:user1@example.com
+ATTENDEE:mailto:user2@example.com
+ATTENDEE:mailto:user3@example.com
+RRULE:COUNT=400;FREQ=DAILY
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;,
+                {&quot;&quot;: {&quot;ATTENDEE&quot;: set(), }},
+                {&quot;&quot;: set((&quot;mailto:user2@example.com&quot;, &quot;mailto:user3@example.com&quot;,))},
+            ),
+            (
</ins><span class="cx">                 &quot;#2.8 Simple recurring component, property order change&quot;,
</span><span class="cx">                 &quot;&quot;&quot;BEGIN:VCALENDAR
</span><span class="cx"> VERSION:2.0
</span><span class="lines">@@ -4127,6 +4282,7 @@
</span><span class="cx"> END:VCALENDAR
</span><span class="cx"> &quot;&quot;&quot;,
</span><span class="cx">                 {},
</span><ins>+                {},
</ins><span class="cx">             ),
</span><span class="cx">         )
</span><span class="cx"> 
</span><span class="lines">@@ -4184,6 +4340,7 @@
</span><span class="cx"> END:VCALENDAR
</span><span class="cx"> &quot;&quot;&quot;,
</span><span class="cx">                 {},
</span><ins>+                {},
</ins><span class="cx">             ),
</span><span class="cx">             (
</span><span class="cx">                 &quot;#3.2 Simple component, one property change in instance&quot;,
</span><span class="lines">@@ -4232,6 +4389,7 @@
</span><span class="cx"> END:VCALENDAR
</span><span class="cx"> &quot;&quot;&quot;,
</span><span class="cx">                 {&quot;20080602T120000Z&quot;: {&quot;SUMMARY&quot;: set(), }},
</span><ins>+                {},
</ins><span class="cx">             ),
</span><span class="cx">             (
</span><span class="cx">                 &quot;#3.3 Simple component, one property change in master&quot;,
</span><span class="lines">@@ -4280,6 +4438,7 @@
</span><span class="cx"> END:VCALENDAR
</span><span class="cx"> &quot;&quot;&quot;,
</span><span class="cx">                 {&quot;&quot;: {&quot;SUMMARY&quot;: set(), }},
</span><ins>+                {},
</ins><span class="cx">             ),
</span><span class="cx">             (
</span><span class="cx">                 &quot;#3.4 Simple component, one property change in master and instance&quot;,
</span><span class="lines">@@ -4328,6 +4487,7 @@
</span><span class="cx"> END:VCALENDAR
</span><span class="cx"> &quot;&quot;&quot;,
</span><span class="cx">                 {&quot;&quot;: {&quot;SUMMARY&quot;: set(), }, &quot;20080602T120000Z&quot;: {&quot;SUMMARY&quot;: set(), }},
</span><ins>+                {},
</ins><span class="cx">             ),
</span><span class="cx">             (
</span><span class="cx">                 &quot;#3.5 Simple component, different property change in master and instance&quot;,
</span><span class="lines">@@ -4377,6 +4537,7 @@
</span><span class="cx"> END:VCALENDAR
</span><span class="cx"> &quot;&quot;&quot;,
</span><span class="cx">                 {&quot;&quot;: {&quot;SUMMARY&quot;: set()}, &quot;20080602T120000Z&quot;: {&quot;Description&quot;: set()}},
</span><ins>+                {},
</ins><span class="cx">             ),
</span><span class="cx">             (
</span><span class="cx">                 &quot;#3.6 Simple component, instance added no change&quot;,
</span><span class="lines">@@ -4412,6 +4573,7 @@
</span><span class="cx"> END:VCALENDAR
</span><span class="cx"> &quot;&quot;&quot;,
</span><span class="cx">                 {},
</span><ins>+                {},
</ins><span class="cx">             ),
</span><span class="cx">             (
</span><span class="cx">                 &quot;#3.7 Simple component, instance added time change&quot;,
</span><span class="lines">@@ -4447,6 +4609,7 @@
</span><span class="cx"> END:VCALENDAR
</span><span class="cx"> &quot;&quot;&quot;,
</span><span class="cx">                 {&quot;20080602T120000Z&quot;: {&quot;DTSTART&quot;: set(), &quot;DTEND&quot;: set(), }},
</span><ins>+                {},
</ins><span class="cx">             ),
</span><span class="cx">             (
</span><span class="cx">                 &quot;#3.8 Simple component, instance removed no change&quot;,
</span><span class="lines">@@ -4482,6 +4645,7 @@
</span><span class="cx"> END:VCALENDAR
</span><span class="cx"> &quot;&quot;&quot;,
</span><span class="cx">                 {},
</span><ins>+                {},
</ins><span class="cx">             ),
</span><span class="cx">             (
</span><span class="cx">                 &quot;#3.9 Simple component, instance removed time change&quot;,
</span><span class="lines">@@ -4517,6 +4681,7 @@
</span><span class="cx"> END:VCALENDAR
</span><span class="cx"> &quot;&quot;&quot;,
</span><span class="cx">                 {&quot;20080602T120000Z&quot;: {&quot;DTSTART&quot;: set(), &quot;DTEND&quot;: set(), }},
</span><ins>+                {},
</ins><span class="cx">             ),
</span><span class="cx">         )
</span><span class="cx"> 
</span><span class="lines">@@ -4555,6 +4720,7 @@
</span><span class="cx"> END:VCALENDAR
</span><span class="cx"> &quot;&quot;&quot;,
</span><span class="cx">                 {},
</span><ins>+                {},
</ins><span class="cx">             ),
</span><span class="cx">             (
</span><span class="cx">                 &quot;#4.2 Override component added&quot;,
</span><span class="lines">@@ -4590,6 +4756,7 @@
</span><span class="cx"> END:VCALENDAR
</span><span class="cx"> &quot;&quot;&quot;,
</span><span class="cx">                 {},
</span><ins>+                {},
</ins><span class="cx">             ),
</span><span class="cx">         )
</span><span class="cx"> 
</span><span class="lines">@@ -4628,6 +4795,7 @@
</span><span class="cx"> END:VCALENDAR
</span><span class="cx"> &quot;&quot;&quot;,
</span><span class="cx">                 {&quot;20080602T120000Z&quot;: {&quot;DTSTART&quot;: set()}},
</span><ins>+                {},
</ins><span class="cx">             ),
</span><span class="cx">             (
</span><span class="cx">                 &quot;#5.2 Override component added&quot;,
</span><span class="lines">@@ -4663,19 +4831,23 @@
</span><span class="cx"> END:VCALENDAR
</span><span class="cx"> &quot;&quot;&quot;,
</span><span class="cx">                 {&quot;20080602T120000Z&quot;: {&quot;DTSTART&quot;: set()}},
</span><ins>+                {},
</ins><span class="cx">             ),
</span><span class="cx">         )
</span><span class="cx"> 
</span><del>-        for description, calendar1, calendar2, rids in itertools.chain(data1, data2, data3, data4,):
</del><ins>+        for description, calendar1, calendar2, rids, changes in itertools.chain(data1, data2, data3, data4,):
</ins><span class="cx">             differ = iCalDiff(Component.fromString(calendar1), Component.fromString(calendar2), False)
</span><del>-            got_rids = differ.whatIsDifferent()
</del><ins>+            got_rids, got_changes = differ.whatIsDifferent()
</ins><span class="cx">             rids = dict([(DateTime.parseText(k) if k else None, v) for k, v in rids.items()])
</span><ins>+            changes = dict([(DateTime.parseText(k) if k else None, v) for k, v in changes.items()])
</ins><span class="cx">             self.assertEqual(got_rids, rids, msg=&quot;%s expected R-IDs: '%s', got: '%s'&quot; % (description, rids, got_rids,))
</span><ins>+            self.assertEqual(got_changes, changes, msg=&quot;%s expected changes R-IDs: '%s', got: '%s'&quot; % (description, changes, got_changes,))
</ins><span class="cx"> 
</span><del>-        for description, calendar1, calendar2, rids in itertools.chain(data5,):
</del><ins>+        for description, calendar1, calendar2, rids, changes in itertools.chain(data5,):
</ins><span class="cx">             differ = iCalDiff(Component.fromString(calendar1), Component.fromString(calendar2), False)
</span><del>-            got_rids = differ.whatIsDifferent(isiTip=False)
</del><ins>+            got_rids, got_changes = differ.whatIsDifferent(isiTip=False)
</ins><span class="cx">             self.assertEqual(got_rids, rids, msg=&quot;%s expected R-IDs: '%s', got: '%s'&quot; % (description, rids, got_rids,))
</span><ins>+            self.assertEqual(got_changes, changes, msg=&quot;%s expected changes R-IDs: '%s', got: '%s'&quot; % (description, changes, got_changes,))
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def test_attendee_needs_action(self):
</span><span class="lines">@@ -5241,7 +5413,7 @@
</span><span class="cx"> 
</span><span class="cx">         for description, calendar1, calendar2, rids, rescheduled in data:
</span><span class="cx">             differ = iCalDiff(Component.fromString(calendar1), Component.fromString(calendar2), False)
</span><del>-            diffs = differ.whatIsDifferent()
</del><ins>+            diffs, _ignore_changes = differ.whatIsDifferent()
</ins><span class="cx">             got_rids, got_rescheduled = differ.attendeeNeedsAction(diffs)
</span><span class="cx">             rids = set([DateTime.parseText(k) if k else None for k in rids])
</span><span class="cx">             self.assertEqual(got_rids, rids, msg=&quot;%s expected R-IDs: '%s', got: '%s'&quot; % (description, rids, got_rids,))
</span></span></pre></div>
<a id="CalendarServertrunktxdavcaldavdatastoreschedulingtesttest_itippy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/caldav/datastore/scheduling/test/test_itip.py (14246 => 14247)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/caldav/datastore/scheduling/test/test_itip.py        2015-01-06 16:42:48 UTC (rev 14246)
+++ CalendarServer/trunk/txdav/caldav/datastore/scheduling/test/test_itip.py        2015-01-06 16:44:21 UTC (rev 14247)
</span><span class="lines">@@ -115,16 +115,214 @@
</span><span class="cx"> END:VEVENT
</span><span class="cx"> END:VCALENDAR
</span><span class="cx"> &quot;&quot;&quot;,
</span><ins>+                0,
</ins><span class="cx">             ),
</span><ins>+            (
+                &quot;2.1 partstat change pinned to sequence - changed&quot;,
+                &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890-1
+DTSTART:20071114T010000Z
+DURATION:PT1H
+DTSTAMP:20071114T000000Z
+ATTENDEE:mailto:user01@example.com
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:user02@example.com
+ORGANIZER:mailto:user01@example.com
+SEQUENCE:1
+SUMMARY:Test - override
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;,
+                &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+METHOD:REQUEST
+BEGIN:VEVENT
+UID:12345-67890-1
+DTSTART:20071114T010000Z
+DURATION:PT1H
+DTSTAMP:20071114T000000Z
+ATTENDEE:mailto:user01@example.com
+ATTENDEE;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;X-CALENDARSERVER-RESET-PARTSTAT=2:mailto:user02@example.com
+ORGANIZER:mailto:user01@example.com
+SEQUENCE:2
+SUMMARY:Test - override
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;,
+                &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890-1
+DTSTART:20071114T010000Z
+DURATION:PT1H
+DTSTAMP:20071114T000000Z
+ATTENDEE:mailto:user01@example.com
+ATTENDEE;PARTSTAT=NEEDS-ACTION;RSVP=TRUE:mailto:user02@example.com
+ORGANIZER:mailto:user01@example.com
+SEQUENCE:2
+SUMMARY:Test - override
+TRANSP:TRANSPARENT
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;,
+                1,
+            ),
+            (
+                &quot;2.2 partstat change pinned to sequence - not changed&quot;,
+                &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890-1
+DTSTART:20071114T010000Z
+DURATION:PT1H
+DTSTAMP:20071114T000000Z
+ATTENDEE:mailto:user01@example.com
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:user02@example.com
+ORGANIZER:mailto:user01@example.com
+SEQUENCE:1
+SUMMARY:Test - override
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;,
+                &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+METHOD:REQUEST
+BEGIN:VEVENT
+UID:12345-67890-1
+DTSTART:20071114T010000Z
+DURATION:PT1H
+DTSTAMP:20071114T000000Z
+ATTENDEE:mailto:user01@example.com
+ATTENDEE;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;X-CALENDARSERVER-RESET-PARTSTAT=1:mailto:user02@example.com
+ORGANIZER:mailto:user01@example.com
+SEQUENCE:1
+SUMMARY:Test - override
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;,
+                &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890-1
+DTSTART:20071114T010000Z
+DURATION:PT1H
+DTSTAMP:20071114T000000Z
+ATTENDEE:mailto:user01@example.com
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:user02@example.com
+ORGANIZER:mailto:user01@example.com
+SEQUENCE:1
+SUMMARY:Test - override
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;,
+                1,
+            ),
+            (
+                &quot;3.1 partstat change pinned to sequence - with recurrence override&quot;,
+                &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890-1
+DTSTART:20071114T010000Z
+DURATION:PT1H
+DTSTAMP:20071114T000000Z
+ATTENDEE:mailto:user01@example.com
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:user02@example.com
+ORGANIZER:mailto:user01@example.com
+SUMMARY:Test - override
+RRULE:FREQ=DAILY
+END:VEVENT
+BEGIN:VEVENT
+UID:12345-67890-1
+RECURRENCE-ID:20071115T010000Z
+DTSTART:20071115T010000Z
+DURATION:PT1H
+DTSTAMP:20071114T000000Z
+ATTENDEE:mailto:user01@example.com
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:user02@example.com
+ORGANIZER:mailto:user01@example.com
+SUMMARY:Test
+BEGIN:VALARM
+DESCRIPTION:Event reminder
+TRIGGER:-PT1M
+ACTION:DISPLAY
+END:VALARM
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;,
+                &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+METHOD:REQUEST
+BEGIN:VEVENT
+UID:12345-67890-1
+DTSTART:20071114T010000Z
+DURATION:PT1H
+DTSTAMP:20071114T000000Z
+ATTENDEE:mailto:user01@example.com
+ATTENDEE;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;X-CALENDARSERVER-RESET-PARTSTAT=1:mailto:user02@example.com
+ORGANIZER:mailto:user01@example.com
+RRULE:FREQ=DAILY
+SEQUENCE:1
+SUMMARY:Test - override
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;,
+                &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890-1
+DTSTART:20071114T010000Z
+DURATION:PT1H
+DTSTAMP:20071114T000000Z
+ATTENDEE:mailto:user01@example.com
+ATTENDEE;PARTSTAT=NEEDS-ACTION;RSVP=TRUE:mailto:user02@example.com
+RRULE:FREQ=DAILY
+ORGANIZER:mailto:user01@example.com
+SEQUENCE:1
+SUMMARY:Test - override
+TRANSP:TRANSPARENT
+END:VEVENT
+BEGIN:VEVENT
+UID:12345-67890-1
+RECURRENCE-ID:20071115T010000Z
+DTSTART:20071115T010000Z
+DURATION:PT1H
+DTSTAMP:20071114T000000Z
+ATTENDEE:mailto:user01@example.com
+ATTENDEE;PARTSTAT=NEEDS-ACTION;RSVP=TRUE:mailto:user02@example.com
+ORGANIZER:mailto:user01@example.com
+SEQUENCE:1
+SUMMARY:Test - override
+TRANSP:TRANSPARENT
+BEGIN:VALARM
+DESCRIPTION:Event reminder
+TRIGGER:-PT1M
+ACTION:DISPLAY
+END:VALARM
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;,
+                2,
+            ),
</ins><span class="cx">         )
</span><span class="cx"> 
</span><del>-        for title, calendar_txt, itip_txt, changed_txt in data:
</del><ins>+        for title, calendar_txt, itip_txt, changed_txt, changed_rid_count in data:
</ins><span class="cx">             calendar = Component.fromString(calendar_txt)
</span><span class="cx">             itip = Component.fromString(itip_txt)
</span><span class="cx">             changed = Component.fromString(changed_txt)
</span><span class="cx"> 
</span><span class="cx">             result, rids = iTipProcessing.processRequest(itip, calendar, &quot;mailto:user02@example.com&quot;)
</span><del>-            self.assertEqual(len(rids), 0)
</del><ins>+            self.assertEqual(len(rids), changed_rid_count, msg=&quot;Rids mismatch: %s&quot; % (title,))
</ins><span class="cx">             self.assertEqual(result, changed, msg=&quot;Calendar mismatch: %s&quot; % (title,))
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -1393,6 +1591,190 @@
</span><span class="cx"> &quot;&quot;&quot;,
</span><span class="cx">                 True,
</span><span class="cx">             ),
</span><ins>+            (
+                &quot;2.1 X-CALENDARSERVER-RESET-PARTSTAT Reply - non recurring&quot;,
+                &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890-1
+DTSTART:20071114T000000Z
+DTSTAMP:20071114T000000Z
+ORGANIZER:mailto:user01@example.com
+ATTENDEE:mailto:user01@example.com
+ATTENDEE;X-CALENDARSERVER-RESET-PARTSTAT=10;PARTSTAT=NEEDS-ACTION:mailto:user02@example.com
+SEQUENCE:10
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;,
+                &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+METHOD:REPLY
+BEGIN:VEVENT
+UID:12345-67890-1
+DTSTART:20071115T000000Z
+DTSTAMP:20071114T000000Z
+ORGANIZER:mailto:user01@example.com
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:user02@example.com
+SEQUENCE:9
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;,
+                &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890-1
+DTSTART:20071114T000000Z
+DTSTAMP:20071114T000000Z
+ORGANIZER:mailto:user01@example.com
+ATTENDEE:mailto:user01@example.com
+ATTENDEE;X-CALENDARSERVER-RESET-PARTSTAT=10;PARTSTAT=NEEDS-ACTION:mailto:user02@example.com
+SEQUENCE:10
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;,
+                True,
+            ),
+            (
+                &quot;2.2 X-CALENDARSERVER-RESET-PARTSTAT Reply - non recurring&quot;,
+                &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890-1
+DTSTART:20071114T000000Z
+DTSTAMP:20071114T000000Z
+ORGANIZER:mailto:user01@example.com
+ATTENDEE:mailto:user01@example.com
+ATTENDEE;X-CALENDARSERVER-RESET-PARTSTAT=10;PARTSTAT=NEEDS-ACTION:mailto:user02@example.com
+SEQUENCE:10
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;,
+                &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+METHOD:REPLY
+BEGIN:VEVENT
+UID:12345-67890-1
+DTSTART:20071115T000000Z
+DTSTAMP:20071114T000000Z
+ORGANIZER:mailto:user01@example.com
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:user02@example.com
+SEQUENCE:10
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;,
+                &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890-1
+DTSTART:20071114T000000Z
+DTSTAMP:20071114T000000Z
+ORGANIZER:mailto:user01@example.com
+ATTENDEE:mailto:user01@example.com
+ATTENDEE;X-CALENDARSERVER-RESET-PARTSTAT=10;PARTSTAT=ACCEPTED;SCHEDULE-STATUS=2.0:mailto:user02@example.com
+SEQUENCE:10
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;,
+                True,
+            ),
+            (
+                &quot;2.3 X-CALENDARSERVER-RESET-PARTSTAT Reply - non recurring&quot;,
+                &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890-1
+DTSTART:20071114T000000Z
+DTSTAMP:20071114T000000Z
+ORGANIZER:mailto:user01@example.com
+ATTENDEE:mailto:user01@example.com
+ATTENDEE;X-CALENDARSERVER-RESET-PARTSTAT=9;PARTSTAT=NEEDS-ACTION:mailto:user02@example.com
+SEQUENCE:10
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;,
+                &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+METHOD:REPLY
+BEGIN:VEVENT
+UID:12345-67890-1
+DTSTART:20071115T000000Z
+DTSTAMP:20071114T000000Z
+ORGANIZER:mailto:user01@example.com
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:user02@example.com
+SEQUENCE:9
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;,
+                &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890-1
+DTSTART:20071114T000000Z
+DTSTAMP:20071114T000000Z
+ORGANIZER:mailto:user01@example.com
+ATTENDEE:mailto:user01@example.com
+ATTENDEE;X-CALENDARSERVER-RESET-PARTSTAT=9;PARTSTAT=ACCEPTED;SCHEDULE-STATUS=2.0:mailto:user02@example.com
+SEQUENCE:10
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;,
+                True,
+            ),
+            (
+                &quot;2.4 X-CALENDARSERVER-RESET-PARTSTAT Reply - non recurring&quot;,
+                &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890-1
+DTSTART:20071114T000000Z
+DTSTAMP:20071114T000000Z
+ORGANIZER:mailto:user01@example.com
+ATTENDEE:mailto:user01@example.com
+ATTENDEE;X-CALENDARSERVER-RESET-PARTSTAT=9;PARTSTAT=NEEDS-ACTION:mailto:user02@example.com
+SEQUENCE:10
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;,
+                &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+METHOD:REPLY
+BEGIN:VEVENT
+UID:12345-67890-1
+DTSTART:20071115T000000Z
+DTSTAMP:20071114T000000Z
+ORGANIZER:mailto:user01@example.com
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:user02@example.com
+SEQUENCE:10
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;,
+                &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890-1
+DTSTART:20071114T000000Z
+DTSTAMP:20071114T000000Z
+ORGANIZER:mailto:user01@example.com
+ATTENDEE:mailto:user01@example.com
+ATTENDEE;X-CALENDARSERVER-RESET-PARTSTAT=9;PARTSTAT=ACCEPTED;SCHEDULE-STATUS=2.0:mailto:user02@example.com
+SEQUENCE:10
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;,
+                True,
+            ),
</ins><span class="cx">         )
</span><span class="cx"> 
</span><span class="cx">         for title, calendar_txt, itip_txt, changed_txt, expected in data:
</span></span></pre></div>
<a id="CalendarServertrunktxdavcaldavdatastoreschedulingtesttest_workpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/caldav/datastore/scheduling/test/test_work.py (14246 => 14247)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/caldav/datastore/scheduling/test/test_work.py        2015-01-06 16:42:48 UTC (rev 14246)
+++ CalendarServer/trunk/txdav/caldav/datastore/scheduling/test/test_work.py        2015-01-06 16:44:21 UTC (rev 14247)
</span><span class="lines">@@ -13,7 +13,7 @@
</span><span class="cx"> # See the License for the specific language governing permissions and
</span><span class="cx"> # limitations under the License.
</span><span class="cx"> ##
</span><del>-from twistedcaldav.ical import Component
</del><ins>+from twistedcaldav.ical import Component, diff_iCalStrs, normalize_iCalStr
</ins><span class="cx"> from twext.enterprise.jobqueue import JobItem, WorkItem
</span><span class="cx"> from txdav.common.datastore.sql_tables import scheduleActionFromSQL
</span><span class="cx"> from twisted.internet import reactor
</span><span class="lines">@@ -22,7 +22,7 @@
</span><span class="cx"> Tests for txdav.caldav.datastore.utils
</span><span class="cx"> &quot;&quot;&quot;
</span><span class="cx"> 
</span><del>-from twisted.internet.defer import inlineCallbacks
</del><ins>+from twisted.internet.defer import inlineCallbacks, returnValue
</ins><span class="cx"> from twisted.trial import unittest
</span><span class="cx"> 
</span><span class="cx"> from txdav.caldav.datastore.scheduling.work import ScheduleOrganizerWork, \
</span><span class="lines">@@ -77,7 +77,115 @@
</span><span class="cx">         return self._sqlCalendarStore
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    @inlineCallbacks
+    def _runAllJobs(self):
+        &quot;&quot;&quot;
+        Run all outstanding jobs.
+        &quot;&quot;&quot;
+        # Run jobs
+        jobs = yield JobItem.all(self.transactionUnderTest())
+        while jobs:
+            yield jobs[0].run()
+            yield self.commit()
+            jobs = yield JobItem.all(self.transactionUnderTest())
+        yield self.commit()
</ins><span class="cx"> 
</span><ins>+
+    @inlineCallbacks
+    def _runOneJob(self):
+        &quot;&quot;&quot;
+        Run the first outstanding jobs.
+        &quot;&quot;&quot;
+        # Run jobs
+        jobs = yield JobItem.all(self.transactionUnderTest())
+        for job in jobs:
+            yield job.run()
+            break
+        yield self.commit()
+
+
+    @inlineCallbacks
+    def createOrganizerEvent(self, organizer, ical, run_jobs=True):
+        &quot;&quot;&quot;
+        Create an organizer event and wait for the jobs to complete.
+        &quot;&quot;&quot;
+        cal = yield self.calendarUnderTest(name=&quot;calendar&quot;, home=organizer)
+        yield cal.createCalendarObjectWithName(&quot;invite.ics&quot;, ical)
+        yield self.commit()
+
+        if run_jobs:
+            yield self._runAllJobs()
+
+
+    @inlineCallbacks
+    def getOrganizerResource(self, organizer):
+        &quot;&quot;&quot;
+        Get the attendee's event.
+        &quot;&quot;&quot;
+        calobj = yield self.calendarObjectUnderTest(name=&quot;invite.ics&quot;, calendar_name=&quot;calendar&quot;, home=organizer)
+        returnValue(calobj)
+
+
+    @inlineCallbacks
+    def setOrganizerEvent(self, organizer, ical, run_jobs=True):
+        &quot;&quot;&quot;
+        Set the organizer's event.
+        &quot;&quot;&quot;
+        calobj = yield self.getOrganizerResource(organizer)
+        yield calobj.setComponent(ical)
+        yield self.commit()
+
+        if run_jobs:
+            yield self._runAllJobs()
+
+
+    @inlineCallbacks
+    def getOrganizerEvent(self, organizer):
+        &quot;&quot;&quot;
+        Get the organizer's event.
+        &quot;&quot;&quot;
+        calobj = yield self.getOrganizerResource(organizer)
+        comp = yield calobj.componentForUser()
+        yield self.commit()
+        returnValue(comp)
+
+
+    @inlineCallbacks
+    def getAttendeeResource(self, attendee):
+        &quot;&quot;&quot;
+        Get the attendee's event.
+        &quot;&quot;&quot;
+        cal = yield self.calendarUnderTest(name=&quot;calendar&quot;, home=attendee)
+        calobjs = yield cal.calendarObjects()
+        self.assertEqual(len(calobjs), 1)
+        returnValue(calobjs[0])
+
+
+    @inlineCallbacks
+    def setAttendeeEvent(self, attendee, ical, run_jobs=True):
+        &quot;&quot;&quot;
+        Set the attendee's event.
+        &quot;&quot;&quot;
+        calobj = yield self.getAttendeeResource(attendee)
+        yield calobj.setComponent(ical)
+        yield self.commit()
+
+        if run_jobs:
+            yield self._runAllJobs()
+
+
+    @inlineCallbacks
+    def getAttendeeEvent(self, attendee):
+        &quot;&quot;&quot;
+        Get the attendee's event.
+        &quot;&quot;&quot;
+        calobj = yield self.getAttendeeResource(attendee)
+        comp = yield calobj.componentForUser()
+        yield self.commit()
+        returnValue(comp)
+
+
+
</ins><span class="cx"> class TestScheduleOrganizerWork(BaseWorkTests):
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     Test creation of L{ScheduleOrganizerWork} items.
</span><span class="lines">@@ -264,3 +372,595 @@
</span><span class="cx">         yield work.delete()
</span><span class="cx">         yield jobs[0].delete()
</span><span class="cx">         yield self.commit()
</span><ins>+
+
+
+class TestScheduleWork(BaseWorkTests):
+    &quot;&quot;&quot;
+    Test various scheduling work scenarios that are potential race conditions and could give rise to
+    partstat mismatches between organizer and attendee, or cause work items to fail.
+    &quot;&quot;&quot;
+
+    def configure(self):
+        super(TestScheduleWork, self).configure()
+
+        # Enable the queue and make it slow
+        self.patch(self.config.Scheduling.Options.WorkQueues, &quot;Enabled&quot;, True)
+        self.patch(self.config.Scheduling.Options.WorkQueues, &quot;RequestDelaySeconds&quot;, 1000)
+        self.patch(self.config.Scheduling.Options.WorkQueues, &quot;ReplyDelaySeconds&quot;, 1000)
+        self.patch(self.config.Scheduling.Options.WorkQueues, &quot;AutoReplyDelaySeconds&quot;, 1000)
+        self.patch(self.config.Scheduling.Options.WorkQueues, &quot;AttendeeRefreshBatchDelaySeconds&quot;, 1000)
+        self.patch(self.config.Scheduling.Options.WorkQueues, &quot;AttendeeRefreshBatchIntervalSeconds&quot;, 1000)
+        self.patch(JobItem, &quot;failureRescheduleInterval&quot;, 1000)
+        self.patch(JobItem, &quot;lockRescheduleInterval&quot;, 1000)
+
+
+    @inlineCallbacks
+    def test_replyBeforeResourceDelete(self):
+        &quot;&quot;&quot;
+        Test that a reply is sent if an attendee changes an event, then immediately deletes it.
+        &quot;&quot;&quot;
+
+        organizer1 = Component.fromString(&quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890
+DTSTAMP:20080601T130000Z
+DTSTART:20080601T130000Z
+DURATION:PT1H
+ORGANIZER;CN=User 01;EMAIL=user01@example.com:urn:x-uid:user01
+ATTENDEE;CN=User 01;EMAIL=user01@example.com;PARTSTAT=ACCEPTED:urn:x-uid:user01
+ATTENDEE;CN=User 02;EMAIL=user02@example.com;PARTSTAT=NEEDS-ACTION:urn:x-uid:user02
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;)
+
+        attendee1 = Component.fromString(&quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890
+DTSTAMP:20080601T130000Z
+DTSTART:20080601T130000Z
+DURATION:PT1H
+ORGANIZER;CN=User 01;EMAIL=user01@example.com:urn:x-uid:user01
+ATTENDEE;CN=User 01;EMAIL=user01@example.com;PARTSTAT=ACCEPTED:urn:x-uid:user01
+ATTENDEE;CN=User 02;EMAIL=user02@example.com;PARTSTAT=NEEDS-ACTION;RSVP=TRUE:urn:x-uid:user02
+TRANSP:TRANSPARENT
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;)
+
+        organizer2 = Component.fromString(&quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890
+DTSTAMP:20080601T130000Z
+DTSTART:20080601T130000Z
+DURATION:PT1H
+ORGANIZER;CN=User 01;EMAIL=user01@example.com:urn:x-uid:user01
+ATTENDEE;CN=User 01;EMAIL=user01@example.com;PARTSTAT=ACCEPTED:urn:x-uid:user01
+ATTENDEE;CN=User 02;EMAIL=user02@example.com;PARTSTAT=DECLINED;SCHEDULE-STATUS=2.0:urn:x-uid:user02
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;)
+
+        attendee2 = Component.fromString(&quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890
+DTSTAMP:20080601T130000Z
+DTSTART:20080601T130000Z
+DURATION:PT1H
+ORGANIZER;CN=User 01;EMAIL=user01@example.com:urn:x-uid:user01
+ATTENDEE;CN=User 01;EMAIL=user01@example.com;PARTSTAT=ACCEPTED:urn:x-uid:user01
+ATTENDEE;CN=User 02;EMAIL=user02@example.com;PARTSTAT=DECLINED:urn:x-uid:user02
+TRANSP:TRANSPARENT
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;)
+
+        yield self.createOrganizerEvent(&quot;user01&quot;, organizer1)
+        attendee = yield self.getAttendeeEvent(&quot;user02&quot;)
+        self.assertEqual(attendee, attendee1, msg=diff_iCalStrs(attendee, attendee1))
+
+        yield self.setAttendeeEvent(&quot;user02&quot;, attendee2, run_jobs=False)
+        calobj = yield self.getAttendeeResource(&quot;user02&quot;)
+        yield calobj.remove()
+        yield self.commit()
+
+        yield self._runAllJobs()
+
+        jobs = yield JobItem.all(self.transactionUnderTest())
+        self.assertEqual(len(jobs), 0)
+        yield self.commit()
+
+        organizer = yield self.getOrganizerEvent(&quot;user01&quot;)
+        self.assertEqual(organizer, organizer2, msg=diff_iCalStrs(organizer, organizer2))
+
+
+    @inlineCallbacks
+    def test_replyBeforeOrganizerEXDATE(self):
+        &quot;&quot;&quot;
+        Test that a reply is sent if an attendee changes an event, but the organizer exdate's
+        the instance before the reply work is processed.
+        &quot;&quot;&quot;
+
+        organizer1 = Component.fromString(&quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890
+DTSTAMP:20080601T130000Z
+DTSTART:20080601T130000Z
+DURATION:PT1H
+ORGANIZER;CN=User 01;EMAIL=user01@example.com:urn:x-uid:user01
+ATTENDEE;CN=User 01;EMAIL=user01@example.com;PARTSTAT=ACCEPTED:urn:x-uid:user01
+ATTENDEE;CN=User 02;EMAIL=user02@example.com;PARTSTAT=NEEDS-ACTION:urn:x-uid:user02
+RRULE:FREQ=DAILY
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;)
+
+        attendee1 = Component.fromString(&quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890
+DTSTAMP:20080601T130000Z
+DTSTART:20080601T130000Z
+DURATION:PT1H
+ORGANIZER;CN=User 01;EMAIL=user01@example.com:urn:x-uid:user01
+ATTENDEE;CN=User 01;EMAIL=user01@example.com;PARTSTAT=ACCEPTED:urn:x-uid:user01
+ATTENDEE;CN=User 02;EMAIL=user02@example.com;PARTSTAT=NEEDS-ACTION;RSVP=TRUE:urn:x-uid:user02
+RRULE:FREQ=DAILY
+TRANSP:TRANSPARENT
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;)
+
+        organizer2 = Component.fromString(&quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890
+DTSTAMP:20080601T130000Z
+DTSTART:20080601T130000Z
+DURATION:PT1H
+ORGANIZER;CN=User 01;EMAIL=user01@example.com:urn:x-uid:user01
+ATTENDEE;CN=User 01;EMAIL=user01@example.com;PARTSTAT=ACCEPTED:urn:x-uid:user01
+ATTENDEE;CN=User 02;EMAIL=user02@example.com;PARTSTAT=NEEDS-ACTION:urn:x-uid:user02
+EXDATE:20080602T130000Z
+RRULE:FREQ=DAILY
+SUMMARY:Test
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;)
+
+        attendee2 = Component.fromString(&quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890
+DTSTAMP:20080601T130000Z
+DTSTART:20080601T130000Z
+DURATION:PT1H
+ORGANIZER;CN=User 01;EMAIL=user01@example.com:urn:x-uid:user01
+ATTENDEE;CN=User 01;EMAIL=user01@example.com;PARTSTAT=ACCEPTED:urn:x-uid:user01
+ATTENDEE;CN=User 02;EMAIL=user02@example.com;PARTSTAT=NEEDS-ACTION;RSVP=TRUE:urn:x-uid:user02
+RRULE:FREQ=DAILY
+TRANSP:TRANSPARENT
+END:VEVENT
+BEGIN:VEVENT
+UID:12345-67890
+RECURRENCE-ID:20080602T130000Z
+DTSTAMP:20080601T130000Z
+DTSTART:20080602T130000Z
+DURATION:PT1H
+ORGANIZER;CN=User 01;EMAIL=user01@example.com:urn:x-uid:user01
+ATTENDEE;CN=User 01;EMAIL=user01@example.com;PARTSTAT=ACCEPTED:urn:x-uid:user01
+ATTENDEE;CN=User 02;EMAIL=user02@example.com;PARTSTAT=DECLINED:urn:x-uid:user02
+TRANSP:TRANSPARENT
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;)
+
+        attendee3 = Component.fromString(&quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890
+DTSTAMP:20080601T130000Z
+DTSTART:20080601T130000Z
+DURATION:PT1H
+ORGANIZER;CN=User 01;EMAIL=user01@example.com:urn:x-uid:user01
+ATTENDEE;CN=User 01;EMAIL=user01@example.com;PARTSTAT=ACCEPTED:urn:x-uid:user01
+ATTENDEE;CN=User 02;EMAIL=user02@example.com;PARTSTAT=NEEDS-ACTION;RSVP=TRUE:urn:x-uid:user02
+EXDATE:20080602T130000Z
+RRULE:FREQ=DAILY
+TRANSP:TRANSPARENT
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;)
+
+        yield self.createOrganizerEvent(&quot;user01&quot;, organizer1)
+        attendee = yield self.getAttendeeEvent(&quot;user02&quot;)
+        self.assertEqual(attendee, attendee1, msg=diff_iCalStrs(attendee, attendee1))
+
+        yield self.setOrganizerEvent(&quot;user01&quot;, organizer2, run_jobs=False)
+        yield self._runOneJob()
+        yield self.setAttendeeEvent(&quot;user02&quot;, attendee2, run_jobs=False)
+        yield self.setAttendeeEvent(&quot;user02&quot;, attendee3, run_jobs=False)
+
+        yield self._runAllJobs()
+
+        jobs = yield JobItem.all(self.transactionUnderTest())
+        self.assertEqual(len(jobs), 0)
+        yield self.commit()
+
+
+    @inlineCallbacks
+    def test_replyBeforeOrganizerInconsequentialChange(self):
+        &quot;&quot;&quot;
+        Test that the organizer and attendee see the attendee's partstat change when the organizer makes
+        an inconsequential change whilst the attendee reply is in progress.
+        &quot;&quot;&quot;
+
+        organizer1 = Component.fromString(&quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890
+DTSTAMP:20080601T130000Z
+DTSTART:20080601T130000Z
+DURATION:PT1H
+ORGANIZER;CN=User 01;EMAIL=user01@example.com:urn:x-uid:user01
+ATTENDEE;CN=User 01;EMAIL=user01@example.com;PARTSTAT=ACCEPTED:urn:x-uid:user01
+ATTENDEE;CN=User 02;EMAIL=user02@example.com;PARTSTAT=NEEDS-ACTION:urn:x-uid:user02
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;)
+
+        organizer2 = Component.fromString(&quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890
+DTSTAMP:20080601T130000Z
+DTSTART:20080601T130000Z
+DURATION:PT1H
+ORGANIZER;CN=User 01;EMAIL=user01@example.com:urn:x-uid:user01
+ATTENDEE;CN=User 01;EMAIL=user01@example.com;PARTSTAT=ACCEPTED:urn:x-uid:user01
+ATTENDEE;CN=User 02;EMAIL=user02@example.com;PARTSTAT=NEEDS-ACTION:urn:x-uid:user02
+SUMMARY:Test
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;)
+
+        organizer3 = Component.fromString(&quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890
+DTSTAMP:20080601T130000Z
+DTSTART:20080601T130000Z
+DURATION:PT1H
+ORGANIZER;CN=User 01;EMAIL=user01@example.com:urn:x-uid:user01
+ATTENDEE;CN=User 01;EMAIL=user01@example.com;PARTSTAT=ACCEPTED:urn:x-uid:user01
+ATTENDEE;CN=User 02;EMAIL=user02@example.com;PARTSTAT=ACCEPTED;SCHEDULE-STATUS=2.0:urn:x-uid:user02
+SEQUENCE:1
+SUMMARY:Test
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;)
+
+        attendee1 = Component.fromString(&quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890
+DTSTAMP:20080601T130000Z
+DTSTART:20080601T130000Z
+DURATION:PT1H
+ORGANIZER;CN=User 01;EMAIL=user01@example.com:urn:x-uid:user01
+ATTENDEE;CN=User 01;EMAIL=user01@example.com;PARTSTAT=ACCEPTED:urn:x-uid:user01
+ATTENDEE;CN=User 02;EMAIL=user02@example.com;PARTSTAT=NEEDS-ACTION;RSVP=TRUE:urn:x-uid:user02
+TRANSP:TRANSPARENT
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;)
+
+        attendee2 = Component.fromString(&quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890
+DTSTAMP:20080601T130000Z
+DTSTART:20080601T130000Z
+DURATION:PT1H
+ORGANIZER;CN=User 01;EMAIL=user01@example.com:urn:x-uid:user01
+ATTENDEE;CN=User 01;EMAIL=user01@example.com;PARTSTAT=ACCEPTED:urn:x-uid:user01
+ATTENDEE;CN=User 02;EMAIL=user02@example.com;PARTSTAT=ACCEPTED:urn:x-uid:user02
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;)
+
+        attendee3 = Component.fromString(&quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890
+DTSTAMP:20080601T130000Z
+DTSTART:20080601T130000Z
+DURATION:PT1H
+ORGANIZER;CN=User 01;EMAIL=user01@example.com;SCHEDULE-STATUS=1.2:urn:x-uid:user01
+ATTENDEE;CN=User 01;EMAIL=user01@example.com;PARTSTAT=ACCEPTED:urn:x-uid:user01
+ATTENDEE;CN=User 02;EMAIL=user02@example.com;PARTSTAT=ACCEPTED:urn:x-uid:user02
+SEQUENCE:1
+SUMMARY:Test
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;)
+
+
+        yield self.createOrganizerEvent(&quot;user01&quot;, organizer1)
+        attendee = yield self.getAttendeeEvent(&quot;user02&quot;)
+        self.assertEqual(attendee, attendee1, msg=diff_iCalStrs(attendee, attendee1))
+
+        yield self.setOrganizerEvent(&quot;user01&quot;, organizer2, run_jobs=False)
+        yield self._runOneJob()
+        yield self.setAttendeeEvent(&quot;user02&quot;, attendee2, run_jobs=False)
+
+        yield self._runAllJobs()
+
+        jobs = yield JobItem.all(self.transactionUnderTest())
+        self.assertEqual(len(jobs), 0)
+        yield self.commit()
+
+        organizer = yield self.getOrganizerEvent(&quot;user01&quot;)
+        self.assertEqual(normalize_iCalStr(organizer), normalize_iCalStr(organizer3), msg=diff_iCalStrs(organizer3, organizer))
+        attendee = yield self.getAttendeeEvent(&quot;user02&quot;)
+        self.assertEqual(normalize_iCalStr(attendee), normalize_iCalStr(attendee3), msg=diff_iCalStrs(attendee3, attendee))
+
+
+    @inlineCallbacks
+    def test_replyBeforeOrganizerConsequentialChange(self):
+        &quot;&quot;&quot;
+        Test that the organizer and attendee see the attendee's partstat change when the organizer makes
+        a consequential change whilst the attendee reply is in progress.
+        &quot;&quot;&quot;
+
+        organizer1 = Component.fromString(&quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890
+DTSTAMP:20080601T130000Z
+DTSTART:20080601T130000Z
+DURATION:PT1H
+ORGANIZER;CN=User 01;EMAIL=user01@example.com:urn:x-uid:user01
+ATTENDEE;CN=User 01;EMAIL=user01@example.com;PARTSTAT=ACCEPTED:urn:x-uid:user01
+ATTENDEE;CN=User 02;EMAIL=user02@example.com;PARTSTAT=NEEDS-ACTION:urn:x-uid:user02
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;)
+
+        organizer2 = Component.fromString(&quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890
+DTSTAMP:20080601T130000Z
+DTSTART:20080602T130000Z
+DURATION:PT1H
+ORGANIZER;CN=User 01;EMAIL=user01@example.com:urn:x-uid:user01
+ATTENDEE;CN=User 01;EMAIL=user01@example.com;PARTSTAT=ACCEPTED:urn:x-uid:user01
+ATTENDEE;CN=User 02;EMAIL=user02@example.com;PARTSTAT=NEEDS-ACTION:urn:x-uid:user02
+SUMMARY:Test
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;)
+
+        organizer3 = Component.fromString(&quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890
+DTSTAMP:20080601T130000Z
+DTSTART:20080602T130000Z
+DURATION:PT1H
+ORGANIZER;CN=User 01;EMAIL=user01@example.com:urn:x-uid:user01
+ATTENDEE;CN=User 01;EMAIL=user01@example.com;PARTSTAT=ACCEPTED:urn:x-uid:user01
+ATTENDEE;CN=User 02;EMAIL=user02@example.com;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;SCHEDULE-STATUS=1.2;X-CALENDARSERVER-RESET-PARTSTAT=1:urn:x-uid:user02
+SEQUENCE:1
+SUMMARY:Test
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;)
+
+        attendee1 = Component.fromString(&quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890
+DTSTAMP:20080601T130000Z
+DTSTART:20080601T130000Z
+DURATION:PT1H
+ORGANIZER;CN=User 01;EMAIL=user01@example.com:urn:x-uid:user01
+ATTENDEE;CN=User 01;EMAIL=user01@example.com;PARTSTAT=ACCEPTED:urn:x-uid:user01
+ATTENDEE;CN=User 02;EMAIL=user02@example.com;PARTSTAT=NEEDS-ACTION;RSVP=TRUE:urn:x-uid:user02
+TRANSP:TRANSPARENT
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;)
+
+        attendee2 = Component.fromString(&quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890
+DTSTAMP:20080601T130000Z
+DTSTART:20080601T130000Z
+DURATION:PT1H
+ORGANIZER;CN=User 01;EMAIL=user01@example.com:urn:x-uid:user01
+ATTENDEE;CN=User 01;EMAIL=user01@example.com;PARTSTAT=ACCEPTED:urn:x-uid:user01
+ATTENDEE;CN=User 02;EMAIL=user02@example.com;PARTSTAT=ACCEPTED:urn:x-uid:user02
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;)
+
+        attendee3 = Component.fromString(&quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890
+DTSTAMP:20080601T130000Z
+DTSTART:20080602T130000Z
+DURATION:PT1H
+ORGANIZER;CN=User 01;EMAIL=user01@example.com;SCHEDULE-STATUS=1.2:urn:x-uid:user01
+ATTENDEE;CN=User 01;EMAIL=user01@example.com;PARTSTAT=ACCEPTED:urn:x-uid:user01
+ATTENDEE;CN=User 02;EMAIL=user02@example.com;PARTSTAT=NEEDS-ACTION;RSVP=TRUE:urn:x-uid:user02
+SEQUENCE:1
+SUMMARY:Test
+TRANSP:TRANSPARENT
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;)
+
+
+        yield self.createOrganizerEvent(&quot;user01&quot;, organizer1)
+        attendee = yield self.getAttendeeEvent(&quot;user02&quot;)
+        self.assertEqual(attendee, attendee1, msg=diff_iCalStrs(attendee, attendee1))
+
+        yield self.setOrganizerEvent(&quot;user01&quot;, organizer2, run_jobs=False)
+        yield self._runOneJob()
+        yield self.setAttendeeEvent(&quot;user02&quot;, attendee2, run_jobs=False)
+
+        yield self._runAllJobs()
+
+        jobs = yield JobItem.all(self.transactionUnderTest())
+        self.assertEqual(len(jobs), 0)
+        yield self.commit()
+
+        organizer = yield self.getOrganizerEvent(&quot;user01&quot;)
+        self.assertEqual(normalize_iCalStr(organizer), normalize_iCalStr(organizer3), msg=diff_iCalStrs(organizer3, organizer))
+        attendee = yield self.getAttendeeEvent(&quot;user02&quot;)
+        self.assertEqual(normalize_iCalStr(attendee), normalize_iCalStr(attendee3), msg=diff_iCalStrs(attendee3, attendee))
+
+
+    @inlineCallbacks
+    def test_needsActionOrganizerChange(self):
+        &quot;&quot;&quot;
+        Test that if the organizer makes an inconsequential change and also changes the
+        attendee partstat, then the new partstat is sent to the attendee.
+        &quot;&quot;&quot;
+
+        organizer1 = Component.fromString(&quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890
+DTSTAMP:20080601T130000Z
+DTSTART:20080601T130000Z
+DURATION:PT1H
+ORGANIZER;CN=User 01;EMAIL=user01@example.com:urn:x-uid:user01
+ATTENDEE;CN=User 01;EMAIL=user01@example.com;PARTSTAT=ACCEPTED:urn:x-uid:user01
+ATTENDEE;CN=User 02;EMAIL=user02@example.com;PARTSTAT=NEEDS-ACTION:urn:x-uid:user02
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;)
+
+        organizer2 = Component.fromString(&quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890
+DTSTAMP:20080601T130000Z
+DTSTART:20080601T130000Z
+DURATION:PT1H
+ORGANIZER;CN=User 01;EMAIL=user01@example.com:urn:x-uid:user01
+ATTENDEE;CN=User 01;EMAIL=user01@example.com;PARTSTAT=ACCEPTED:urn:x-uid:user01
+ATTENDEE;CN=User 02;EMAIL=user02@example.com;PARTSTAT=ACCEPTED;SCHEDULE-STATUS=2.0:urn:x-uid:user02
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;)
+
+        organizer3 = Component.fromString(&quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890
+DTSTAMP:20080601T130000Z
+DTSTART:20080601T130000Z
+DURATION:PT1H
+ORGANIZER;CN=User 01;EMAIL=user01@example.com:urn:x-uid:user01
+ATTENDEE;CN=User 01;EMAIL=user01@example.com;PARTSTAT=ACCEPTED:urn:x-uid:user01
+ATTENDEE;CN=User 02;EMAIL=user02@example.com;PARTSTAT=NEEDS-ACTION:urn:x-uid:user02
+SUMMARY:Test
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;)
+
+        attendee1 = Component.fromString(&quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890
+DTSTAMP:20080601T130000Z
+DTSTART:20080601T130000Z
+DURATION:PT1H
+ORGANIZER;CN=User 01;EMAIL=user01@example.com:urn:x-uid:user01
+ATTENDEE;CN=User 01;EMAIL=user01@example.com;PARTSTAT=ACCEPTED:urn:x-uid:user01
+ATTENDEE;CN=User 02;EMAIL=user02@example.com;PARTSTAT=NEEDS-ACTION;RSVP=TRUE:urn:x-uid:user02
+TRANSP:TRANSPARENT
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;)
+
+        attendee2 = Component.fromString(&quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890
+DTSTAMP:20080601T130000Z
+DTSTART:20080601T130000Z
+DURATION:PT1H
+ORGANIZER;CN=User 01;EMAIL=user01@example.com:urn:x-uid:user01
+ATTENDEE;CN=User 01;EMAIL=user01@example.com;PARTSTAT=ACCEPTED:urn:x-uid:user01
+ATTENDEE;CN=User 02;EMAIL=user02@example.com;PARTSTAT=ACCEPTED:urn:x-uid:user02
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;)
+
+        attendee3 = Component.fromString(&quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890
+DTSTAMP:20080601T130000Z
+DTSTART:20080601T130000Z
+DURATION:PT1H
+ORGANIZER;CN=User 01;EMAIL=user01@example.com;SCHEDULE-STATUS=1.2:urn:x-uid:user01
+ATTENDEE;CN=User 01;EMAIL=user01@example.com;PARTSTAT=ACCEPTED:urn:x-uid:user01
+ATTENDEE;CN=User 02;EMAIL=user02@example.com;PARTSTAT=NEEDS-ACTION;RSVP=TRUE:urn:x-uid:user02
+SEQUENCE:1
+SUMMARY:Test
+TRANSP:TRANSPARENT
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;)
+
+
+        yield self.createOrganizerEvent(&quot;user01&quot;, organizer1)
+        attendee = yield self.getAttendeeEvent(&quot;user02&quot;)
+        self.assertEqual(attendee, attendee1, msg=diff_iCalStrs(attendee, attendee1))
+        yield self.setAttendeeEvent(&quot;user02&quot;, attendee2)
+        organizer = yield self.getOrganizerEvent(&quot;user01&quot;)
+        self.assertEqual(normalize_iCalStr(organizer), normalize_iCalStr(organizer2), msg=diff_iCalStrs(organizer2, organizer))
+
+        yield self.setOrganizerEvent(&quot;user01&quot;, organizer3)
+        attendee = yield self.getAttendeeEvent(&quot;user02&quot;)
+        self.assertEqual(normalize_iCalStr(attendee), normalize_iCalStr(attendee3), msg=diff_iCalStrs(attendee3, attendee))
</ins></span></pre></div>
<a id="CalendarServertrunktxdavcaldavdatastoreschedulingworkpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/caldav/datastore/scheduling/work.py (14246 => 14247)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/caldav/datastore/scheduling/work.py        2015-01-06 16:42:48 UTC (rev 14246)
+++ CalendarServer/trunk/txdav/caldav/datastore/scheduling/work.py        2015-01-06 16:44:21 UTC (rev 14247)
</span><span class="lines">@@ -26,13 +26,11 @@
</span><span class="cx"> from twistedcaldav.ical import Component
</span><span class="cx"> 
</span><span class="cx"> from txdav.caldav.datastore.scheduling.cuaddress import calendarUserFromCalendarUserUID
</span><del>-from txdav.caldav.datastore.scheduling.itip import iTipGenerator, iTIPRequestStatus
</del><ins>+from txdav.caldav.datastore.scheduling.itip import iTIPRequestStatus
</ins><span class="cx"> from txdav.caldav.icalendarstore import ComponentUpdateState
</span><span class="cx"> from txdav.common.datastore.sql_tables import schema, \
</span><span class="cx">     scheduleActionToSQL, scheduleActionFromSQL
</span><span class="cx"> 
</span><del>-from pycalendar.datetime import DateTime
-
</del><span class="cx"> import datetime
</span><span class="cx"> import hashlib
</span><span class="cx"> import traceback
</span><span class="lines">@@ -40,7 +38,6 @@
</span><span class="cx"> __all__ = [
</span><span class="cx">     &quot;ScheduleOrganizerWork&quot;,
</span><span class="cx">     &quot;ScheduleReplyWork&quot;,
</span><del>-    &quot;ScheduleReplyCancelWork&quot;,
</del><span class="cx">     &quot;ScheduleRefreshWork&quot;,
</span><span class="cx">     &quot;ScheduleAutoReplyWork&quot;,
</span><span class="cx"> ]
</span><span class="lines">@@ -504,33 +501,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-class ScheduleReplyWorkMixin(ScheduleWorkMixin):
-
-
-    def makeScheduler(self, home):
-        &quot;&quot;&quot;
-        Convenience method which we can override in unit tests to make testing easier.
-        &quot;&quot;&quot;
-        from txdav.caldav.datastore.scheduling.caldav.scheduler import CalDAVScheduler
-        return CalDAVScheduler(self.transaction, home.uid())
-
-
-    @inlineCallbacks
-    def sendToOrganizer(self, home, action, itipmsg, originator, recipient):
-
-        # Send scheduling message
-
-        # This is a local CALDAV scheduling operation.
-        scheduler = self.makeScheduler(home)
-
-        # Do the PUT processing
-        log.info(&quot;Implicit %s - attendee: '%s' to organizer: '%s', UID: '%s'&quot; % (action, originator, recipient, itipmsg.resourceUID(),))
-        response = (yield scheduler.doSchedulingViaPUT(originator, (recipient,), itipmsg, internal_request=True))
-        returnValue(response)
-
-
-
-class ScheduleReplyWork(ScheduleReplyWorkMixin, fromTable(schema.SCHEDULE_REPLY_WORK)):
</del><ins>+class ScheduleReplyWork(ScheduleWorkMixin, fromTable(schema.SCHEDULE_REPLY_WORK)):
</ins><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     The associated work item table is SCHEDULE_REPLY_WORK.
</span><span class="cx"> 
</span><span class="lines">@@ -540,121 +511,75 @@
</span><span class="cx"> 
</span><span class="cx">     @classmethod
</span><span class="cx">     @inlineCallbacks
</span><del>-    def reply(cls, txn, home, resource, changedRids, attendee):
</del><ins>+    def reply(cls, txn, home, resource, itipmsg, attendee):
</ins><span class="cx">         # Always queue up new work - coalescing happens when work is executed
</span><span class="cx">         notBefore = datetime.datetime.utcnow() + datetime.timedelta(seconds=config.Scheduling.Options.WorkQueues.ReplyDelaySeconds)
</span><ins>+        uid = itipmsg.resourceUID()
</ins><span class="cx">         proposal = (yield txn.enqueue(
</span><span class="cx">             cls,
</span><span class="cx">             notBefore=notBefore,
</span><del>-            icalendarUid=resource.uid(),
</del><ins>+            icalendarUid=uid,
</ins><span class="cx">             homeResourceID=home.id(),
</span><del>-            resourceID=resource.id(),
-
-            # Serialize None as &quot;&quot;
-            changedRids=&quot;,&quot;.join(map(lambda x: &quot;&quot; if x is None else str(x), changedRids)) if changedRids else None,
</del><ins>+            resourceID=resource.id() if resource else None,
+            itipMsg=itipmsg.getTextWithTimezones(includeTimezones=not config.EnableTimezonesByReference),
</ins><span class="cx">         ))
</span><span class="cx">         cls._enqueued()
</span><del>-        log.debug(&quot;ScheduleReplyWork - enqueued for ID: {id}, UID: {uid}, attendee: {att}&quot;, id=proposal.workItem.workID, uid=resource.uid(), att=attendee)
</del><ins>+        log.debug(&quot;ScheduleReplyWork - enqueued for ID: {id}, UID: {uid}, attendee: {att}&quot;, id=proposal.workItem.workID, uid=uid, att=attendee)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><del>-    def doWork(self):
</del><ins>+    def sendToOrganizer(self, home, itipmsg, originator, recipient):
</ins><span class="cx"> 
</span><del>-        try:
-            home = (yield self.transaction.calendarHomeWithResourceID(self.homeResourceID))
-            resource = (yield home.objectResourceWithID(self.resourceID))
-            attendeeAddress = yield calendarUserFromCalendarUserUID(home.uid(), self.transaction)
-            attendee = attendeeAddress.record.canonicalCalendarUserAddress()
-            calendar = (yield resource.componentForUser())
-            organizer = calendar.validOrganizerForScheduling()
</del><ins>+        # Send scheduling message
</ins><span class="cx"> 
</span><del>-            # Deserialize &quot;&quot; as None
-            changedRids = map(lambda x: DateTime.parseText(x) if x else None, self.changedRids.split(&quot;,&quot;)) if self.changedRids else None
</del><ins>+        # This is a local CALDAV scheduling operation.
+        from txdav.caldav.datastore.scheduling.caldav.scheduler import CalDAVScheduler
+        scheduler = CalDAVScheduler(self.transaction, home.uid())
</ins><span class="cx"> 
</span><del>-            log.debug(&quot;ScheduleReplyWork - running for ID: {id}, UID: {uid}, attendee: {att}&quot;, id=self.workID, uid=calendar.resourceUID(), att=attendee)
</del><ins>+        # Do the PUT processing
+        log.info(&quot;Implicit REPLY - attendee: '%s' to organizer: '%s', UID: '%s'&quot; % (originator, recipient, itipmsg.resourceUID(),))
+        response = (yield scheduler.doSchedulingViaPUT(originator, (recipient,), itipmsg, internal_request=True))
+        returnValue(response)
</ins><span class="cx"> 
</span><del>-            # We need to get the UID lock for implicit processing.
-            yield NamedLock.acquire(self.transaction, &quot;ImplicitUIDLock:%s&quot; % (hashlib.md5(calendar.resourceUID()).hexdigest(),))
</del><span class="cx"> 
</span><del>-            itipmsg = iTipGenerator.generateAttendeeReply(calendar, attendee, changedRids=changedRids)
-
-            # Send scheduling message and process response
-            response = (yield self.sendToOrganizer(home, &quot;REPLY&quot;, itipmsg, attendee, organizer))
-            responses, all_delivered = self.extractSchedulingResponse((response,))
-            if not all_delivered:
-                changed = yield self.handleSchedulingResponse(responses, calendar, False)
-                if changed:
-                    yield resource._setComponentInternal(calendar, internal_state=ComponentUpdateState.ATTENDEE_ITIP_UPDATE)
-
-            self._dequeued()
-
-        except Exception, e:
-            # FIXME: calendar may not be set here!
-            log.debug(&quot;ScheduleReplyWork - exception ID: {id}, UID: '{uid}', {err}&quot;, id=self.workID, uid=calendar.resourceUID(), err=str(e))
-            raise
-        except:
-            log.debug(&quot;ScheduleReplyWork - bare exception ID: {id}, UID: '{uid}'&quot;, id=self.workID, uid=calendar.resourceUID())
-            raise
-
-        log.debug(&quot;ScheduleReplyWork - done for ID: {id}, UID: {uid}, attendee: {att}&quot;, id=self.workID, uid=calendar.resourceUID(), att=attendee)
-
-
-
-class ScheduleReplyCancelWork(ScheduleReplyWorkMixin, fromTable(schema.SCHEDULE_REPLY_CANCEL_WORK)):
-    &quot;&quot;&quot;
-    The associated work item table is SCHEDULE_REPLY_CANCEL_WORK.
-
-    This work item is used to send an iTIP reply message when an attendee deletes
-    their copy of the calendar object resource. For this to work we need to store a copy
-    of the original resource data.
-    &quot;&quot;&quot;
-
-    @classmethod
</del><span class="cx">     @inlineCallbacks
</span><del>-    def replyCancel(cls, txn, home, calendar, attendee):
-        # Always queue up new work - coalescing happens when work is executed
-        notBefore = datetime.datetime.utcnow() + datetime.timedelta(seconds=config.Scheduling.Options.WorkQueues.ReplyDelaySeconds)
-        proposal = (yield txn.enqueue(
-            cls,
-            notBefore=notBefore,
-            icalendarUid=calendar.resourceUID(),
-            homeResourceID=home.id(),
-            icalendarText=calendar.getTextWithTimezones(includeTimezones=not config.EnableTimezonesByReference),
-        ))
-        cls._enqueued()
-        log.debug(&quot;ScheduleReplyCancelWork - enqueued for ID: {id}, UID: {uid}, attendee: {att}&quot;, id=proposal.workItem.workID, uid=calendar.resourceUID(), att=attendee)
-
-
-    @inlineCallbacks
</del><span class="cx">     def doWork(self):
</span><span class="cx"> 
</span><span class="cx">         try:
</span><span class="cx">             home = (yield self.transaction.calendarHomeWithResourceID(self.homeResourceID))
</span><ins>+            resource = (yield home.objectResourceWithID(self.resourceID))
+            itipmsg = Component.fromString(self.itipMsg)
</ins><span class="cx">             attendeeAddress = yield calendarUserFromCalendarUserUID(home.uid(), self.transaction)
</span><span class="cx">             attendee = attendeeAddress.record.canonicalCalendarUserAddress()
</span><del>-            calendar = Component.fromString(self.icalendarText)
-            organizer = calendar.validOrganizerForScheduling()
</del><ins>+            organizer = itipmsg.validOrganizerForScheduling()
</ins><span class="cx"> 
</span><del>-            log.debug(&quot;ScheduleReplyCancelWork - running for ID: {id}, UID: {uid}, attendee: {att}&quot;, id=self.workID, uid=calendar.resourceUID(), att=attendee)
</del><ins>+            log.debug(&quot;ScheduleReplyWork - running for ID: {id}, UID: {uid}, attendee: {att}&quot;, id=self.workID, uid=itipmsg.resourceUID(), att=attendee)
</ins><span class="cx"> 
</span><span class="cx">             # We need to get the UID lock for implicit processing.
</span><del>-            yield NamedLock.acquire(self.transaction, &quot;ImplicitUIDLock:%s&quot; % (hashlib.md5(calendar.resourceUID()).hexdigest(),))
</del><ins>+            yield NamedLock.acquire(self.transaction, &quot;ImplicitUIDLock:%s&quot; % (hashlib.md5(itipmsg.resourceUID()).hexdigest(),))
</ins><span class="cx"> 
</span><del>-            itipmsg = iTipGenerator.generateAttendeeReply(calendar, attendee, force_decline=True)
</del><ins>+            # Send scheduling message and process response
+            response = (yield self.sendToOrganizer(home, itipmsg, attendee, organizer))
</ins><span class="cx"> 
</span><del>-            # Send scheduling message - no need to process response as original resource is gone
-            yield self.sendToOrganizer(home, &quot;CANCEL&quot;, itipmsg, attendee, organizer)
</del><ins>+            if resource is not None:
+                responses, all_delivered = self.extractSchedulingResponse((response,))
+                if not all_delivered:
+                    calendar = (yield resource.componentForUser())
+                    changed = yield self.handleSchedulingResponse(responses, calendar, False)
+                    if changed:
+                        yield resource._setComponentInternal(calendar, internal_state=ComponentUpdateState.ATTENDEE_ITIP_UPDATE)
</ins><span class="cx"> 
</span><span class="cx">             self._dequeued()
</span><span class="cx"> 
</span><span class="cx">         except Exception, e:
</span><del>-            log.debug(&quot;ScheduleReplyCancelWork - exception ID: {id}, UID: '{uid}', {err}&quot;, id=self.workID, uid=calendar.resourceUID(), err=str(e))
</del><ins>+            # FIXME: calendar may not be set here!
+            log.debug(&quot;ScheduleReplyWork - exception ID: {id}, UID: '{uid}', {err}&quot;, id=self.workID, uid=itipmsg.resourceUID(), err=str(e))
</ins><span class="cx">             raise
</span><span class="cx">         except:
</span><del>-            log.debug(&quot;ScheduleReplyCancelWork - bare exception ID: {id}, UID: '{uid}'&quot;, id=self.workID, uid=calendar.resourceUID())
</del><ins>+            log.debug(&quot;ScheduleReplyWork - bare exception ID: {id}, UID: '{uid}'&quot;, id=self.workID, uid=itipmsg.resourceUID())
</ins><span class="cx">             raise
</span><span class="cx"> 
</span><del>-        log.debug(&quot;ScheduleReplyCancelWork - done for ID: {id}, UID: {uid}, attendee: {att}&quot;, id=self.workID, uid=calendar.resourceUID(), att=attendee)
</del><ins>+        log.debug(&quot;ScheduleReplyWork - done for ID: {id}, UID: {uid}, attendee: {att}&quot;, id=self.workID, uid=itipmsg.resourceUID(), att=attendee)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span></span></pre></div>
<a id="CalendarServertrunktxdavcommondatastoresql_dumppy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/common/datastore/sql_dump.py (14246 => 14247)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/common/datastore/sql_dump.py        2015-01-06 16:42:48 UTC (rev 14246)
+++ CalendarServer/trunk/txdav/common/datastore/sql_dump.py        2015-01-06 16:44:21 UTC (rev 14247)
</span><span class="lines">@@ -17,7 +17,7 @@
</span><span class="cx"> 
</span><span class="cx"> from twisted.internet.defer import inlineCallbacks, returnValue
</span><span class="cx"> from twext.enterprise.dal.model import Schema, Table, Column, Sequence, Function, \
</span><del>-    SQLType, ProcedureCall
</del><ins>+    SQLType, ProcedureCall, Constraint
</ins><span class="cx"> from twext.enterprise.dal.parseschema import addSQLToSchema
</span><span class="cx"> 
</span><span class="cx"> &quot;&quot;&quot;
</span><span class="lines">@@ -63,8 +63,8 @@
</span><span class="cx">         tables[name.upper()] = table
</span><span class="cx"> 
</span><span class="cx">         # Columns
</span><del>-        rows = yield txn.execSQL(&quot;select column_name, data_type, character_maximum_length, column_default from information_schema.columns where table_schema = '%s' and table_name = '%s';&quot; % (schemaname, name,))
-        for name, datatype, charlen, default in rows:
</del><ins>+        rows = yield txn.execSQL(&quot;select column_name, data_type, is_nullable, character_maximum_length, column_default from information_schema.columns where table_schema = '%s' and table_name = '%s';&quot; % (schemaname, name,))
+        for name, datatype, is_nullable, charlen, default in rows:
</ins><span class="cx">             # TODO: figure out the type
</span><span class="cx">             column = Column(table, name.upper(), SQLType(DTYPE_MAP.get(datatype, datatype), charlen))
</span><span class="cx">             table.columns.append(column)
</span><span class="lines">@@ -79,6 +79,8 @@
</span><span class="cx">                         column.default = int(default)
</span><span class="cx">                     except ValueError:
</span><span class="cx">                         column.default = default
</span><ins>+            if is_nullable == &quot;NO&quot;:
+                table.tableConstraint(Constraint.NOT_NULL, [column.name, ])
</ins><span class="cx"> 
</span><span class="cx">     # Key columns
</span><span class="cx">     keys = {}
</span></span></pre></div>
<a id="CalendarServertrunktxdavcommondatastoresql_schemacurrentoracledialectsql"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/common/datastore/sql_schema/current-oracle-dialect.sql (14246 => 14247)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/common/datastore/sql_schema/current-oracle-dialect.sql        2015-01-06 16:42:48 UTC (rev 14246)
+++ CalendarServer/trunk/txdav/common/datastore/sql_schema/current-oracle-dialect.sql        2015-01-06 16:44:21 UTC (rev 14247)
</span><span class="lines">@@ -17,7 +17,7 @@
</span><span class="cx"> );
</span><span class="cx"> 
</span><span class="cx"> create table JOB (
</span><del>-    &quot;JOB_ID&quot; integer primary key not null,
</del><ins>+    &quot;JOB_ID&quot; integer primary key,
</ins><span class="cx">     &quot;WORK_TYPE&quot; nvarchar2(255),
</span><span class="cx">     &quot;PRIORITY&quot; integer default 0,
</span><span class="cx">     &quot;WEIGHT&quot; integer default 0,
</span><span class="lines">@@ -370,7 +370,7 @@
</span><span class="cx"> );
</span><span class="cx"> 
</span><span class="cx"> create table IMIP_INVITATION_WORK (
</span><del>-    &quot;WORK_ID&quot; integer primary key not null,
</del><ins>+    &quot;WORK_ID&quot; integer primary key,
</ins><span class="cx">     &quot;JOB_ID&quot; integer not null references JOB,
</span><span class="cx">     &quot;FROM_ADDR&quot; nvarchar2(255),
</span><span class="cx">     &quot;TO_ADDR&quot; nvarchar2(255),
</span><span class="lines">@@ -378,12 +378,12 @@
</span><span class="cx"> );
</span><span class="cx"> 
</span><span class="cx"> create table IMIP_POLLING_WORK (
</span><del>-    &quot;WORK_ID&quot; integer primary key not null,
</del><ins>+    &quot;WORK_ID&quot; integer primary key,
</ins><span class="cx">     &quot;JOB_ID&quot; integer not null references JOB
</span><span class="cx"> );
</span><span class="cx"> 
</span><span class="cx"> create table IMIP_REPLY_WORK (
</span><del>-    &quot;WORK_ID&quot; integer primary key not null,
</del><ins>+    &quot;WORK_ID&quot; integer primary key,
</ins><span class="cx">     &quot;JOB_ID&quot; integer not null references JOB,
</span><span class="cx">     &quot;ORGANIZER&quot; nvarchar2(255),
</span><span class="cx">     &quot;ATTENDEE&quot; nvarchar2(255),
</span><span class="lines">@@ -391,25 +391,25 @@
</span><span class="cx"> );
</span><span class="cx"> 
</span><span class="cx"> create table PUSH_NOTIFICATION_WORK (
</span><del>-    &quot;WORK_ID&quot; integer primary key not null,
</del><ins>+    &quot;WORK_ID&quot; integer primary key,
</ins><span class="cx">     &quot;JOB_ID&quot; integer not null references JOB,
</span><span class="cx">     &quot;PUSH_ID&quot; nvarchar2(255),
</span><span class="cx">     &quot;PUSH_PRIORITY&quot; integer not null
</span><span class="cx"> );
</span><span class="cx"> 
</span><span class="cx"> create table GROUP_CACHER_POLLING_WORK (
</span><del>-    &quot;WORK_ID&quot; integer primary key not null,
</del><ins>+    &quot;WORK_ID&quot; integer primary key,
</ins><span class="cx">     &quot;JOB_ID&quot; integer not null references JOB
</span><span class="cx"> );
</span><span class="cx"> 
</span><span class="cx"> create table GROUP_REFRESH_WORK (
</span><del>-    &quot;WORK_ID&quot; integer primary key not null,
</del><ins>+    &quot;WORK_ID&quot; integer primary key,
</ins><span class="cx">     &quot;JOB_ID&quot; integer not null references JOB,
</span><span class="cx">     &quot;GROUP_UID&quot; nvarchar2(255)
</span><span class="cx"> );
</span><span class="cx"> 
</span><span class="cx"> create table GROUP_DELEGATE_CHANGES_WORK (
</span><del>-    &quot;WORK_ID&quot; integer primary key not null,
</del><ins>+    &quot;WORK_ID&quot; integer primary key,
</ins><span class="cx">     &quot;JOB_ID&quot; integer not null references JOB,
</span><span class="cx">     &quot;DELEGATOR_UID&quot; nvarchar2(255),
</span><span class="cx">     &quot;READ_DELEGATE_UID&quot; nvarchar2(255),
</span><span class="lines">@@ -433,7 +433,7 @@
</span><span class="cx"> );
</span><span class="cx"> 
</span><span class="cx"> create table GROUP_ATTENDEE_RECONCILE_WORK (
</span><del>-    &quot;WORK_ID&quot; integer primary key not null,
</del><ins>+    &quot;WORK_ID&quot; integer primary key,
</ins><span class="cx">     &quot;JOB_ID&quot; integer not null references JOB,
</span><span class="cx">     &quot;RESOURCE_ID&quot; integer not null references CALENDAR_OBJECT on delete cascade,
</span><span class="cx">     &quot;GROUP_ID&quot; integer not null references GROUPS on delete cascade
</span><span class="lines">@@ -447,7 +447,7 @@
</span><span class="cx"> );
</span><span class="cx"> 
</span><span class="cx"> create table GROUP_SHAREE_RECONCILE_WORK (
</span><del>-    &quot;WORK_ID&quot; integer primary key not null,
</del><ins>+    &quot;WORK_ID&quot; integer primary key,
</ins><span class="cx">     &quot;JOB_ID&quot; integer not null references JOB,
</span><span class="cx">     &quot;CALENDAR_ID&quot; integer not null references CALENDAR on delete cascade,
</span><span class="cx">     &quot;GROUP_ID&quot; integer not null references GROUPS on delete cascade
</span><span class="lines">@@ -483,34 +483,34 @@
</span><span class="cx"> );
</span><span class="cx"> 
</span><span class="cx"> create table CALENDAR_OBJECT_SPLITTER_WORK (
</span><del>-    &quot;WORK_ID&quot; integer primary key not null,
</del><ins>+    &quot;WORK_ID&quot; integer primary key,
</ins><span class="cx">     &quot;JOB_ID&quot; integer not null references JOB,
</span><span class="cx">     &quot;RESOURCE_ID&quot; integer not null references CALENDAR_OBJECT on delete cascade
</span><span class="cx"> );
</span><span class="cx"> 
</span><span class="cx"> create table FIND_MIN_VALID_REVISION_WORK (
</span><del>-    &quot;WORK_ID&quot; integer primary key not null,
</del><ins>+    &quot;WORK_ID&quot; integer primary key,
</ins><span class="cx">     &quot;JOB_ID&quot; integer not null references JOB
</span><span class="cx"> );
</span><span class="cx"> 
</span><span class="cx"> create table REVISION_CLEANUP_WORK (
</span><del>-    &quot;WORK_ID&quot; integer primary key not null,
</del><ins>+    &quot;WORK_ID&quot; integer primary key,
</ins><span class="cx">     &quot;JOB_ID&quot; integer not null references JOB
</span><span class="cx"> );
</span><span class="cx"> 
</span><span class="cx"> create table INBOX_CLEANUP_WORK (
</span><del>-    &quot;WORK_ID&quot; integer primary key not null,
</del><ins>+    &quot;WORK_ID&quot; integer primary key,
</ins><span class="cx">     &quot;JOB_ID&quot; integer not null references JOB
</span><span class="cx"> );
</span><span class="cx"> 
</span><span class="cx"> create table CLEANUP_ONE_INBOX_WORK (
</span><del>-    &quot;WORK_ID&quot; integer primary key not null,
</del><ins>+    &quot;WORK_ID&quot; integer primary key,
</ins><span class="cx">     &quot;JOB_ID&quot; integer not null references JOB,
</span><span class="cx">     &quot;HOME_ID&quot; integer not null unique references CALENDAR_HOME on delete cascade
</span><span class="cx"> );
</span><span class="cx"> 
</span><span class="cx"> create table SCHEDULE_WORK (
</span><del>-    &quot;WORK_ID&quot; integer primary key not null,
</del><ins>+    &quot;WORK_ID&quot; integer primary key,
</ins><span class="cx">     &quot;JOB_ID&quot; integer not null references JOB,
</span><span class="cx">     &quot;ICALENDAR_UID&quot; nvarchar2(255),
</span><span class="cx">     &quot;WORK_TYPE&quot; nvarchar2(255)
</span><span class="lines">@@ -569,35 +569,29 @@
</span><span class="cx"> create table SCHEDULE_REPLY_WORK (
</span><span class="cx">     &quot;WORK_ID&quot; integer primary key references SCHEDULE_WORK on delete cascade,
</span><span class="cx">     &quot;HOME_RESOURCE_ID&quot; integer not null references CALENDAR_HOME on delete cascade,
</span><del>-    &quot;RESOURCE_ID&quot; integer not null references CALENDAR_OBJECT on delete cascade,
-    &quot;CHANGED_RIDS&quot; nclob
</del><ins>+    &quot;RESOURCE_ID&quot; integer,
+    &quot;ITIP_MSG&quot; nclob
</ins><span class="cx"> );
</span><span class="cx"> 
</span><del>-create table SCHEDULE_REPLY_CANCEL_WORK (
-    &quot;WORK_ID&quot; integer primary key references SCHEDULE_WORK on delete cascade,
-    &quot;HOME_RESOURCE_ID&quot; integer not null references CALENDAR_HOME on delete cascade,
-    &quot;ICALENDAR_TEXT&quot; nclob
-);
-
</del><span class="cx"> create table PRINCIPAL_PURGE_POLLING_WORK (
</span><del>-    &quot;WORK_ID&quot; integer primary key not null,
</del><ins>+    &quot;WORK_ID&quot; integer primary key,
</ins><span class="cx">     &quot;JOB_ID&quot; integer not null references JOB
</span><span class="cx"> );
</span><span class="cx"> 
</span><span class="cx"> create table PRINCIPAL_PURGE_CHECK_WORK (
</span><del>-    &quot;WORK_ID&quot; integer primary key not null,
</del><ins>+    &quot;WORK_ID&quot; integer primary key,
</ins><span class="cx">     &quot;JOB_ID&quot; integer not null references JOB,
</span><span class="cx">     &quot;UID&quot; nvarchar2(255)
</span><span class="cx"> );
</span><span class="cx"> 
</span><span class="cx"> create table PRINCIPAL_PURGE_WORK (
</span><del>-    &quot;WORK_ID&quot; integer primary key not null,
</del><ins>+    &quot;WORK_ID&quot; integer primary key,
</ins><span class="cx">     &quot;JOB_ID&quot; integer not null references JOB,
</span><span class="cx">     &quot;UID&quot; nvarchar2(255)
</span><span class="cx"> );
</span><span class="cx"> 
</span><span class="cx"> create table PRINCIPAL_PURGE_HOME_WORK (
</span><del>-    &quot;WORK_ID&quot; integer primary key not null,
</del><ins>+    &quot;WORK_ID&quot; integer primary key,
</ins><span class="cx">     &quot;JOB_ID&quot; integer not null references JOB,
</span><span class="cx">     &quot;HOME_RESOURCE_ID&quot; integer not null references CALENDAR_HOME on delete cascade
</span><span class="cx"> );
</span><span class="lines">@@ -607,7 +601,7 @@
</span><span class="cx">     &quot;VALUE&quot; nvarchar2(255)
</span><span class="cx"> );
</span><span class="cx"> 
</span><del>-insert into CALENDARSERVER (NAME, VALUE) values ('VERSION', '49');
</del><ins>+insert into CALENDARSERVER (NAME, VALUE) values ('VERSION', '50');
</ins><span class="cx"> insert into CALENDARSERVER (NAME, VALUE) values ('CALENDAR-DATAVERSION', '6');
</span><span class="cx"> insert into CALENDARSERVER (NAME, VALUE) values ('ADDRESSBOOK-DATAVERSION', '2');
</span><span class="cx"> insert into CALENDARSERVER (NAME, VALUE) values ('NOTIFICATION-DATAVERSION', '1');
</span><span class="lines">@@ -900,10 +894,6 @@
</span><span class="cx">     RESOURCE_ID
</span><span class="cx"> );
</span><span class="cx"> 
</span><del>-create index SCHEDULE_REPLY_CANCEL_dab513ef on SCHEDULE_REPLY_CANCEL_WORK (
-    HOME_RESOURCE_ID
-);
-
</del><span class="cx"> create index PRINCIPAL_PURGE_POLLI_6383e68a on PRINCIPAL_PURGE_POLLING_WORK (
</span><span class="cx">     JOB_ID
</span><span class="cx"> );
</span></span></pre></div>
<a id="CalendarServertrunktxdavcommondatastoresql_schemacurrentsql"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/common/datastore/sql_schema/current.sql (14246 => 14247)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/common/datastore/sql_schema/current.sql        2015-01-06 16:42:48 UTC (rev 14246)
+++ CalendarServer/trunk/txdav/common/datastore/sql_schema/current.sql        2015-01-06 16:44:21 UTC (rev 14247)
</span><span class="lines">@@ -54,7 +54,7 @@
</span><span class="cx"> create sequence JOB_SEQ;
</span><span class="cx"> 
</span><span class="cx"> create table JOB (
</span><del>-  JOB_ID      integer primary key default nextval('JOB_SEQ') not null, --implicit index
</del><ins>+  JOB_ID      integer primary key default nextval('JOB_SEQ'), --implicit index
</ins><span class="cx">   WORK_TYPE   varchar(255) not null,
</span><span class="cx">   PRIORITY    integer default 0,
</span><span class="cx">   WEIGHT      integer default 0,
</span><span class="lines">@@ -688,7 +688,7 @@
</span><span class="cx"> ---------------------------
</span><span class="cx"> 
</span><span class="cx"> create table IMIP_INVITATION_WORK (
</span><del>-  WORK_ID                       integer      primary key default nextval('WORKITEM_SEQ') not null, -- implicit index
</del><ins>+  WORK_ID                       integer      primary key default nextval('WORKITEM_SEQ'), -- implicit index
</ins><span class="cx">   JOB_ID                        integer      references JOB not null,
</span><span class="cx">   FROM_ADDR                     varchar(255) not null,
</span><span class="cx">   TO_ADDR                       varchar(255) not null,
</span><span class="lines">@@ -703,7 +703,7 @@
</span><span class="cx"> -----------------------
</span><span class="cx"> 
</span><span class="cx"> create table IMIP_POLLING_WORK (
</span><del>-  WORK_ID                       integer      primary key default nextval('WORKITEM_SEQ') not null, -- implicit index
</del><ins>+  WORK_ID                       integer      primary key default nextval('WORKITEM_SEQ'), -- implicit index
</ins><span class="cx">   JOB_ID                        integer      references JOB not null
</span><span class="cx"> );
</span><span class="cx"> 
</span><span class="lines">@@ -716,7 +716,7 @@
</span><span class="cx"> ---------------------
</span><span class="cx"> 
</span><span class="cx"> create table IMIP_REPLY_WORK (
</span><del>-  WORK_ID                       integer      primary key default nextval('WORKITEM_SEQ') not null, -- implicit index
</del><ins>+  WORK_ID                       integer      primary key default nextval('WORKITEM_SEQ'), -- implicit index
</ins><span class="cx">   JOB_ID                        integer      references JOB not null,
</span><span class="cx">   ORGANIZER                     varchar(255) not null,
</span><span class="cx">   ATTENDEE                      varchar(255) not null,
</span><span class="lines">@@ -732,7 +732,7 @@
</span><span class="cx"> ------------------------
</span><span class="cx"> 
</span><span class="cx"> create table PUSH_NOTIFICATION_WORK (
</span><del>-  WORK_ID                       integer      primary key default nextval('WORKITEM_SEQ') not null, -- implicit index
</del><ins>+  WORK_ID                       integer      primary key default nextval('WORKITEM_SEQ'), -- implicit index
</ins><span class="cx">   JOB_ID                        integer      references JOB not null,
</span><span class="cx">   PUSH_ID                       varchar(255) not null,
</span><span class="cx">   PUSH_PRIORITY                 integer      not null -- 1:low 5:medium 10:high
</span><span class="lines">@@ -748,7 +748,7 @@
</span><span class="cx"> -----------------
</span><span class="cx"> 
</span><span class="cx"> create table GROUP_CACHER_POLLING_WORK (
</span><del>-  WORK_ID                       integer      primary key default nextval('WORKITEM_SEQ') not null, -- implicit index
</del><ins>+  WORK_ID                       integer      primary key default nextval('WORKITEM_SEQ'), -- implicit index
</ins><span class="cx">   JOB_ID                        integer      references JOB not null
</span><span class="cx"> );
</span><span class="cx"> 
</span><span class="lines">@@ -756,7 +756,7 @@
</span><span class="cx">   GROUP_CACHER_POLLING_WORK(JOB_ID);
</span><span class="cx"> 
</span><span class="cx"> create table GROUP_REFRESH_WORK (
</span><del>-  WORK_ID                       integer      primary key default nextval('WORKITEM_SEQ') not null, -- implicit index
</del><ins>+  WORK_ID                       integer      primary key default nextval('WORKITEM_SEQ'), -- implicit index
</ins><span class="cx">   JOB_ID                        integer      references JOB not null,
</span><span class="cx">   GROUP_UID                     varchar(255) not null
</span><span class="cx"> );
</span><span class="lines">@@ -767,7 +767,7 @@
</span><span class="cx">   GROUP_REFRESH_WORK(GROUP_UID);
</span><span class="cx"> 
</span><span class="cx"> create table GROUP_DELEGATE_CHANGES_WORK (
</span><del>-  WORK_ID                       integer      primary key default nextval('WORKITEM_SEQ') not null, -- implicit index
</del><ins>+  WORK_ID                       integer      primary key default nextval('WORKITEM_SEQ'), -- implicit index
</ins><span class="cx">   JOB_ID                        integer      references JOB not null,
</span><span class="cx">   DELEGATOR_UID                 varchar(255) not null,
</span><span class="cx">   READ_DELEGATE_UID             varchar(255) not null,
</span><span class="lines">@@ -802,7 +802,7 @@
</span><span class="cx">   GROUP_MEMBERSHIP(MEMBER_UID);
</span><span class="cx"> 
</span><span class="cx"> create table GROUP_ATTENDEE_RECONCILE_WORK (
</span><del>-  WORK_ID                       integer primary key default nextval('WORKITEM_SEQ') not null, -- implicit index
</del><ins>+  WORK_ID                       integer primary key default nextval('WORKITEM_SEQ'), -- implicit index
</ins><span class="cx">   JOB_ID                        integer not null references JOB,
</span><span class="cx">   RESOURCE_ID                   integer not null references CALENDAR_OBJECT on delete cascade,
</span><span class="cx">   GROUP_ID                      integer not null references GROUPS on delete cascade
</span><span class="lines">@@ -829,7 +829,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> create table GROUP_SHAREE_RECONCILE_WORK (
</span><del>-  WORK_ID                       integer primary key default nextval('WORKITEM_SEQ') not null, -- implicit index
</del><ins>+  WORK_ID                       integer primary key default nextval('WORKITEM_SEQ'), -- implicit index
</ins><span class="cx">   JOB_ID                        integer not null references JOB,
</span><span class="cx">   CALENDAR_ID                   integer        not null references CALENDAR on delete cascade,
</span><span class="cx">   GROUP_ID                      integer not null references GROUPS on delete cascade
</span><span class="lines">@@ -881,7 +881,7 @@
</span><span class="cx">   DELEGATE_GROUPS(GROUP_ID);
</span><span class="cx"> 
</span><span class="cx"> create table EXTERNAL_DELEGATE_GROUPS (
</span><del>-  DELEGATOR                     varchar(255) primary key not null,
</del><ins>+  DELEGATOR                     varchar(255) primary key,
</ins><span class="cx">   GROUP_UID_READ                varchar(255),
</span><span class="cx">   GROUP_UID_WRITE               varchar(255)
</span><span class="cx"> );
</span><span class="lines">@@ -891,7 +891,7 @@
</span><span class="cx"> --------------------------
</span><span class="cx"> 
</span><span class="cx"> create table CALENDAR_OBJECT_SPLITTER_WORK (
</span><del>-  WORK_ID                       integer      primary key default nextval('WORKITEM_SEQ') not null, -- implicit index
</del><ins>+  WORK_ID                       integer      primary key default nextval('WORKITEM_SEQ'), -- implicit index
</ins><span class="cx">   JOB_ID                        integer      references JOB not null,
</span><span class="cx">   RESOURCE_ID                   integer      not null references CALENDAR_OBJECT on delete cascade
</span><span class="cx"> );
</span><span class="lines">@@ -906,7 +906,7 @@
</span><span class="cx"> ---------------------------
</span><span class="cx"> 
</span><span class="cx"> create table FIND_MIN_VALID_REVISION_WORK (
</span><del>-  WORK_ID                       integer      primary key default nextval('WORKITEM_SEQ') not null, -- implicit index
</del><ins>+  WORK_ID                       integer      primary key default nextval('WORKITEM_SEQ'), -- implicit index
</ins><span class="cx">   JOB_ID                        integer      references JOB not null
</span><span class="cx"> );
</span><span class="cx"> 
</span><span class="lines">@@ -914,7 +914,7 @@
</span><span class="cx">   FIND_MIN_VALID_REVISION_WORK(JOB_ID);
</span><span class="cx"> 
</span><span class="cx"> create table REVISION_CLEANUP_WORK (
</span><del>-  WORK_ID                       integer      primary key default nextval('WORKITEM_SEQ') not null, -- implicit index
</del><ins>+  WORK_ID                       integer      primary key default nextval('WORKITEM_SEQ'), -- implicit index
</ins><span class="cx">   JOB_ID                        integer      references JOB not null
</span><span class="cx"> );
</span><span class="cx"> 
</span><span class="lines">@@ -926,7 +926,7 @@
</span><span class="cx"> ------------------------
</span><span class="cx"> 
</span><span class="cx"> create table INBOX_CLEANUP_WORK (
</span><del>-  WORK_ID                       integer      primary key default nextval('WORKITEM_SEQ') not null, -- implicit index
</del><ins>+  WORK_ID                       integer      primary key default nextval('WORKITEM_SEQ'), -- implicit index
</ins><span class="cx">   JOB_ID                        integer      references JOB not null
</span><span class="cx"> );
</span><span class="cx"> 
</span><span class="lines">@@ -934,7 +934,7 @@
</span><span class="cx">    INBOX_CLEANUP_WORK(JOB_ID);
</span><span class="cx"> 
</span><span class="cx"> create table CLEANUP_ONE_INBOX_WORK (
</span><del>-  WORK_ID                       integer      primary key default nextval('WORKITEM_SEQ') not null, -- implicit index
</del><ins>+  WORK_ID                       integer      primary key default nextval('WORKITEM_SEQ'), -- implicit index
</ins><span class="cx">   JOB_ID                        integer      references JOB not null,
</span><span class="cx">   HOME_ID                       integer      not null unique references CALENDAR_HOME on delete cascade -- implicit index
</span><span class="cx"> );
</span><span class="lines">@@ -947,7 +947,7 @@
</span><span class="cx"> -------------------
</span><span class="cx"> 
</span><span class="cx"> create table SCHEDULE_WORK (
</span><del>-  WORK_ID                       integer      primary key default nextval('WORKITEM_SEQ') not null, -- implicit index
</del><ins>+  WORK_ID                       integer      primary key default nextval('WORKITEM_SEQ'), -- implicit index
</ins><span class="cx">   JOB_ID                        integer      references JOB not null,
</span><span class="cx">   ICALENDAR_UID                 varchar(255) not null,
</span><span class="cx">   WORK_TYPE                     varchar(255) not null
</span><span class="lines">@@ -1058,8 +1058,8 @@
</span><span class="cx"> create table SCHEDULE_REPLY_WORK (
</span><span class="cx">   WORK_ID                       integer      primary key references SCHEDULE_WORK on delete cascade, -- implicit index
</span><span class="cx">   HOME_RESOURCE_ID              integer      not null references CALENDAR_HOME on delete cascade,
</span><del>-  RESOURCE_ID                   integer      not null references CALENDAR_OBJECT on delete cascade,
-  CHANGED_RIDS                  text
</del><ins>+  RESOURCE_ID                   integer,     -- this references a possibly non-existent CALENDAR_OBJECT
+  ITIP_MSG                      text
</ins><span class="cx"> );
</span><span class="cx"> 
</span><span class="cx"> create index SCHEDULE_REPLY_WORK_HOME_RESOURCE_ID on
</span><span class="lines">@@ -1067,25 +1067,12 @@
</span><span class="cx"> create index SCHEDULE_REPLY_WORK_RESOURCE_ID on
</span><span class="cx">   SCHEDULE_REPLY_WORK(RESOURCE_ID);
</span><span class="cx"> 
</span><del>---------------------------------
--- Schedule Reply Cancel Work --
---------------------------------
-
-create table SCHEDULE_REPLY_CANCEL_WORK (
-  WORK_ID                       integer      primary key references SCHEDULE_WORK on delete cascade, -- implicit index
-  HOME_RESOURCE_ID              integer      not null references CALENDAR_HOME on delete cascade,
-  ICALENDAR_TEXT                text         not null
-);
-
-create index SCHEDULE_REPLY_CANCEL_WORK_HOME_RESOURCE_ID on
-  SCHEDULE_REPLY_CANCEL_WORK(HOME_RESOURCE_ID);
-
</del><span class="cx"> ----------------------------------
</span><span class="cx"> -- Principal Purge Polling Work --
</span><span class="cx"> ----------------------------------
</span><span class="cx"> 
</span><span class="cx"> create table PRINCIPAL_PURGE_POLLING_WORK (
</span><del>-  WORK_ID                       integer      primary key default nextval('WORKITEM_SEQ') not null, -- implicit index
</del><ins>+  WORK_ID                       integer      primary key default nextval('WORKITEM_SEQ'), -- implicit index
</ins><span class="cx">   JOB_ID                        integer      references JOB not null
</span><span class="cx"> );
</span><span class="cx"> 
</span><span class="lines">@@ -1097,7 +1084,7 @@
</span><span class="cx"> --------------------------------
</span><span class="cx"> 
</span><span class="cx"> create table PRINCIPAL_PURGE_CHECK_WORK (
</span><del>-  WORK_ID                       integer      primary key default nextval('WORKITEM_SEQ') not null, -- implicit index
</del><ins>+  WORK_ID                       integer      primary key default nextval('WORKITEM_SEQ'), -- implicit index
</ins><span class="cx">   JOB_ID                        integer      references JOB not null,
</span><span class="cx">   UID                           varchar(255) not null
</span><span class="cx"> );
</span><span class="lines">@@ -1112,7 +1099,7 @@
</span><span class="cx"> --------------------------
</span><span class="cx"> 
</span><span class="cx"> create table PRINCIPAL_PURGE_WORK (
</span><del>-  WORK_ID                       integer      primary key default nextval('WORKITEM_SEQ') not null, -- implicit index
</del><ins>+  WORK_ID                       integer      primary key default nextval('WORKITEM_SEQ'), -- implicit index
</ins><span class="cx">   JOB_ID                        integer      references JOB not null,
</span><span class="cx">   UID                           varchar(255) not null
</span><span class="cx"> );
</span><span class="lines">@@ -1128,7 +1115,7 @@
</span><span class="cx"> --------------------------------
</span><span class="cx"> 
</span><span class="cx"> create table PRINCIPAL_PURGE_HOME_WORK (
</span><del>-  WORK_ID                       integer      primary key default nextval('WORKITEM_SEQ') not null, -- implicit index
</del><ins>+  WORK_ID                       integer      primary key default nextval('WORKITEM_SEQ'), -- implicit index
</ins><span class="cx">   JOB_ID                        integer      references JOB not null,
</span><span class="cx">   HOME_RESOURCE_ID              integer      not null references CALENDAR_HOME on delete cascade
</span><span class="cx"> );
</span><span class="lines">@@ -1148,7 +1135,7 @@
</span><span class="cx">   VALUE                         varchar(255)
</span><span class="cx"> );
</span><span class="cx"> 
</span><del>-insert into CALENDARSERVER values ('VERSION', '49');
</del><ins>+insert into CALENDARSERVER values ('VERSION', '50');
</ins><span class="cx"> insert into CALENDARSERVER values ('CALENDAR-DATAVERSION', '6');
</span><span class="cx"> insert into CALENDARSERVER values ('ADDRESSBOOK-DATAVERSION', '2');
</span><span class="cx"> insert into CALENDARSERVER values ('NOTIFICATION-DATAVERSION', '1');
</span></span></pre></div>
<a id="CalendarServertrunktxdavcommondatastoresql_schemaoldoracledialectv49sql"></a>
<div class="addfile"><h4>Added: CalendarServer/trunk/txdav/common/datastore/sql_schema/old/oracle-dialect/v49.sql (0 => 14247)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/common/datastore/sql_schema/old/oracle-dialect/v49.sql                                (rev 0)
+++ CalendarServer/trunk/txdav/common/datastore/sql_schema/old/oracle-dialect/v49.sql        2015-01-06 16:44:21 UTC (rev 14247)
</span><span class="lines">@@ -0,0 +1,935 @@
</span><ins>+create sequence RESOURCE_ID_SEQ;
+create sequence JOB_SEQ;
+create sequence INSTANCE_ID_SEQ;
+create sequence ATTACHMENT_ID_SEQ;
+create sequence REVISION_SEQ;
+create sequence WORKITEM_SEQ;
+create table NODE_INFO (
+    &quot;HOSTNAME&quot; nvarchar2(255),
+    &quot;PID&quot; integer not null,
+    &quot;PORT&quot; integer not null,
+    &quot;TIME&quot; timestamp default CURRENT_TIMESTAMP at time zone 'UTC' not null, 
+    primary key (&quot;HOSTNAME&quot;, &quot;PORT&quot;)
+);
+
+create table NAMED_LOCK (
+    &quot;LOCK_NAME&quot; nvarchar2(255) primary key
+);
+
+create table JOB (
+    &quot;JOB_ID&quot; integer primary key not null,
+    &quot;WORK_TYPE&quot; nvarchar2(255),
+    &quot;PRIORITY&quot; integer default 0,
+    &quot;WEIGHT&quot; integer default 0,
+    &quot;NOT_BEFORE&quot; timestamp not null,
+    &quot;ASSIGNED&quot; timestamp default null,
+    &quot;OVERDUE&quot; timestamp default null,
+    &quot;FAILED&quot; integer default 0
+);
+
+create table CALENDAR_HOME (
+    &quot;RESOURCE_ID&quot; integer primary key,
+    &quot;OWNER_UID&quot; nvarchar2(255) unique,
+    &quot;STATUS&quot; integer default 0 not null,
+    &quot;DATAVERSION&quot; integer default 0 not null
+);
+
+create table HOME_STATUS (
+    &quot;ID&quot; integer primary key,
+    &quot;DESCRIPTION&quot; nvarchar2(16) unique
+);
+
+insert into HOME_STATUS (DESCRIPTION, ID) values ('normal', 0);
+insert into HOME_STATUS (DESCRIPTION, ID) values ('external', 1);
+insert into HOME_STATUS (DESCRIPTION, ID) values ('purging', 2);
+create table CALENDAR (
+    &quot;RESOURCE_ID&quot; integer primary key
+);
+
+create table CALENDAR_HOME_METADATA (
+    &quot;RESOURCE_ID&quot; integer primary key references CALENDAR_HOME on delete cascade,
+    &quot;QUOTA_USED_BYTES&quot; integer default 0 not null,
+    &quot;DEFAULT_EVENTS&quot; integer default null references CALENDAR on delete set null,
+    &quot;DEFAULT_TASKS&quot; integer default null references CALENDAR on delete set null,
+    &quot;DEFAULT_POLLS&quot; integer default null references CALENDAR on delete set null,
+    &quot;ALARM_VEVENT_TIMED&quot; nclob default null,
+    &quot;ALARM_VEVENT_ALLDAY&quot; nclob default null,
+    &quot;ALARM_VTODO_TIMED&quot; nclob default null,
+    &quot;ALARM_VTODO_ALLDAY&quot; nclob default null,
+    &quot;AVAILABILITY&quot; nclob default null,
+    &quot;CREATED&quot; timestamp default CURRENT_TIMESTAMP at time zone 'UTC',
+    &quot;MODIFIED&quot; timestamp default CURRENT_TIMESTAMP at time zone 'UTC'
+);
+
+create table CALENDAR_METADATA (
+    &quot;RESOURCE_ID&quot; integer primary key references CALENDAR on delete cascade,
+    &quot;SUPPORTED_COMPONENTS&quot; nvarchar2(255) default null,
+    &quot;CREATED&quot; timestamp default CURRENT_TIMESTAMP at time zone 'UTC',
+    &quot;MODIFIED&quot; timestamp default CURRENT_TIMESTAMP at time zone 'UTC'
+);
+
+create table NOTIFICATION_HOME (
+    &quot;RESOURCE_ID&quot; integer primary key,
+    &quot;OWNER_UID&quot; nvarchar2(255) unique,
+    &quot;STATUS&quot; integer default 0 not null,
+    &quot;DATAVERSION&quot; integer default 0 not null
+);
+
+create table NOTIFICATION (
+    &quot;RESOURCE_ID&quot; integer primary key,
+    &quot;NOTIFICATION_HOME_RESOURCE_ID&quot; integer not null references NOTIFICATION_HOME,
+    &quot;NOTIFICATION_UID&quot; nvarchar2(255),
+    &quot;NOTIFICATION_TYPE&quot; nvarchar2(255),
+    &quot;NOTIFICATION_DATA&quot; nclob,
+    &quot;MD5&quot; nchar(32),
+    &quot;CREATED&quot; timestamp default CURRENT_TIMESTAMP at time zone 'UTC',
+    &quot;MODIFIED&quot; timestamp default CURRENT_TIMESTAMP at time zone 'UTC', 
+    unique (&quot;NOTIFICATION_UID&quot;, &quot;NOTIFICATION_HOME_RESOURCE_ID&quot;)
+);
+
+create table CALENDAR_BIND (
+    &quot;CALENDAR_HOME_RESOURCE_ID&quot; integer not null references CALENDAR_HOME,
+    &quot;CALENDAR_RESOURCE_ID&quot; integer not null references CALENDAR on delete cascade,
+    &quot;EXTERNAL_ID&quot; integer default null,
+    &quot;CALENDAR_RESOURCE_NAME&quot; nvarchar2(255),
+    &quot;BIND_MODE&quot; integer not null,
+    &quot;BIND_STATUS&quot; integer not null,
+    &quot;BIND_REVISION&quot; integer default 0 not null,
+    &quot;MESSAGE&quot; nclob,
+    &quot;TRANSP&quot; integer default 0 not null,
+    &quot;ALARM_VEVENT_TIMED&quot; nclob default null,
+    &quot;ALARM_VEVENT_ALLDAY&quot; nclob default null,
+    &quot;ALARM_VTODO_TIMED&quot; nclob default null,
+    &quot;ALARM_VTODO_ALLDAY&quot; nclob default null,
+    &quot;TIMEZONE&quot; nclob default null, 
+    primary key (&quot;CALENDAR_HOME_RESOURCE_ID&quot;, &quot;CALENDAR_RESOURCE_ID&quot;), 
+    unique (&quot;CALENDAR_HOME_RESOURCE_ID&quot;, &quot;CALENDAR_RESOURCE_NAME&quot;)
+);
+
+create table CALENDAR_BIND_MODE (
+    &quot;ID&quot; integer primary key,
+    &quot;DESCRIPTION&quot; nvarchar2(16) unique
+);
+
+insert into CALENDAR_BIND_MODE (DESCRIPTION, ID) values ('own', 0);
+insert into CALENDAR_BIND_MODE (DESCRIPTION, ID) values ('read', 1);
+insert into CALENDAR_BIND_MODE (DESCRIPTION, ID) values ('write', 2);
+insert into CALENDAR_BIND_MODE (DESCRIPTION, ID) values ('direct', 3);
+insert into CALENDAR_BIND_MODE (DESCRIPTION, ID) values ('indirect', 4);
+insert into CALENDAR_BIND_MODE (DESCRIPTION, ID) values ('group', 5);
+insert into CALENDAR_BIND_MODE (DESCRIPTION, ID) values ('group_read', 6);
+insert into CALENDAR_BIND_MODE (DESCRIPTION, ID) values ('group_write', 7);
+create table CALENDAR_BIND_STATUS (
+    &quot;ID&quot; integer primary key,
+    &quot;DESCRIPTION&quot; nvarchar2(16) unique
+);
+
+insert into CALENDAR_BIND_STATUS (DESCRIPTION, ID) values ('invited', 0);
+insert into CALENDAR_BIND_STATUS (DESCRIPTION, ID) values ('accepted', 1);
+insert into CALENDAR_BIND_STATUS (DESCRIPTION, ID) values ('declined', 2);
+insert into CALENDAR_BIND_STATUS (DESCRIPTION, ID) values ('invalid', 3);
+insert into CALENDAR_BIND_STATUS (DESCRIPTION, ID) values ('deleted', 4);
+create table CALENDAR_TRANSP (
+    &quot;ID&quot; integer primary key,
+    &quot;DESCRIPTION&quot; nvarchar2(16) unique
+);
+
+insert into CALENDAR_TRANSP (DESCRIPTION, ID) values ('opaque', 0);
+insert into CALENDAR_TRANSP (DESCRIPTION, ID) values ('transparent', 1);
+create table CALENDAR_OBJECT (
+    &quot;RESOURCE_ID&quot; integer primary key,
+    &quot;CALENDAR_RESOURCE_ID&quot; integer not null references CALENDAR on delete cascade,
+    &quot;RESOURCE_NAME&quot; nvarchar2(255),
+    &quot;ICALENDAR_TEXT&quot; nclob,
+    &quot;ICALENDAR_UID&quot; nvarchar2(255),
+    &quot;ICALENDAR_TYPE&quot; nvarchar2(255),
+    &quot;ATTACHMENTS_MODE&quot; integer default 0 not null,
+    &quot;DROPBOX_ID&quot; nvarchar2(255),
+    &quot;ORGANIZER&quot; nvarchar2(255),
+    &quot;RECURRANCE_MIN&quot; date,
+    &quot;RECURRANCE_MAX&quot; date,
+    &quot;ACCESS&quot; integer default 0 not null,
+    &quot;SCHEDULE_OBJECT&quot; integer default 0,
+    &quot;SCHEDULE_TAG&quot; nvarchar2(36) default null,
+    &quot;SCHEDULE_ETAGS&quot; nclob default null,
+    &quot;PRIVATE_COMMENTS&quot; integer default 0 not null,
+    &quot;MD5&quot; nchar(32),
+    &quot;CREATED&quot; timestamp default CURRENT_TIMESTAMP at time zone 'UTC',
+    &quot;MODIFIED&quot; timestamp default CURRENT_TIMESTAMP at time zone 'UTC',
+    &quot;DATAVERSION&quot; integer default 0 not null, 
+    unique (&quot;CALENDAR_RESOURCE_ID&quot;, &quot;RESOURCE_NAME&quot;)
+);
+
+create table CALENDAR_OBJ_ATTACHMENTS_MODE (
+    &quot;ID&quot; integer primary key,
+    &quot;DESCRIPTION&quot; nvarchar2(16) unique
+);
+
+insert into CALENDAR_OBJ_ATTACHMENTS_MODE (DESCRIPTION, ID) values ('none', 0);
+insert into CALENDAR_OBJ_ATTACHMENTS_MODE (DESCRIPTION, ID) values ('read', 1);
+insert into CALENDAR_OBJ_ATTACHMENTS_MODE (DESCRIPTION, ID) values ('write', 2);
+create table CALENDAR_ACCESS_TYPE (
+    &quot;ID&quot; integer primary key,
+    &quot;DESCRIPTION&quot; nvarchar2(32) unique
+);
+
+insert into CALENDAR_ACCESS_TYPE (DESCRIPTION, ID) values ('', 0);
+insert into CALENDAR_ACCESS_TYPE (DESCRIPTION, ID) values ('public', 1);
+insert into CALENDAR_ACCESS_TYPE (DESCRIPTION, ID) values ('private', 2);
+insert into CALENDAR_ACCESS_TYPE (DESCRIPTION, ID) values ('confidential', 3);
+insert into CALENDAR_ACCESS_TYPE (DESCRIPTION, ID) values ('restricted', 4);
+create table TIME_RANGE (
+    &quot;INSTANCE_ID&quot; integer primary key,
+    &quot;CALENDAR_RESOURCE_ID&quot; integer not null references CALENDAR on delete cascade,
+    &quot;CALENDAR_OBJECT_RESOURCE_ID&quot; integer not null references CALENDAR_OBJECT on delete cascade,
+    &quot;FLOATING&quot; integer not null,
+    &quot;START_DATE&quot; timestamp not null,
+    &quot;END_DATE&quot; timestamp not null,
+    &quot;FBTYPE&quot; integer not null,
+    &quot;TRANSPARENT&quot; integer not null
+);
+
+create table FREE_BUSY_TYPE (
+    &quot;ID&quot; integer primary key,
+    &quot;DESCRIPTION&quot; nvarchar2(16) unique
+);
+
+insert into FREE_BUSY_TYPE (DESCRIPTION, ID) values ('unknown', 0);
+insert into FREE_BUSY_TYPE (DESCRIPTION, ID) values ('free', 1);
+insert into FREE_BUSY_TYPE (DESCRIPTION, ID) values ('busy', 2);
+insert into FREE_BUSY_TYPE (DESCRIPTION, ID) values ('busy-unavailable', 3);
+insert into FREE_BUSY_TYPE (DESCRIPTION, ID) values ('busy-tentative', 4);
+create table PERUSER (
+    &quot;TIME_RANGE_INSTANCE_ID&quot; integer not null references TIME_RANGE on delete cascade,
+    &quot;USER_ID&quot; nvarchar2(255),
+    &quot;TRANSPARENT&quot; integer not null,
+    &quot;ADJUSTED_START_DATE&quot; timestamp default null,
+    &quot;ADJUSTED_END_DATE&quot; timestamp default null, 
+    primary key (&quot;TIME_RANGE_INSTANCE_ID&quot;, &quot;USER_ID&quot;)
+);
+
+create table ATTACHMENT (
+    &quot;ATTACHMENT_ID&quot; integer primary key,
+    &quot;CALENDAR_HOME_RESOURCE_ID&quot; integer not null references CALENDAR_HOME,
+    &quot;DROPBOX_ID&quot; nvarchar2(255),
+    &quot;CONTENT_TYPE&quot; nvarchar2(255),
+    &quot;SIZE&quot; integer not null,
+    &quot;MD5&quot; nchar(32),
+    &quot;CREATED&quot; timestamp default CURRENT_TIMESTAMP at time zone 'UTC',
+    &quot;MODIFIED&quot; timestamp default CURRENT_TIMESTAMP at time zone 'UTC',
+    &quot;PATH&quot; nvarchar2(1024)
+);
+
+create table ATTACHMENT_CALENDAR_OBJECT (
+    &quot;ATTACHMENT_ID&quot; integer not null references ATTACHMENT on delete cascade,
+    &quot;MANAGED_ID&quot; nvarchar2(255),
+    &quot;CALENDAR_OBJECT_RESOURCE_ID&quot; integer not null references CALENDAR_OBJECT on delete cascade, 
+    primary key (&quot;ATTACHMENT_ID&quot;, &quot;CALENDAR_OBJECT_RESOURCE_ID&quot;), 
+    unique (&quot;MANAGED_ID&quot;, &quot;CALENDAR_OBJECT_RESOURCE_ID&quot;)
+);
+
+create table RESOURCE_PROPERTY (
+    &quot;RESOURCE_ID&quot; integer not null,
+    &quot;NAME&quot; nvarchar2(255),
+    &quot;VALUE&quot; nclob,
+    &quot;VIEWER_UID&quot; nvarchar2(255), 
+    primary key (&quot;RESOURCE_ID&quot;, &quot;NAME&quot;, &quot;VIEWER_UID&quot;)
+);
+
+create table ADDRESSBOOK_HOME (
+    &quot;RESOURCE_ID&quot; integer primary key,
+    &quot;ADDRESSBOOK_PROPERTY_STORE_ID&quot; integer not null,
+    &quot;OWNER_UID&quot; nvarchar2(255) unique,
+    &quot;STATUS&quot; integer default 0 not null,
+    &quot;DATAVERSION&quot; integer default 0 not null
+);
+
+create table ADDRESSBOOK_HOME_METADATA (
+    &quot;RESOURCE_ID&quot; integer primary key references ADDRESSBOOK_HOME on delete cascade,
+    &quot;QUOTA_USED_BYTES&quot; integer default 0 not null,
+    &quot;CREATED&quot; timestamp default CURRENT_TIMESTAMP at time zone 'UTC',
+    &quot;MODIFIED&quot; timestamp default CURRENT_TIMESTAMP at time zone 'UTC'
+);
+
+create table SHARED_ADDRESSBOOK_BIND (
+    &quot;ADDRESSBOOK_HOME_RESOURCE_ID&quot; integer not null references ADDRESSBOOK_HOME,
+    &quot;OWNER_HOME_RESOURCE_ID&quot; integer not null references ADDRESSBOOK_HOME on delete cascade,
+    &quot;EXTERNAL_ID&quot; integer default null,
+    &quot;ADDRESSBOOK_RESOURCE_NAME&quot; nvarchar2(255),
+    &quot;BIND_MODE&quot; integer not null,
+    &quot;BIND_STATUS&quot; integer not null,
+    &quot;BIND_REVISION&quot; integer default 0 not null,
+    &quot;MESSAGE&quot; nclob, 
+    primary key (&quot;ADDRESSBOOK_HOME_RESOURCE_ID&quot;, &quot;OWNER_HOME_RESOURCE_ID&quot;), 
+    unique (&quot;ADDRESSBOOK_HOME_RESOURCE_ID&quot;, &quot;ADDRESSBOOK_RESOURCE_NAME&quot;)
+);
+
+create table ADDRESSBOOK_OBJECT (
+    &quot;RESOURCE_ID&quot; integer primary key,
+    &quot;ADDRESSBOOK_HOME_RESOURCE_ID&quot; integer not null references ADDRESSBOOK_HOME on delete cascade,
+    &quot;RESOURCE_NAME&quot; nvarchar2(255),
+    &quot;VCARD_TEXT&quot; nclob,
+    &quot;VCARD_UID&quot; nvarchar2(255),
+    &quot;KIND&quot; integer not null,
+    &quot;MD5&quot; nchar(32),
+    &quot;CREATED&quot; timestamp default CURRENT_TIMESTAMP at time zone 'UTC',
+    &quot;MODIFIED&quot; timestamp default CURRENT_TIMESTAMP at time zone 'UTC',
+    &quot;DATAVERSION&quot; integer default 0 not null, 
+    unique (&quot;ADDRESSBOOK_HOME_RESOURCE_ID&quot;, &quot;RESOURCE_NAME&quot;), 
+    unique (&quot;ADDRESSBOOK_HOME_RESOURCE_ID&quot;, &quot;VCARD_UID&quot;)
+);
+
+create table ADDRESSBOOK_OBJECT_KIND (
+    &quot;ID&quot; integer primary key,
+    &quot;DESCRIPTION&quot; nvarchar2(16) unique
+);
+
+insert into ADDRESSBOOK_OBJECT_KIND (DESCRIPTION, ID) values ('person', 0);
+insert into ADDRESSBOOK_OBJECT_KIND (DESCRIPTION, ID) values ('group', 1);
+insert into ADDRESSBOOK_OBJECT_KIND (DESCRIPTION, ID) values ('resource', 2);
+insert into ADDRESSBOOK_OBJECT_KIND (DESCRIPTION, ID) values ('location', 3);
+create table ABO_MEMBERS (
+    &quot;GROUP_ID&quot; integer not null,
+    &quot;ADDRESSBOOK_ID&quot; integer not null references ADDRESSBOOK_HOME on delete cascade,
+    &quot;MEMBER_ID&quot; integer not null,
+    &quot;REVISION&quot; integer not null,
+    &quot;REMOVED&quot; integer default 0 not null,
+    &quot;MODIFIED&quot; timestamp default CURRENT_TIMESTAMP at time zone 'UTC', 
+    primary key (&quot;GROUP_ID&quot;, &quot;MEMBER_ID&quot;, &quot;REVISION&quot;)
+);
+
+create table ABO_FOREIGN_MEMBERS (
+    &quot;GROUP_ID&quot; integer not null references ADDRESSBOOK_OBJECT on delete cascade,
+    &quot;ADDRESSBOOK_ID&quot; integer not null references ADDRESSBOOK_HOME on delete cascade,
+    &quot;MEMBER_ADDRESS&quot; nvarchar2(255), 
+    primary key (&quot;GROUP_ID&quot;, &quot;MEMBER_ADDRESS&quot;)
+);
+
+create table SHARED_GROUP_BIND (
+    &quot;ADDRESSBOOK_HOME_RESOURCE_ID&quot; integer not null references ADDRESSBOOK_HOME,
+    &quot;GROUP_RESOURCE_ID&quot; integer not null references ADDRESSBOOK_OBJECT on delete cascade,
+    &quot;EXTERNAL_ID&quot; integer default null,
+    &quot;GROUP_ADDRESSBOOK_NAME&quot; nvarchar2(255),
+    &quot;BIND_MODE&quot; integer not null,
+    &quot;BIND_STATUS&quot; integer not null,
+    &quot;BIND_REVISION&quot; integer default 0 not null,
+    &quot;MESSAGE&quot; nclob, 
+    primary key (&quot;ADDRESSBOOK_HOME_RESOURCE_ID&quot;, &quot;GROUP_RESOURCE_ID&quot;), 
+    unique (&quot;ADDRESSBOOK_HOME_RESOURCE_ID&quot;, &quot;GROUP_ADDRESSBOOK_NAME&quot;)
+);
+
+create table CALENDAR_OBJECT_REVISIONS (
+    &quot;CALENDAR_HOME_RESOURCE_ID&quot; integer not null references CALENDAR_HOME,
+    &quot;CALENDAR_RESOURCE_ID&quot; integer references CALENDAR,
+    &quot;CALENDAR_NAME&quot; nvarchar2(255) default null,
+    &quot;RESOURCE_NAME&quot; nvarchar2(255),
+    &quot;REVISION&quot; integer not null,
+    &quot;DELETED&quot; integer not null,
+    &quot;MODIFIED&quot; timestamp default CURRENT_TIMESTAMP at time zone 'UTC', 
+    unique (&quot;CALENDAR_HOME_RESOURCE_ID&quot;, &quot;CALENDAR_RESOURCE_ID&quot;, &quot;CALENDAR_NAME&quot;, &quot;RESOURCE_NAME&quot;)
+);
+
+create table ADDRESSBOOK_OBJECT_REVISIONS (
+    &quot;ADDRESSBOOK_HOME_RESOURCE_ID&quot; integer not null references ADDRESSBOOK_HOME,
+    &quot;OWNER_HOME_RESOURCE_ID&quot; integer references ADDRESSBOOK_HOME,
+    &quot;ADDRESSBOOK_NAME&quot; nvarchar2(255) default null,
+    &quot;OBJECT_RESOURCE_ID&quot; integer default 0,
+    &quot;RESOURCE_NAME&quot; nvarchar2(255),
+    &quot;REVISION&quot; integer not null,
+    &quot;DELETED&quot; integer not null,
+    &quot;MODIFIED&quot; timestamp default CURRENT_TIMESTAMP at time zone 'UTC', 
+    unique (&quot;ADDRESSBOOK_HOME_RESOURCE_ID&quot;, &quot;OWNER_HOME_RESOURCE_ID&quot;, &quot;ADDRESSBOOK_NAME&quot;, &quot;RESOURCE_NAME&quot;)
+);
+
+create table NOTIFICATION_OBJECT_REVISIONS (
+    &quot;NOTIFICATION_HOME_RESOURCE_ID&quot; integer not null references NOTIFICATION_HOME on delete cascade,
+    &quot;RESOURCE_NAME&quot; nvarchar2(255),
+    &quot;REVISION&quot; integer not null,
+    &quot;DELETED&quot; integer not null,
+    &quot;MODIFIED&quot; timestamp default CURRENT_TIMESTAMP at time zone 'UTC', 
+    unique (&quot;NOTIFICATION_HOME_RESOURCE_ID&quot;, &quot;RESOURCE_NAME&quot;)
+);
+
+create table APN_SUBSCRIPTIONS (
+    &quot;TOKEN&quot; nvarchar2(255),
+    &quot;RESOURCE_KEY&quot; nvarchar2(255),
+    &quot;MODIFIED&quot; integer not null,
+    &quot;SUBSCRIBER_GUID&quot; nvarchar2(255),
+    &quot;USER_AGENT&quot; nvarchar2(255) default null,
+    &quot;IP_ADDR&quot; nvarchar2(255) default null, 
+    primary key (&quot;TOKEN&quot;, &quot;RESOURCE_KEY&quot;)
+);
+
+create table IMIP_TOKENS (
+    &quot;TOKEN&quot; nvarchar2(255),
+    &quot;ORGANIZER&quot; nvarchar2(255),
+    &quot;ATTENDEE&quot; nvarchar2(255),
+    &quot;ICALUID&quot; nvarchar2(255),
+    &quot;ACCESSED&quot; timestamp default CURRENT_TIMESTAMP at time zone 'UTC', 
+    primary key (&quot;ORGANIZER&quot;, &quot;ATTENDEE&quot;, &quot;ICALUID&quot;)
+);
+
+create table IMIP_INVITATION_WORK (
+    &quot;WORK_ID&quot; integer primary key not null,
+    &quot;JOB_ID&quot; integer not null references JOB,
+    &quot;FROM_ADDR&quot; nvarchar2(255),
+    &quot;TO_ADDR&quot; nvarchar2(255),
+    &quot;ICALENDAR_TEXT&quot; nclob
+);
+
+create table IMIP_POLLING_WORK (
+    &quot;WORK_ID&quot; integer primary key not null,
+    &quot;JOB_ID&quot; integer not null references JOB
+);
+
+create table IMIP_REPLY_WORK (
+    &quot;WORK_ID&quot; integer primary key not null,
+    &quot;JOB_ID&quot; integer not null references JOB,
+    &quot;ORGANIZER&quot; nvarchar2(255),
+    &quot;ATTENDEE&quot; nvarchar2(255),
+    &quot;ICALENDAR_TEXT&quot; nclob
+);
+
+create table PUSH_NOTIFICATION_WORK (
+    &quot;WORK_ID&quot; integer primary key not null,
+    &quot;JOB_ID&quot; integer not null references JOB,
+    &quot;PUSH_ID&quot; nvarchar2(255),
+    &quot;PUSH_PRIORITY&quot; integer not null
+);
+
+create table GROUP_CACHER_POLLING_WORK (
+    &quot;WORK_ID&quot; integer primary key not null,
+    &quot;JOB_ID&quot; integer not null references JOB
+);
+
+create table GROUP_REFRESH_WORK (
+    &quot;WORK_ID&quot; integer primary key not null,
+    &quot;JOB_ID&quot; integer not null references JOB,
+    &quot;GROUP_UID&quot; nvarchar2(255)
+);
+
+create table GROUP_DELEGATE_CHANGES_WORK (
+    &quot;WORK_ID&quot; integer primary key not null,
+    &quot;JOB_ID&quot; integer not null references JOB,
+    &quot;DELEGATOR_UID&quot; nvarchar2(255),
+    &quot;READ_DELEGATE_UID&quot; nvarchar2(255),
+    &quot;WRITE_DELEGATE_UID&quot; nvarchar2(255)
+);
+
+create table GROUPS (
+    &quot;GROUP_ID&quot; integer primary key,
+    &quot;NAME&quot; nvarchar2(255),
+    &quot;GROUP_UID&quot; nvarchar2(255) unique,
+    &quot;MEMBERSHIP_HASH&quot; nvarchar2(255),
+    &quot;EXTANT&quot; integer default 1,
+    &quot;CREATED&quot; timestamp default CURRENT_TIMESTAMP at time zone 'UTC',
+    &quot;MODIFIED&quot; timestamp default CURRENT_TIMESTAMP at time zone 'UTC'
+);
+
+create table GROUP_MEMBERSHIP (
+    &quot;GROUP_ID&quot; integer not null references GROUPS on delete cascade,
+    &quot;MEMBER_UID&quot; nvarchar2(255), 
+    primary key (&quot;GROUP_ID&quot;, &quot;MEMBER_UID&quot;)
+);
+
+create table GROUP_ATTENDEE_RECONCILE_WORK (
+    &quot;WORK_ID&quot; integer primary key not null,
+    &quot;JOB_ID&quot; integer not null references JOB,
+    &quot;RESOURCE_ID&quot; integer not null references CALENDAR_OBJECT on delete cascade,
+    &quot;GROUP_ID&quot; integer not null references GROUPS on delete cascade
+);
+
+create table GROUP_ATTENDEE (
+    &quot;GROUP_ID&quot; integer not null references GROUPS on delete cascade,
+    &quot;RESOURCE_ID&quot; integer not null references CALENDAR_OBJECT on delete cascade,
+    &quot;MEMBERSHIP_HASH&quot; nvarchar2(255), 
+    primary key (&quot;GROUP_ID&quot;, &quot;RESOURCE_ID&quot;)
+);
+
+create table GROUP_SHAREE_RECONCILE_WORK (
+    &quot;WORK_ID&quot; integer primary key not null,
+    &quot;JOB_ID&quot; integer not null references JOB,
+    &quot;CALENDAR_ID&quot; integer not null references CALENDAR on delete cascade,
+    &quot;GROUP_ID&quot; integer not null references GROUPS on delete cascade
+);
+
+create table GROUP_SHAREE (
+    &quot;GROUP_ID&quot; integer not null references GROUPS on delete cascade,
+    &quot;CALENDAR_ID&quot; integer not null references CALENDAR on delete cascade,
+    &quot;GROUP_BIND_MODE&quot; integer not null,
+    &quot;MEMBERSHIP_HASH&quot; nvarchar2(255), 
+    primary key (&quot;GROUP_ID&quot;, &quot;CALENDAR_ID&quot;)
+);
+
+create table DELEGATES (
+    &quot;DELEGATOR&quot; nvarchar2(255),
+    &quot;DELEGATE&quot; nvarchar2(255),
+    &quot;READ_WRITE&quot; integer not null, 
+    primary key (&quot;DELEGATOR&quot;, &quot;READ_WRITE&quot;, &quot;DELEGATE&quot;)
+);
+
+create table DELEGATE_GROUPS (
+    &quot;DELEGATOR&quot; nvarchar2(255),
+    &quot;GROUP_ID&quot; integer not null references GROUPS on delete cascade,
+    &quot;READ_WRITE&quot; integer not null,
+    &quot;IS_EXTERNAL&quot; integer not null, 
+    primary key (&quot;DELEGATOR&quot;, &quot;READ_WRITE&quot;, &quot;GROUP_ID&quot;)
+);
+
+create table EXTERNAL_DELEGATE_GROUPS (
+    &quot;DELEGATOR&quot; nvarchar2(255) primary key,
+    &quot;GROUP_UID_READ&quot; nvarchar2(255),
+    &quot;GROUP_UID_WRITE&quot; nvarchar2(255)
+);
+
+create table CALENDAR_OBJECT_SPLITTER_WORK (
+    &quot;WORK_ID&quot; integer primary key not null,
+    &quot;JOB_ID&quot; integer not null references JOB,
+    &quot;RESOURCE_ID&quot; integer not null references CALENDAR_OBJECT on delete cascade
+);
+
+create table FIND_MIN_VALID_REVISION_WORK (
+    &quot;WORK_ID&quot; integer primary key not null,
+    &quot;JOB_ID&quot; integer not null references JOB
+);
+
+create table REVISION_CLEANUP_WORK (
+    &quot;WORK_ID&quot; integer primary key not null,
+    &quot;JOB_ID&quot; integer not null references JOB
+);
+
+create table INBOX_CLEANUP_WORK (
+    &quot;WORK_ID&quot; integer primary key not null,
+    &quot;JOB_ID&quot; integer not null references JOB
+);
+
+create table CLEANUP_ONE_INBOX_WORK (
+    &quot;WORK_ID&quot; integer primary key not null,
+    &quot;JOB_ID&quot; integer not null references JOB,
+    &quot;HOME_ID&quot; integer not null unique references CALENDAR_HOME on delete cascade
+);
+
+create table SCHEDULE_WORK (
+    &quot;WORK_ID&quot; integer primary key not null,
+    &quot;JOB_ID&quot; integer not null references JOB,
+    &quot;ICALENDAR_UID&quot; nvarchar2(255),
+    &quot;WORK_TYPE&quot; nvarchar2(255)
+);
+
+create table SCHEDULE_REFRESH_WORK (
+    &quot;WORK_ID&quot; integer primary key references SCHEDULE_WORK on delete cascade,
+    &quot;HOME_RESOURCE_ID&quot; integer not null references CALENDAR_HOME on delete cascade,
+    &quot;RESOURCE_ID&quot; integer not null references CALENDAR_OBJECT on delete cascade,
+    &quot;ATTENDEE_COUNT&quot; integer
+);
+
+create table SCHEDULE_REFRESH_ATTENDEES (
+    &quot;RESOURCE_ID&quot; integer not null references CALENDAR_OBJECT on delete cascade,
+    &quot;ATTENDEE&quot; nvarchar2(255), 
+    primary key (&quot;RESOURCE_ID&quot;, &quot;ATTENDEE&quot;)
+);
+
+create table SCHEDULE_AUTO_REPLY_WORK (
+    &quot;WORK_ID&quot; integer primary key references SCHEDULE_WORK on delete cascade,
+    &quot;HOME_RESOURCE_ID&quot; integer not null references CALENDAR_HOME on delete cascade,
+    &quot;RESOURCE_ID&quot; integer not null references CALENDAR_OBJECT on delete cascade,
+    &quot;PARTSTAT&quot; nvarchar2(255)
+);
+
+create table SCHEDULE_ORGANIZER_WORK (
+    &quot;WORK_ID&quot; integer primary key references SCHEDULE_WORK on delete cascade,
+    &quot;SCHEDULE_ACTION&quot; integer not null,
+    &quot;HOME_RESOURCE_ID&quot; integer not null references CALENDAR_HOME on delete cascade,
+    &quot;RESOURCE_ID&quot; integer,
+    &quot;ICALENDAR_TEXT_OLD&quot; nclob,
+    &quot;ICALENDAR_TEXT_NEW&quot; nclob,
+    &quot;ATTENDEE_COUNT&quot; integer,
+    &quot;SMART_MERGE&quot; integer
+);
+
+create table SCHEDULE_ACTION (
+    &quot;ID&quot; integer primary key,
+    &quot;DESCRIPTION&quot; nvarchar2(16) unique
+);
+
+insert into SCHEDULE_ACTION (DESCRIPTION, ID) values ('create', 0);
+insert into SCHEDULE_ACTION (DESCRIPTION, ID) values ('modify', 1);
+insert into SCHEDULE_ACTION (DESCRIPTION, ID) values ('modify-cancelled', 2);
+insert into SCHEDULE_ACTION (DESCRIPTION, ID) values ('remove', 3);
+create table SCHEDULE_ORGANIZER_SEND_WORK (
+    &quot;WORK_ID&quot; integer primary key references SCHEDULE_WORK on delete cascade,
+    &quot;SCHEDULE_ACTION&quot; integer not null,
+    &quot;HOME_RESOURCE_ID&quot; integer not null references CALENDAR_HOME on delete cascade,
+    &quot;RESOURCE_ID&quot; integer,
+    &quot;ATTENDEE&quot; nvarchar2(255),
+    &quot;ITIP_MSG&quot; nclob,
+    &quot;NO_REFRESH&quot; integer
+);
+
+create table SCHEDULE_REPLY_WORK (
+    &quot;WORK_ID&quot; integer primary key references SCHEDULE_WORK on delete cascade,
+    &quot;HOME_RESOURCE_ID&quot; integer not null references CALENDAR_HOME on delete cascade,
+    &quot;RESOURCE_ID&quot; integer not null references CALENDAR_OBJECT on delete cascade,
+    &quot;CHANGED_RIDS&quot; nclob
+);
+
+create table SCHEDULE_REPLY_CANCEL_WORK (
+    &quot;WORK_ID&quot; integer primary key references SCHEDULE_WORK on delete cascade,
+    &quot;HOME_RESOURCE_ID&quot; integer not null references CALENDAR_HOME on delete cascade,
+    &quot;ICALENDAR_TEXT&quot; nclob
+);
+
+create table PRINCIPAL_PURGE_POLLING_WORK (
+    &quot;WORK_ID&quot; integer primary key not null,
+    &quot;JOB_ID&quot; integer not null references JOB
+);
+
+create table PRINCIPAL_PURGE_CHECK_WORK (
+    &quot;WORK_ID&quot; integer primary key not null,
+    &quot;JOB_ID&quot; integer not null references JOB,
+    &quot;UID&quot; nvarchar2(255)
+);
+
+create table PRINCIPAL_PURGE_WORK (
+    &quot;WORK_ID&quot; integer primary key not null,
+    &quot;JOB_ID&quot; integer not null references JOB,
+    &quot;UID&quot; nvarchar2(255)
+);
+
+create table PRINCIPAL_PURGE_HOME_WORK (
+    &quot;WORK_ID&quot; integer primary key not null,
+    &quot;JOB_ID&quot; integer not null references JOB,
+    &quot;HOME_RESOURCE_ID&quot; integer not null references CALENDAR_HOME on delete cascade
+);
+
+create table CALENDARSERVER (
+    &quot;NAME&quot; nvarchar2(255) primary key,
+    &quot;VALUE&quot; nvarchar2(255)
+);
+
+insert into CALENDARSERVER (NAME, VALUE) values ('VERSION', '49');
+insert into CALENDARSERVER (NAME, VALUE) values ('CALENDAR-DATAVERSION', '6');
+insert into CALENDARSERVER (NAME, VALUE) values ('ADDRESSBOOK-DATAVERSION', '2');
+insert into CALENDARSERVER (NAME, VALUE) values ('NOTIFICATION-DATAVERSION', '1');
+insert into CALENDARSERVER (NAME, VALUE) values ('MIN-VALID-REVISION', '1');
+create index CALENDAR_HOME_METADAT_3cb9049e on CALENDAR_HOME_METADATA (
+    DEFAULT_EVENTS
+);
+
+create index CALENDAR_HOME_METADAT_d55e5548 on CALENDAR_HOME_METADATA (
+    DEFAULT_TASKS
+);
+
+create index CALENDAR_HOME_METADAT_910264ce on CALENDAR_HOME_METADATA (
+    DEFAULT_POLLS
+);
+
+create index NOTIFICATION_NOTIFICA_f891f5f9 on NOTIFICATION (
+    NOTIFICATION_HOME_RESOURCE_ID
+);
+
+create index CALENDAR_BIND_RESOURC_e57964d4 on CALENDAR_BIND (
+    CALENDAR_RESOURCE_ID
+);
+
+create index CALENDAR_OBJECT_CALEN_a9a453a9 on CALENDAR_OBJECT (
+    CALENDAR_RESOURCE_ID,
+    ICALENDAR_UID
+);
+
+create index CALENDAR_OBJECT_CALEN_c4dc619c on CALENDAR_OBJECT (
+    CALENDAR_RESOURCE_ID,
+    RECURRANCE_MAX,
+    RECURRANCE_MIN
+);
+
+create index CALENDAR_OBJECT_ICALE_82e731d5 on CALENDAR_OBJECT (
+    ICALENDAR_UID
+);
+
+create index CALENDAR_OBJECT_DROPB_de041d80 on CALENDAR_OBJECT (
+    DROPBOX_ID
+);
+
+create index TIME_RANGE_CALENDAR_R_beb6e7eb on TIME_RANGE (
+    CALENDAR_RESOURCE_ID
+);
+
+create index TIME_RANGE_CALENDAR_O_acf37bd1 on TIME_RANGE (
+    CALENDAR_OBJECT_RESOURCE_ID
+);
+
+create index ATTACHMENT_CALENDAR_H_0078845c on ATTACHMENT (
+    CALENDAR_HOME_RESOURCE_ID
+);
+
+create index ATTACHMENT_DROPBOX_ID_5073cf23 on ATTACHMENT (
+    DROPBOX_ID
+);
+
+create index ATTACHMENT_CALENDAR_O_81508484 on ATTACHMENT_CALENDAR_OBJECT (
+    CALENDAR_OBJECT_RESOURCE_ID
+);
+
+create index SHARED_ADDRESSBOOK_BI_e9a2e6d4 on SHARED_ADDRESSBOOK_BIND (
+    OWNER_HOME_RESOURCE_ID
+);
+
+create index ABO_MEMBERS_ADDRESSBO_4effa879 on ABO_MEMBERS (
+    ADDRESSBOOK_ID
+);
+
+create index ABO_MEMBERS_MEMBER_ID_8d66adcf on ABO_MEMBERS (
+    MEMBER_ID
+);
+
+create index ABO_FOREIGN_MEMBERS_A_1fd2c5e9 on ABO_FOREIGN_MEMBERS (
+    ADDRESSBOOK_ID
+);
+
+create index SHARED_GROUP_BIND_RES_cf52f95d on SHARED_GROUP_BIND (
+    GROUP_RESOURCE_ID
+);
+
+create index CALENDAR_OBJECT_REVIS_6d9d929c on CALENDAR_OBJECT_REVISIONS (
+    CALENDAR_RESOURCE_ID,
+    RESOURCE_NAME,
+    DELETED,
+    REVISION
+);
+
+create index CALENDAR_OBJECT_REVIS_265c8acf on CALENDAR_OBJECT_REVISIONS (
+    CALENDAR_RESOURCE_ID,
+    REVISION
+);
+
+create index CALENDAR_OBJECT_REVIS_550b1c56 on CALENDAR_OBJECT_REVISIONS (
+    CALENDAR_HOME_RESOURCE_ID,
+    REVISION
+);
+
+create index ADDRESSBOOK_OBJECT_RE_00fe8288 on ADDRESSBOOK_OBJECT_REVISIONS (
+    OWNER_HOME_RESOURCE_ID,
+    RESOURCE_NAME,
+    DELETED,
+    REVISION
+);
+
+create index ADDRESSBOOK_OBJECT_RE_45004780 on ADDRESSBOOK_OBJECT_REVISIONS (
+    OWNER_HOME_RESOURCE_ID,
+    REVISION
+);
+
+create index NOTIFICATION_OBJECT_R_036a9cee on NOTIFICATION_OBJECT_REVISIONS (
+    NOTIFICATION_HOME_RESOURCE_ID,
+    REVISION
+);
+
+create index APN_SUBSCRIPTIONS_RES_9610d78e on APN_SUBSCRIPTIONS (
+    RESOURCE_KEY
+);
+
+create index IMIP_TOKENS_TOKEN_e94b918f on IMIP_TOKENS (
+    TOKEN
+);
+
+create index IMIP_INVITATION_WORK__586d064c on IMIP_INVITATION_WORK (
+    JOB_ID
+);
+
+create index IMIP_POLLING_WORK_JOB_d5535891 on IMIP_POLLING_WORK (
+    JOB_ID
+);
+
+create index IMIP_REPLY_WORK_JOB_I_bf4ae73e on IMIP_REPLY_WORK (
+    JOB_ID
+);
+
+create index PUSH_NOTIFICATION_WOR_8bbab117 on PUSH_NOTIFICATION_WORK (
+    JOB_ID
+);
+
+create index PUSH_NOTIFICATION_WOR_3a3ee588 on PUSH_NOTIFICATION_WORK (
+    PUSH_ID
+);
+
+create index GROUP_CACHER_POLLING__6eb3151c on GROUP_CACHER_POLLING_WORK (
+    JOB_ID
+);
+
+create index GROUP_REFRESH_WORK_JO_717ede20 on GROUP_REFRESH_WORK (
+    JOB_ID
+);
+
+create index GROUP_REFRESH_WORK_GR_0325f3a8 on GROUP_REFRESH_WORK (
+    GROUP_UID
+);
+
+create index GROUP_DELEGATE_CHANGE_8bf9e6d8 on GROUP_DELEGATE_CHANGES_WORK (
+    JOB_ID
+);
+
+create index GROUP_DELEGATE_CHANGE_d8f7af69 on GROUP_DELEGATE_CHANGES_WORK (
+    DELEGATOR_UID
+);
+
+create index GROUPS_GROUP_UID_b35cce23 on GROUPS (
+    GROUP_UID
+);
+
+create index GROUP_MEMBERSHIP_MEMB_0ca508e8 on GROUP_MEMBERSHIP (
+    MEMBER_UID
+);
+
+create index GROUP_ATTENDEE_RECONC_da73d3c2 on GROUP_ATTENDEE_RECONCILE_WORK (
+    JOB_ID
+);
+
+create index GROUP_ATTENDEE_RECONC_b894ee7a on GROUP_ATTENDEE_RECONCILE_WORK (
+    RESOURCE_ID
+);
+
+create index GROUP_ATTENDEE_RECONC_5eabc549 on GROUP_ATTENDEE_RECONCILE_WORK (
+    GROUP_ID
+);
+
+create index GROUP_ATTENDEE_RESOUR_855124dc on GROUP_ATTENDEE (
+    RESOURCE_ID
+);
+
+create index GROUP_SHAREE_RECONCIL_9aad0858 on GROUP_SHAREE_RECONCILE_WORK (
+    JOB_ID
+);
+
+create index GROUP_SHAREE_RECONCIL_4dc60f78 on GROUP_SHAREE_RECONCILE_WORK (
+    CALENDAR_ID
+);
+
+create index GROUP_SHAREE_RECONCIL_1d14c921 on GROUP_SHAREE_RECONCILE_WORK (
+    GROUP_ID
+);
+
+create index GROUP_SHAREE_CALENDAR_28a88850 on GROUP_SHAREE (
+    CALENDAR_ID
+);
+
+create index DELEGATE_TO_DELEGATOR_5e149b11 on DELEGATES (
+    DELEGATE,
+    READ_WRITE,
+    DELEGATOR
+);
+
+create index DELEGATE_GROUPS_GROUP_25117446 on DELEGATE_GROUPS (
+    GROUP_ID
+);
+
+create index CALENDAR_OBJECT_SPLIT_af71dcda on CALENDAR_OBJECT_SPLITTER_WORK (
+    RESOURCE_ID
+);
+
+create index CALENDAR_OBJECT_SPLIT_33603b72 on CALENDAR_OBJECT_SPLITTER_WORK (
+    JOB_ID
+);
+
+create index FIND_MIN_VALID_REVISI_78d17400 on FIND_MIN_VALID_REVISION_WORK (
+    JOB_ID
+);
+
+create index REVISION_CLEANUP_WORK_eb062686 on REVISION_CLEANUP_WORK (
+    JOB_ID
+);
+
+create index INBOX_CLEANUP_WORK_JO_799132bd on INBOX_CLEANUP_WORK (
+    JOB_ID
+);
+
+create index CLEANUP_ONE_INBOX_WOR_375dac36 on CLEANUP_ONE_INBOX_WORK (
+    JOB_ID
+);
+
+create index SCHEDULE_WORK_JOB_ID_65e810ee on SCHEDULE_WORK (
+    JOB_ID
+);
+
+create index SCHEDULE_WORK_ICALEND_089f33dc on SCHEDULE_WORK (
+    ICALENDAR_UID
+);
+
+create index SCHEDULE_REFRESH_WORK_26084c7b on SCHEDULE_REFRESH_WORK (
+    HOME_RESOURCE_ID
+);
+
+create index SCHEDULE_REFRESH_WORK_989efe54 on SCHEDULE_REFRESH_WORK (
+    RESOURCE_ID
+);
+
+create index SCHEDULE_REFRESH_ATTE_83053b91 on SCHEDULE_REFRESH_ATTENDEES (
+    RESOURCE_ID,
+    ATTENDEE
+);
+
+create index SCHEDULE_AUTO_REPLY_W_0256478d on SCHEDULE_AUTO_REPLY_WORK (
+    HOME_RESOURCE_ID
+);
+
+create index SCHEDULE_AUTO_REPLY_W_0755e754 on SCHEDULE_AUTO_REPLY_WORK (
+    RESOURCE_ID
+);
+
+create index SCHEDULE_ORGANIZER_WO_18ce4edd on SCHEDULE_ORGANIZER_WORK (
+    HOME_RESOURCE_ID
+);
+
+create index SCHEDULE_ORGANIZER_WO_14702035 on SCHEDULE_ORGANIZER_WORK (
+    RESOURCE_ID
+);
+
+create index SCHEDULE_ORGANIZER_SE_9ec9f827 on SCHEDULE_ORGANIZER_SEND_WORK (
+    HOME_RESOURCE_ID
+);
+
+create index SCHEDULE_ORGANIZER_SE_699fefc4 on SCHEDULE_ORGANIZER_SEND_WORK (
+    RESOURCE_ID
+);
+
+create index SCHEDULE_REPLY_WORK_H_745af8cf on SCHEDULE_REPLY_WORK (
+    HOME_RESOURCE_ID
+);
+
+create index SCHEDULE_REPLY_WORK_R_11bd3fbb on SCHEDULE_REPLY_WORK (
+    RESOURCE_ID
+);
+
+create index SCHEDULE_REPLY_CANCEL_dab513ef on SCHEDULE_REPLY_CANCEL_WORK (
+    HOME_RESOURCE_ID
+);
+
+create index PRINCIPAL_PURGE_POLLI_6383e68a on PRINCIPAL_PURGE_POLLING_WORK (
+    JOB_ID
+);
+
+create index PRINCIPAL_PURGE_CHECK_b0c024c1 on PRINCIPAL_PURGE_CHECK_WORK (
+    JOB_ID
+);
+
+create index PRINCIPAL_PURGE_CHECK_198388a5 on PRINCIPAL_PURGE_CHECK_WORK (
+    UID
+);
+
+create index PRINCIPAL_PURGE_WORK__7a8141a3 on PRINCIPAL_PURGE_WORK (
+    JOB_ID
+);
+
+create index PRINCIPAL_PURGE_WORK__db35cfdc on PRINCIPAL_PURGE_WORK (
+    UID
+);
+
+create index PRINCIPAL_PURGE_HOME__f35eea7a on PRINCIPAL_PURGE_HOME_WORK (
+    JOB_ID
+);
+
+create index PRINCIPAL_PURGE_HOME__967e4480 on PRINCIPAL_PURGE_HOME_WORK (
+    HOME_RESOURCE_ID
+);
+
+-- Extra schema to add to current-oracle-dialect.sql
</ins></span></pre></div>
<a id="CalendarServertrunktxdavcommondatastoresql_schemaoldpostgresdialectv49sql"></a>
<div class="addfile"><h4>Added: CalendarServer/trunk/txdav/common/datastore/sql_schema/old/postgres-dialect/v49.sql (0 => 14247)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/common/datastore/sql_schema/old/postgres-dialect/v49.sql                                (rev 0)
+++ CalendarServer/trunk/txdav/common/datastore/sql_schema/old/postgres-dialect/v49.sql        2015-01-06 16:44:21 UTC (rev 14247)
</span><span class="lines">@@ -0,0 +1,1155 @@
</span><ins>+-- -*- test-case-name: txdav.caldav.datastore.test.test_sql,txdav.carddav.datastore.test.test_sql -*-
+
+----
+-- Copyright (c) 2010-2014 Apple Inc. All rights reserved.
+--
+-- Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an &quot;AS IS&quot; BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+----
+
+
+-----------------
+-- Resource ID --
+-----------------
+
+create sequence RESOURCE_ID_SEQ;
+
+
+-------------------------
+-- Cluster Bookkeeping --
+-------------------------
+
+-- Information about a process connected to this database.
+
+-- Note that this must match the node info schema in twext.enterprise.queue.
+create table NODE_INFO (
+  HOSTNAME  varchar(255) not null,
+  PID       integer      not null,
+  PORT      integer      not null,
+  TIME      timestamp    not null default timezone('UTC', CURRENT_TIMESTAMP),
+
+  primary key (HOSTNAME, PORT)
+);
+
+-- Unique named locks.  This table should always be empty, but rows are
+-- temporarily created in order to prevent undesirable concurrency.
+create table NAMED_LOCK (
+    LOCK_NAME varchar(255) primary key
+);
+
+
+--------------------
+-- Jobs           --
+--------------------
+
+create sequence JOB_SEQ;
+
+create table JOB (
+  JOB_ID      integer primary key default nextval('JOB_SEQ') not null, --implicit index
+  WORK_TYPE   varchar(255) not null,
+  PRIORITY    integer default 0,
+  WEIGHT      integer default 0,
+  NOT_BEFORE  timestamp not null,
+  ASSIGNED    timestamp default null,
+  OVERDUE     timestamp default null,
+  FAILED      integer default 0
+);
+
+-------------------
+-- Calendar Home --
+-------------------
+
+create table CALENDAR_HOME (
+  RESOURCE_ID      integer      primary key default nextval('RESOURCE_ID_SEQ'), -- implicit index
+  OWNER_UID        varchar(255) not null unique,                                -- implicit index
+  STATUS           integer      default 0 not null,                             -- enum HOME_STATUS
+  DATAVERSION      integer      default 0 not null
+);
+
+-- Enumeration of statuses
+
+create table HOME_STATUS (
+  ID          integer     primary key,
+  DESCRIPTION varchar(16) not null unique
+);
+
+insert into HOME_STATUS values (0, 'normal' );
+insert into HOME_STATUS values (1, 'external');
+insert into HOME_STATUS values (2, 'purging');
+
+
+--------------
+-- Calendar --
+--------------
+
+create table CALENDAR (
+  RESOURCE_ID integer   primary key default nextval('RESOURCE_ID_SEQ') -- implicit index
+);
+
+
+----------------------------
+-- Calendar Home Metadata --
+----------------------------
+
+create table CALENDAR_HOME_METADATA (
+  RESOURCE_ID              integer     primary key references CALENDAR_HOME on delete cascade, -- implicit index
+  QUOTA_USED_BYTES         integer     default 0 not null,
+  DEFAULT_EVENTS           integer     default null references CALENDAR on delete set null,
+  DEFAULT_TASKS            integer     default null references CALENDAR on delete set null,
+  DEFAULT_POLLS            integer     default null references CALENDAR on delete set null,
+  ALARM_VEVENT_TIMED       text        default null,
+  ALARM_VEVENT_ALLDAY      text        default null,
+  ALARM_VTODO_TIMED        text        default null,
+  ALARM_VTODO_ALLDAY       text        default null,
+  AVAILABILITY             text        default null,
+  CREATED                  timestamp   default timezone('UTC', CURRENT_TIMESTAMP),
+  MODIFIED                 timestamp   default timezone('UTC', CURRENT_TIMESTAMP)
+);
+
+create index CALENDAR_HOME_METADATA_DEFAULT_EVENTS on
+  CALENDAR_HOME_METADATA(DEFAULT_EVENTS);
+create index CALENDAR_HOME_METADATA_DEFAULT_TASKS on
+  CALENDAR_HOME_METADATA(DEFAULT_TASKS);
+create index CALENDAR_HOME_METADATA_DEFAULT_POLLS on
+  CALENDAR_HOME_METADATA(DEFAULT_POLLS);
+
+
+-----------------------
+-- Calendar Metadata --
+-----------------------
+
+create table CALENDAR_METADATA (
+  RESOURCE_ID           integer      primary key references CALENDAR on delete cascade, -- implicit index
+  SUPPORTED_COMPONENTS  varchar(255) default null,
+  CREATED               timestamp    default timezone('UTC', CURRENT_TIMESTAMP),
+  MODIFIED              timestamp    default timezone('UTC', CURRENT_TIMESTAMP)
+);
+
+
+---------------------------
+-- Sharing Notifications --
+---------------------------
+
+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
+  STATUS      integer      default 0 not null,                             -- enum HOME_STATUS
+  DATAVERSION integer      default 0 not null
+);
+
+create table NOTIFICATION (
+  RESOURCE_ID                   integer      primary key default nextval('RESOURCE_ID_SEQ'), -- implicit index
+  NOTIFICATION_HOME_RESOURCE_ID integer      not null references NOTIFICATION_HOME,
+  NOTIFICATION_UID              varchar(255) not null,
+  NOTIFICATION_TYPE             varchar(255) not null,
+  NOTIFICATION_DATA             text         not null,
+  MD5                           char(32)     not null,
+  CREATED                       timestamp    default timezone('UTC', CURRENT_TIMESTAMP),
+  MODIFIED                      timestamp    default timezone('UTC', CURRENT_TIMESTAMP),
+
+  unique (NOTIFICATION_UID, NOTIFICATION_HOME_RESOURCE_ID) -- implicit index
+);
+
+create index NOTIFICATION_NOTIFICATION_HOME_RESOURCE_ID on
+  NOTIFICATION(NOTIFICATION_HOME_RESOURCE_ID);
+
+
+-------------------
+-- Calendar Bind --
+-------------------
+
+-- Joins CALENDAR_HOME and CALENDAR
+
+create table CALENDAR_BIND (
+  CALENDAR_HOME_RESOURCE_ID integer      not null references CALENDAR_HOME,
+  CALENDAR_RESOURCE_ID      integer      not null references CALENDAR on delete cascade,
+  EXTERNAL_ID               integer      default null,
+  CALENDAR_RESOURCE_NAME    varchar(255) not null,
+  BIND_MODE                 integer      not null, -- enum CALENDAR_BIND_MODE
+  BIND_STATUS               integer      not null, -- enum CALENDAR_BIND_STATUS
+  BIND_REVISION             integer      default 0 not null,
+  MESSAGE                   text,
+  TRANSP                    integer      default 0 not null, -- enum CALENDAR_TRANSP
+  ALARM_VEVENT_TIMED        text         default null,
+  ALARM_VEVENT_ALLDAY       text         default null,
+  ALARM_VTODO_TIMED         text         default null,
+  ALARM_VTODO_ALLDAY        text         default null,
+  TIMEZONE                  text         default null,
+
+  primary key (CALENDAR_HOME_RESOURCE_ID, CALENDAR_RESOURCE_ID), -- implicit index
+  unique (CALENDAR_HOME_RESOURCE_ID, CALENDAR_RESOURCE_NAME)     -- implicit index
+);
+
+create index CALENDAR_BIND_RESOURCE_ID on
+  CALENDAR_BIND(CALENDAR_RESOURCE_ID);
+
+-- Enumeration of calendar bind modes
+
+create table CALENDAR_BIND_MODE (
+  ID          integer     primary key,
+  DESCRIPTION varchar(16) not null unique
+);
+
+insert into CALENDAR_BIND_MODE values (0, 'own'  );
+insert into CALENDAR_BIND_MODE values (1, 'read' );
+insert into CALENDAR_BIND_MODE values (2, 'write');
+insert into CALENDAR_BIND_MODE values (3, 'direct');
+insert into CALENDAR_BIND_MODE values (4, 'indirect');
+insert into CALENDAR_BIND_MODE values (5, 'group');
+insert into CALENDAR_BIND_MODE values (6, 'group_read');
+insert into CALENDAR_BIND_MODE values (7, 'group_write');
+
+-- Enumeration of statuses
+
+create table CALENDAR_BIND_STATUS (
+  ID          integer     primary key,
+  DESCRIPTION varchar(16) not null unique
+);
+
+insert into CALENDAR_BIND_STATUS values (0, 'invited' );
+insert into CALENDAR_BIND_STATUS values (1, 'accepted');
+insert into CALENDAR_BIND_STATUS values (2, 'declined');
+insert into CALENDAR_BIND_STATUS values (3, 'invalid');
+insert into CALENDAR_BIND_STATUS values (4, 'deleted');
+
+
+-- Enumeration of transparency
+
+create table CALENDAR_TRANSP (
+  ID          integer     primary key,
+  DESCRIPTION varchar(16) not null unique
+);
+
+insert into CALENDAR_TRANSP values (0, 'opaque' );
+insert into CALENDAR_TRANSP values (1, 'transparent');
+
+
+---------------------
+-- Calendar Object --
+---------------------
+
+create table CALENDAR_OBJECT (
+  RESOURCE_ID          integer      primary key default nextval('RESOURCE_ID_SEQ'), -- implicit index
+  CALENDAR_RESOURCE_ID integer      not null references CALENDAR on delete cascade,
+  RESOURCE_NAME        varchar(255) not null,
+  ICALENDAR_TEXT       text         not null,
+  ICALENDAR_UID        varchar(255) not null,
+  ICALENDAR_TYPE       varchar(255) not null,
+  ATTACHMENTS_MODE     integer      default 0 not null, -- enum CALENDAR_OBJ_ATTACHMENTS_MODE
+  DROPBOX_ID           varchar(255),
+  ORGANIZER            varchar(255),
+  RECURRANCE_MIN       date,        -- minimum date that recurrences have been expanded to.
+  RECURRANCE_MAX       date,        -- maximum date that recurrences have been expanded to.
+  ACCESS               integer      default 0 not null,
+  SCHEDULE_OBJECT      boolean      default false,
+  SCHEDULE_TAG         varchar(36)  default null,
+  SCHEDULE_ETAGS       text         default null,
+  PRIVATE_COMMENTS     boolean      default false not null,
+  MD5                  char(32)     not null,
+  CREATED              timestamp    default timezone('UTC', CURRENT_TIMESTAMP),
+  MODIFIED             timestamp    default timezone('UTC', CURRENT_TIMESTAMP),
+  DATAVERSION          integer      default 0 not null,
+
+  unique (CALENDAR_RESOURCE_ID, RESOURCE_NAME) -- implicit index
+
+  -- since the 'inbox' is a 'calendar resource' for the purpose of storing
+  -- calendar objects, this constraint has to be selectively enforced by the
+  -- application layer.
+
+  -- unique (CALENDAR_RESOURCE_ID, ICALENDAR_UID)
+);
+
+create index CALENDAR_OBJECT_CALENDAR_RESOURCE_ID_AND_ICALENDAR_UID on
+  CALENDAR_OBJECT(CALENDAR_RESOURCE_ID, ICALENDAR_UID);
+
+create index CALENDAR_OBJECT_CALENDAR_RESOURCE_ID_RECURRANCE_MAX_MIN on
+  CALENDAR_OBJECT(CALENDAR_RESOURCE_ID, RECURRANCE_MAX, RECURRANCE_MIN);
+
+create index CALENDAR_OBJECT_ICALENDAR_UID on
+  CALENDAR_OBJECT(ICALENDAR_UID);
+
+create index CALENDAR_OBJECT_DROPBOX_ID on
+  CALENDAR_OBJECT(DROPBOX_ID);
+
+-- Enumeration of attachment modes
+
+create table CALENDAR_OBJ_ATTACHMENTS_MODE (
+  ID          integer     primary key,
+  DESCRIPTION varchar(16) not null unique
+);
+
+insert into CALENDAR_OBJ_ATTACHMENTS_MODE values (0, 'none' );
+insert into CALENDAR_OBJ_ATTACHMENTS_MODE values (1, 'read' );
+insert into CALENDAR_OBJ_ATTACHMENTS_MODE values (2, 'write');
+
+
+-- Enumeration of calendar access types
+
+create table CALENDAR_ACCESS_TYPE (
+  ID          integer     primary key,
+  DESCRIPTION varchar(32) not null unique
+);
+
+insert into CALENDAR_ACCESS_TYPE values (0, ''             );
+insert into CALENDAR_ACCESS_TYPE values (1, 'public'       );
+insert into CALENDAR_ACCESS_TYPE values (2, 'private'      );
+insert into CALENDAR_ACCESS_TYPE values (3, 'confidential' );
+insert into CALENDAR_ACCESS_TYPE values (4, 'restricted'   );
+
+
+-----------------
+-- Instance ID --
+-----------------
+
+create sequence INSTANCE_ID_SEQ;
+
+
+----------------
+-- Time Range --
+----------------
+
+create table TIME_RANGE (
+  INSTANCE_ID                 integer        primary key default nextval('INSTANCE_ID_SEQ'), -- implicit index
+  CALENDAR_RESOURCE_ID        integer        not null references CALENDAR on delete cascade,
+  CALENDAR_OBJECT_RESOURCE_ID integer        not null references CALENDAR_OBJECT on delete cascade,
+  FLOATING                    boolean        not null,
+  START_DATE                  timestamp      not null,
+  END_DATE                    timestamp      not null,
+  FBTYPE                      integer        not null,
+  TRANSPARENT                 boolean        not null
+);
+
+create index TIME_RANGE_CALENDAR_RESOURCE_ID on
+  TIME_RANGE(CALENDAR_RESOURCE_ID);
+create index TIME_RANGE_CALENDAR_OBJECT_RESOURCE_ID on
+  TIME_RANGE(CALENDAR_OBJECT_RESOURCE_ID);
+
+
+-- Enumeration of free/busy types
+
+create table FREE_BUSY_TYPE (
+  ID          integer     primary key,
+  DESCRIPTION varchar(16) not null unique
+);
+
+insert into FREE_BUSY_TYPE values (0, 'unknown'         );
+insert into FREE_BUSY_TYPE values (1, 'free'            );
+insert into FREE_BUSY_TYPE values (2, 'busy'            );
+insert into FREE_BUSY_TYPE values (3, 'busy-unavailable');
+insert into FREE_BUSY_TYPE values (4, 'busy-tentative'  );
+
+
+-------------------
+-- Per-user data --
+-------------------
+
+create table PERUSER (
+  TIME_RANGE_INSTANCE_ID      integer      not null references TIME_RANGE on delete cascade,
+  USER_ID                     varchar(255) not null,
+  TRANSPARENT                 boolean      not null,
+  ADJUSTED_START_DATE         timestamp    default null,
+  ADJUSTED_END_DATE           timestamp    default null,
+  
+  primary key (TIME_RANGE_INSTANCE_ID, USER_ID)    -- implicit index
+);
+
+
+----------------
+-- Attachment --
+----------------
+
+create sequence ATTACHMENT_ID_SEQ;
+
+create table ATTACHMENT (
+  ATTACHMENT_ID               integer           primary key default nextval('ATTACHMENT_ID_SEQ'), -- implicit index
+  CALENDAR_HOME_RESOURCE_ID   integer           not null references CALENDAR_HOME,
+  DROPBOX_ID                  varchar(255),
+  CONTENT_TYPE                varchar(255)      not null,
+  SIZE                        integer           not null,
+  MD5                         char(32)          not null,
+  CREATED                     timestamp default timezone('UTC', CURRENT_TIMESTAMP),
+  MODIFIED                    timestamp default timezone('UTC', CURRENT_TIMESTAMP),
+  PATH                        varchar(1024)     not null
+);
+
+create index ATTACHMENT_CALENDAR_HOME_RESOURCE_ID on
+  ATTACHMENT(CALENDAR_HOME_RESOURCE_ID);
+
+create index ATTACHMENT_DROPBOX_ID on
+  ATTACHMENT(DROPBOX_ID);
+
+-- Many-to-many relationship between attachments and calendar objects
+create table ATTACHMENT_CALENDAR_OBJECT (
+  ATTACHMENT_ID                  integer      not null references ATTACHMENT on delete cascade,
+  MANAGED_ID                     varchar(255) not null,
+  CALENDAR_OBJECT_RESOURCE_ID    integer      not null references CALENDAR_OBJECT on delete cascade,
+
+  primary key (ATTACHMENT_ID, CALENDAR_OBJECT_RESOURCE_ID), -- implicit index
+  unique (MANAGED_ID, CALENDAR_OBJECT_RESOURCE_ID) --implicit index
+);
+
+create index ATTACHMENT_CALENDAR_OBJECT_CALENDAR_OBJECT_RESOURCE_ID on
+  ATTACHMENT_CALENDAR_OBJECT(CALENDAR_OBJECT_RESOURCE_ID);
+
+-----------------------
+-- Resource Property --
+-----------------------
+
+create table RESOURCE_PROPERTY (
+  RESOURCE_ID integer      not null, -- foreign key: *.RESOURCE_ID
+  NAME        varchar(255) not null,
+  VALUE       text         not null, -- FIXME: xml?
+  VIEWER_UID  varchar(255),
+
+  primary key (RESOURCE_ID, NAME, VIEWER_UID) -- implicit index
+);
+
+
+----------------------
+-- AddressBook Home --
+----------------------
+
+create table ADDRESSBOOK_HOME (
+  RESOURCE_ID                   integer         primary key default nextval('RESOURCE_ID_SEQ'), -- implicit index
+  ADDRESSBOOK_PROPERTY_STORE_ID integer         default nextval('RESOURCE_ID_SEQ') not null,    -- implicit index
+  OWNER_UID                     varchar(255)    not null unique,                                -- implicit index
+  STATUS                        integer         default 0 not null,                             -- enum HOME_STATUS
+  DATAVERSION                   integer         default 0 not null
+);
+
+
+-------------------------------
+-- AddressBook Home Metadata --
+-------------------------------
+
+create table ADDRESSBOOK_HOME_METADATA (
+  RESOURCE_ID      integer      primary key references ADDRESSBOOK_HOME on delete cascade, -- implicit index
+  QUOTA_USED_BYTES integer      default 0 not null,
+  CREATED          timestamp    default timezone('UTC', CURRENT_TIMESTAMP),
+  MODIFIED         timestamp    default timezone('UTC', CURRENT_TIMESTAMP)
+);
+
+
+-----------------------------
+-- Shared AddressBook Bind --
+-----------------------------
+
+-- Joins sharee ADDRESSBOOK_HOME and owner ADDRESSBOOK_HOME
+
+create table SHARED_ADDRESSBOOK_BIND (
+  ADDRESSBOOK_HOME_RESOURCE_ID          integer         not null references ADDRESSBOOK_HOME,
+  OWNER_HOME_RESOURCE_ID                integer         not null references ADDRESSBOOK_HOME on delete cascade,
+  EXTERNAL_ID                           integer         default null,
+  ADDRESSBOOK_RESOURCE_NAME             varchar(255)    not null,
+  BIND_MODE                             integer         not null, -- enum CALENDAR_BIND_MODE
+  BIND_STATUS                           integer         not null, -- enum CALENDAR_BIND_STATUS
+  BIND_REVISION                         integer         default 0 not null,
+  MESSAGE                               text,                     -- FIXME: xml?
+
+  primary key (ADDRESSBOOK_HOME_RESOURCE_ID, OWNER_HOME_RESOURCE_ID), -- implicit index
+  unique (ADDRESSBOOK_HOME_RESOURCE_ID, ADDRESSBOOK_RESOURCE_NAME)     -- implicit index
+);
+
+create index SHARED_ADDRESSBOOK_BIND_RESOURCE_ID on
+  SHARED_ADDRESSBOOK_BIND(OWNER_HOME_RESOURCE_ID);
+
+
+------------------------
+-- AddressBook Object --
+------------------------
+
+create table ADDRESSBOOK_OBJECT (
+  RESOURCE_ID                   integer         primary key default nextval('RESOURCE_ID_SEQ'),    -- implicit index
+  ADDRESSBOOK_HOME_RESOURCE_ID  integer         not null references ADDRESSBOOK_HOME on delete cascade,
+  RESOURCE_NAME                 varchar(255)    not null,
+  VCARD_TEXT                    text            not null,
+  VCARD_UID                     varchar(255)    not null,
+  KIND                          integer         not null,  -- enum ADDRESSBOOK_OBJECT_KIND
+  MD5                           char(32)        not null,
+  CREATED                       timestamp       default timezone('UTC', CURRENT_TIMESTAMP),
+  MODIFIED                      timestamp       default timezone('UTC', CURRENT_TIMESTAMP),
+  DATAVERSION                   integer         default 0 not null,
+
+  unique (ADDRESSBOOK_HOME_RESOURCE_ID, RESOURCE_NAME), -- implicit index
+  unique (ADDRESSBOOK_HOME_RESOURCE_ID, VCARD_UID)      -- implicit index
+);
+
+
+-----------------------------
+-- AddressBook Object kind --
+-----------------------------
+
+create table ADDRESSBOOK_OBJECT_KIND (
+  ID          integer     primary key,
+  DESCRIPTION varchar(16) not null unique
+);
+
+insert into ADDRESSBOOK_OBJECT_KIND values (0, 'person');
+insert into ADDRESSBOOK_OBJECT_KIND values (1, 'group' );
+insert into ADDRESSBOOK_OBJECT_KIND values (2, 'resource');
+insert into ADDRESSBOOK_OBJECT_KIND values (3, 'location');
+
+
+----------------------------------
+-- Revisions, forward reference --
+----------------------------------
+
+create sequence REVISION_SEQ;
+
+---------------------------------
+-- Address Book Object Members --
+---------------------------------
+
+create table ABO_MEMBERS (
+  GROUP_ID        integer     not null, -- references ADDRESSBOOK_OBJECT on delete cascade,   -- AddressBook Object's (kind=='group') RESOURCE_ID
+  ADDRESSBOOK_ID  integer     not null references ADDRESSBOOK_HOME on delete cascade,
+  MEMBER_ID       integer     not null, -- references ADDRESSBOOK_OBJECT,                     -- member AddressBook Object's RESOURCE_ID
+  REVISION        integer     default nextval('REVISION_SEQ') not null,
+  REMOVED         boolean     default false not null,
+  MODIFIED        timestamp   default timezone('UTC', CURRENT_TIMESTAMP),
+
+  primary key (GROUP_ID, MEMBER_ID, REVISION) -- implicit index
+);
+
+create index ABO_MEMBERS_ADDRESSBOOK_ID on
+  ABO_MEMBERS(ADDRESSBOOK_ID);
+create index ABO_MEMBERS_MEMBER_ID on
+  ABO_MEMBERS(MEMBER_ID);
+
+------------------------------------------
+-- Address Book Object Foreign Members  --
+------------------------------------------
+
+create table ABO_FOREIGN_MEMBERS (
+  GROUP_ID           integer      not null references ADDRESSBOOK_OBJECT on delete cascade,  -- AddressBook Object's (kind=='group') RESOURCE_ID
+  ADDRESSBOOK_ID     integer      not null references ADDRESSBOOK_HOME on delete cascade,
+  MEMBER_ADDRESS     varchar(255) not null,                                                  -- member AddressBook Object's 'calendar' address
+
+  primary key (GROUP_ID, MEMBER_ADDRESS) -- implicit index
+);
+
+create index ABO_FOREIGN_MEMBERS_ADDRESSBOOK_ID on
+  ABO_FOREIGN_MEMBERS(ADDRESSBOOK_ID);
+
+-----------------------
+-- Shared Group Bind --
+-----------------------
+
+-- Joins ADDRESSBOOK_HOME and ADDRESSBOOK_OBJECT (kind == group)
+
+create table SHARED_GROUP_BIND (
+  ADDRESSBOOK_HOME_RESOURCE_ID      integer      not null references ADDRESSBOOK_HOME,
+  GROUP_RESOURCE_ID                 integer      not null references ADDRESSBOOK_OBJECT on delete cascade,
+  EXTERNAL_ID                       integer      default null,
+  GROUP_ADDRESSBOOK_NAME            varchar(255) not null,
+  BIND_MODE                         integer      not null, -- enum CALENDAR_BIND_MODE
+  BIND_STATUS                       integer      not null, -- enum CALENDAR_BIND_STATUS
+  BIND_REVISION                     integer      default 0 not null,
+  MESSAGE                           text,                  -- FIXME: xml?
+
+  primary key (ADDRESSBOOK_HOME_RESOURCE_ID, GROUP_RESOURCE_ID), -- implicit index
+  unique (ADDRESSBOOK_HOME_RESOURCE_ID, GROUP_ADDRESSBOOK_NAME)  -- implicit index
+);
+
+create index SHARED_GROUP_BIND_RESOURCE_ID on
+  SHARED_GROUP_BIND(GROUP_RESOURCE_ID);
+
+
+---------------
+-- Revisions --
+---------------
+
+-- create sequence REVISION_SEQ;
+
+
+-------------------------------
+-- Calendar Object Revisions --
+-------------------------------
+
+create table CALENDAR_OBJECT_REVISIONS (
+  CALENDAR_HOME_RESOURCE_ID integer      not null references CALENDAR_HOME,
+  CALENDAR_RESOURCE_ID      integer      references CALENDAR,
+  CALENDAR_NAME             varchar(255) default null,
+  RESOURCE_NAME             varchar(255),
+  REVISION                  integer      default nextval('REVISION_SEQ') not null,
+  DELETED                   boolean      not null,
+  MODIFIED                  timestamp    default timezone('UTC', CURRENT_TIMESTAMP),
+  
+  unique(CALENDAR_HOME_RESOURCE_ID, CALENDAR_RESOURCE_ID, CALENDAR_NAME, RESOURCE_NAME)    -- implicit index
+);
+
+create index CALENDAR_OBJECT_REVISIONS_RESOURCE_ID_RESOURCE_NAME_DELETED_REVISION
+  on CALENDAR_OBJECT_REVISIONS(CALENDAR_RESOURCE_ID, RESOURCE_NAME, DELETED, REVISION);
+
+create index CALENDAR_OBJECT_REVISIONS_RESOURCE_ID_REVISION
+  on CALENDAR_OBJECT_REVISIONS(CALENDAR_RESOURCE_ID, REVISION);
+
+create index CALENDAR_OBJECT_REVISIONS_HOME_RESOURCE_ID_REVISION
+  on CALENDAR_OBJECT_REVISIONS(CALENDAR_HOME_RESOURCE_ID, REVISION);
+
+
+----------------------------------
+-- AddressBook Object Revisions --
+----------------------------------
+
+create table ADDRESSBOOK_OBJECT_REVISIONS (
+  ADDRESSBOOK_HOME_RESOURCE_ID  integer      not null references ADDRESSBOOK_HOME,
+  OWNER_HOME_RESOURCE_ID        integer      references ADDRESSBOOK_HOME,
+  ADDRESSBOOK_NAME              varchar(255) default null,
+  OBJECT_RESOURCE_ID            integer      default 0,
+  RESOURCE_NAME                 varchar(255),
+  REVISION                      integer      default nextval('REVISION_SEQ') not null,
+  DELETED                       boolean      not null,
+  MODIFIED                      timestamp    default timezone('UTC', CURRENT_TIMESTAMP),
+  
+  unique(ADDRESSBOOK_HOME_RESOURCE_ID, OWNER_HOME_RESOURCE_ID, ADDRESSBOOK_NAME, RESOURCE_NAME)    -- implicit index
+);
+
+create index ADDRESSBOOK_OBJECT_REVISIONS_OWNER_HOME_RESOURCE_ID_RESOURCE_NAME_DELETED_REVISION
+  on ADDRESSBOOK_OBJECT_REVISIONS(OWNER_HOME_RESOURCE_ID, RESOURCE_NAME, DELETED, REVISION);
+
+create index ADDRESSBOOK_OBJECT_REVISIONS_OWNER_HOME_RESOURCE_ID_REVISION
+  on ADDRESSBOOK_OBJECT_REVISIONS(OWNER_HOME_RESOURCE_ID, REVISION);
+
+
+-----------------------------------
+-- Notification Object Revisions --
+-----------------------------------
+
+create table NOTIFICATION_OBJECT_REVISIONS (
+  NOTIFICATION_HOME_RESOURCE_ID integer      not null references NOTIFICATION_HOME on delete cascade,
+  RESOURCE_NAME                 varchar(255),
+  REVISION                      integer      default nextval('REVISION_SEQ') not null,
+  DELETED                       boolean      not null,
+  MODIFIED                      timestamp    default timezone('UTC', CURRENT_TIMESTAMP),
+
+  unique (NOTIFICATION_HOME_RESOURCE_ID, RESOURCE_NAME) -- implicit index
+);
+
+create index NOTIFICATION_OBJECT_REVISIONS_RESOURCE_ID_REVISION
+  on NOTIFICATION_OBJECT_REVISIONS(NOTIFICATION_HOME_RESOURCE_ID, REVISION);
+
+
+-------------------------------------------
+-- Apple Push Notification Subscriptions --
+-------------------------------------------
+
+create table APN_SUBSCRIPTIONS (
+  TOKEN                         varchar(255) not null,
+  RESOURCE_KEY                  varchar(255) not null,
+  MODIFIED                      integer      not null,
+  SUBSCRIBER_GUID               varchar(255) not null,
+  USER_AGENT                    varchar(255) default null,
+  IP_ADDR                       varchar(255) default null,
+
+  primary key (TOKEN, RESOURCE_KEY) -- implicit index
+);
+
+create index APN_SUBSCRIPTIONS_RESOURCE_KEY
+  on APN_SUBSCRIPTIONS(RESOURCE_KEY);
+
+
+-----------------
+-- IMIP Tokens --
+-----------------
+
+create table IMIP_TOKENS (
+  TOKEN                         varchar(255) not null,
+  ORGANIZER                     varchar(255) not null,
+  ATTENDEE                      varchar(255) not null,
+  ICALUID                       varchar(255) not null,
+  ACCESSED                      timestamp    default timezone('UTC', CURRENT_TIMESTAMP),
+
+  primary key (ORGANIZER, ATTENDEE, ICALUID) -- implicit index
+);
+
+create index IMIP_TOKENS_TOKEN
+  on IMIP_TOKENS(TOKEN);
+
+
+----------------
+-- Work Items --
+----------------
+
+create sequence WORKITEM_SEQ;
+
+
+---------------------------
+-- IMIP Inivitation Work --
+---------------------------
+
+create table IMIP_INVITATION_WORK (
+  WORK_ID                       integer      primary key default nextval('WORKITEM_SEQ') not null, -- implicit index
+  JOB_ID                        integer      references JOB not null,
+  FROM_ADDR                     varchar(255) not null,
+  TO_ADDR                       varchar(255) not null,
+  ICALENDAR_TEXT                text         not null
+);
+
+create index IMIP_INVITATION_WORK_JOB_ID on
+  IMIP_INVITATION_WORK(JOB_ID);
+
+-----------------------
+-- IMIP Polling Work --
+-----------------------
+
+create table IMIP_POLLING_WORK (
+  WORK_ID                       integer      primary key default nextval('WORKITEM_SEQ') not null, -- implicit index
+  JOB_ID                        integer      references JOB not null
+);
+
+create index IMIP_POLLING_WORK_JOB_ID on
+  IMIP_POLLING_WORK(JOB_ID);
+
+
+---------------------
+-- IMIP Reply Work --
+---------------------
+
+create table IMIP_REPLY_WORK (
+  WORK_ID                       integer      primary key default nextval('WORKITEM_SEQ') not null, -- implicit index
+  JOB_ID                        integer      references JOB not null,
+  ORGANIZER                     varchar(255) not null,
+  ATTENDEE                      varchar(255) not null,
+  ICALENDAR_TEXT                text         not null
+);
+
+create index IMIP_REPLY_WORK_JOB_ID on
+  IMIP_REPLY_WORK(JOB_ID);
+
+
+------------------------
+-- Push Notifications --
+------------------------
+
+create table PUSH_NOTIFICATION_WORK (
+  WORK_ID                       integer      primary key default nextval('WORKITEM_SEQ') not null, -- implicit index
+  JOB_ID                        integer      references JOB not null,
+  PUSH_ID                       varchar(255) not null,
+  PUSH_PRIORITY                 integer      not null -- 1:low 5:medium 10:high
+);
+
+create index PUSH_NOTIFICATION_WORK_JOB_ID on
+  PUSH_NOTIFICATION_WORK(JOB_ID);
+create index PUSH_NOTIFICATION_WORK_PUSH_ID on
+  PUSH_NOTIFICATION_WORK(PUSH_ID);
+
+-----------------
+-- GroupCacher --
+-----------------
+
+create table GROUP_CACHER_POLLING_WORK (
+  WORK_ID                       integer      primary key default nextval('WORKITEM_SEQ') not null, -- implicit index
+  JOB_ID                        integer      references JOB not null
+);
+
+create index GROUP_CACHER_POLLING_WORK_JOB_ID on
+  GROUP_CACHER_POLLING_WORK(JOB_ID);
+
+create table GROUP_REFRESH_WORK (
+  WORK_ID                       integer      primary key default nextval('WORKITEM_SEQ') not null, -- implicit index
+  JOB_ID                        integer      references JOB not null,
+  GROUP_UID                     varchar(255) not null
+);
+
+create index GROUP_REFRESH_WORK_JOB_ID on
+  GROUP_REFRESH_WORK(JOB_ID);
+create index GROUP_REFRESH_WORK_GROUP_UID on
+  GROUP_REFRESH_WORK(GROUP_UID);
+
+create table GROUP_DELEGATE_CHANGES_WORK (
+  WORK_ID                       integer      primary key default nextval('WORKITEM_SEQ') not null, -- implicit index
+  JOB_ID                        integer      references JOB not null,
+  DELEGATOR_UID                 varchar(255) not null,
+  READ_DELEGATE_UID             varchar(255) not null,
+  WRITE_DELEGATE_UID            varchar(255) not null
+);
+
+create index GROUP_DELEGATE_CHANGES_WORK_JOB_ID on
+  GROUP_DELEGATE_CHANGES_WORK(JOB_ID);
+create index GROUP_DELEGATE_CHANGES_WORK_DELEGATOR_UID on
+  GROUP_DELEGATE_CHANGES_WORK(DELEGATOR_UID);
+
+create table GROUPS (
+  GROUP_ID                      integer      primary key default nextval('RESOURCE_ID_SEQ'),    -- implicit index
+  NAME                          varchar(255) not null,
+  GROUP_UID                     varchar(255) not null unique,
+  MEMBERSHIP_HASH               varchar(255) not null,
+  EXTANT                        integer default 1,
+  CREATED                       timestamp default timezone('UTC', CURRENT_TIMESTAMP),
+  MODIFIED                      timestamp default timezone('UTC', CURRENT_TIMESTAMP)
+);
+create index GROUPS_GROUP_UID on
+  GROUPS(GROUP_UID);
+
+create table GROUP_MEMBERSHIP (
+  GROUP_ID                     integer not null references GROUPS on delete cascade,
+  MEMBER_UID                   varchar(255) not null,
+
+  primary key (GROUP_ID, MEMBER_UID)
+);
+
+create index GROUP_MEMBERSHIP_MEMBER on
+  GROUP_MEMBERSHIP(MEMBER_UID);
+
+create table GROUP_ATTENDEE_RECONCILE_WORK (
+  WORK_ID                       integer primary key default nextval('WORKITEM_SEQ') not null, -- implicit index
+  JOB_ID                        integer not null references JOB,
+  RESOURCE_ID                   integer not null references CALENDAR_OBJECT on delete cascade,
+  GROUP_ID                      integer not null references GROUPS on delete cascade
+);
+
+create index GROUP_ATTENDEE_RECONCILE_WORK_JOB_ID on
+  GROUP_ATTENDEE_RECONCILE_WORK(JOB_ID);
+create index GROUP_ATTENDEE_RECONCILE_WORK_RESOURCE_ID on
+  GROUP_ATTENDEE_RECONCILE_WORK(RESOURCE_ID);
+create index GROUP_ATTENDEE_RECONCILE_WORK_GROUP_ID on
+  GROUP_ATTENDEE_RECONCILE_WORK(GROUP_ID);
+
+
+create table GROUP_ATTENDEE (
+  GROUP_ID                      integer not null references GROUPS on delete cascade,
+  RESOURCE_ID                   integer not null references CALENDAR_OBJECT on delete cascade,
+  MEMBERSHIP_HASH               varchar(255) not null,
+
+  primary key (GROUP_ID, RESOURCE_ID)
+);
+
+create index GROUP_ATTENDEE_RESOURCE_ID on
+  GROUP_ATTENDEE(RESOURCE_ID);
+
+
+create table GROUP_SHAREE_RECONCILE_WORK (
+  WORK_ID                       integer primary key default nextval('WORKITEM_SEQ') not null, -- implicit index
+  JOB_ID                        integer not null references JOB,
+  CALENDAR_ID                   integer        not null references CALENDAR on delete cascade,
+  GROUP_ID                      integer not null references GROUPS on delete cascade
+);
+
+create index GROUP_SHAREE_RECONCILE_WORK_JOB_ID on
+  GROUP_SHAREE_RECONCILE_WORK(JOB_ID);
+create index GROUP_SHAREE_RECONCILE_WORK_CALENDAR_ID on
+  GROUP_SHAREE_RECONCILE_WORK(CALENDAR_ID);
+create index GROUP_SHAREE_RECONCILE_WORK_GROUP_ID on
+  GROUP_SHAREE_RECONCILE_WORK(GROUP_ID);
+
+
+create table GROUP_SHAREE (
+  GROUP_ID                      integer not null references GROUPS on delete cascade,
+  CALENDAR_ID                                      integer not null references CALENDAR on delete cascade,
+  GROUP_BIND_MODE               integer not null, -- enum CALENDAR_BIND_MODE
+  MEMBERSHIP_HASH               varchar(255) not null,
+
+  primary key (GROUP_ID, CALENDAR_ID)
+);
+
+create index GROUP_SHAREE_CALENDAR_ID on
+  GROUP_SHAREE(CALENDAR_ID);
+
+---------------
+-- Delegates --
+---------------
+
+create table DELEGATES (
+  DELEGATOR                     varchar(255) not null,
+  DELEGATE                      varchar(255) not null,
+  READ_WRITE                    integer      not null, -- 1 = ReadWrite, 0 = ReadOnly
+
+  primary key (DELEGATOR, READ_WRITE, DELEGATE)
+);
+create index DELEGATE_TO_DELEGATOR on
+  DELEGATES(DELEGATE, READ_WRITE, DELEGATOR);
+
+create table DELEGATE_GROUPS (
+  DELEGATOR                     varchar(255) not null,
+  GROUP_ID                      integer      not null references GROUPS on delete cascade,
+  READ_WRITE                    integer      not null, -- 1 = ReadWrite, 0 = ReadOnly
+  IS_EXTERNAL                   integer      not null, -- 1 = ReadWrite, 0 = ReadOnly
+
+  primary key (DELEGATOR, READ_WRITE, GROUP_ID)
+);
+create index DELEGATE_GROUPS_GROUP_ID on
+  DELEGATE_GROUPS(GROUP_ID);
+
+create table EXTERNAL_DELEGATE_GROUPS (
+  DELEGATOR                     varchar(255) primary key not null,
+  GROUP_UID_READ                varchar(255),
+  GROUP_UID_WRITE               varchar(255)
+);
+
+--------------------------
+-- Object Splitter Work --
+--------------------------
+
+create table CALENDAR_OBJECT_SPLITTER_WORK (
+  WORK_ID                       integer      primary key default nextval('WORKITEM_SEQ') not null, -- implicit index
+  JOB_ID                        integer      references JOB not null,
+  RESOURCE_ID                   integer      not null references CALENDAR_OBJECT on delete cascade
+);
+
+create index CALENDAR_OBJECT_SPLITTER_WORK_RESOURCE_ID on
+  CALENDAR_OBJECT_SPLITTER_WORK(RESOURCE_ID);
+create index CALENDAR_OBJECT_SPLITTER_WORK_JOB_ID on
+  CALENDAR_OBJECT_SPLITTER_WORK(JOB_ID);
+
+---------------------------
+-- Revision Cleanup Work --
+---------------------------
+
+create table FIND_MIN_VALID_REVISION_WORK (
+  WORK_ID                       integer      primary key default nextval('WORKITEM_SEQ') not null, -- implicit index
+  JOB_ID                        integer      references JOB not null
+);
+
+create index FIND_MIN_VALID_REVISION_WORK_JOB_ID on
+  FIND_MIN_VALID_REVISION_WORK(JOB_ID);
+
+create table REVISION_CLEANUP_WORK (
+  WORK_ID                       integer      primary key default nextval('WORKITEM_SEQ') not null, -- implicit index
+  JOB_ID                        integer      references JOB not null
+);
+
+create index REVISION_CLEANUP_WORK_JOB_ID on
+  REVISION_CLEANUP_WORK(JOB_ID);
+
+------------------------
+-- Inbox Cleanup Work --
+------------------------
+
+create table INBOX_CLEANUP_WORK (
+  WORK_ID                       integer      primary key default nextval('WORKITEM_SEQ') not null, -- implicit index
+  JOB_ID                        integer      references JOB not null
+);
+
+create index INBOX_CLEANUP_WORK_JOB_ID on
+   INBOX_CLEANUP_WORK(JOB_ID);
+
+create table CLEANUP_ONE_INBOX_WORK (
+  WORK_ID                       integer      primary key default nextval('WORKITEM_SEQ') not null, -- implicit index
+  JOB_ID                        integer      references JOB not null,
+  HOME_ID                       integer      not null unique references CALENDAR_HOME on delete cascade -- implicit index
+);
+
+create index CLEANUP_ONE_INBOX_WORK_JOB_ID on
+  CLEANUP_ONE_INBOX_WORK(JOB_ID);
+
+-------------------
+-- Schedule Work --
+-------------------
+
+create table SCHEDULE_WORK (
+  WORK_ID                       integer      primary key default nextval('WORKITEM_SEQ') not null, -- implicit index
+  JOB_ID                        integer      references JOB not null,
+  ICALENDAR_UID                 varchar(255) not null,
+  WORK_TYPE                     varchar(255) not null
+);
+
+create index SCHEDULE_WORK_JOB_ID on
+  SCHEDULE_WORK(JOB_ID);
+create index SCHEDULE_WORK_ICALENDAR_UID on
+  SCHEDULE_WORK(ICALENDAR_UID);
+
+---------------------------
+-- Schedule Refresh Work --
+---------------------------
+
+create table SCHEDULE_REFRESH_WORK (
+  WORK_ID                       integer      primary key references SCHEDULE_WORK on delete cascade, -- implicit index
+  HOME_RESOURCE_ID              integer      not null references CALENDAR_HOME on delete cascade,
+  RESOURCE_ID                   integer      not null references CALENDAR_OBJECT on delete cascade,
+  ATTENDEE_COUNT                integer
+);
+
+create index SCHEDULE_REFRESH_WORK_HOME_RESOURCE_ID on
+  SCHEDULE_REFRESH_WORK(HOME_RESOURCE_ID);
+create index SCHEDULE_REFRESH_WORK_RESOURCE_ID on
+  SCHEDULE_REFRESH_WORK(RESOURCE_ID);
+
+create table SCHEDULE_REFRESH_ATTENDEES (
+  RESOURCE_ID                   integer      not null references CALENDAR_OBJECT on delete cascade,
+  ATTENDEE                      varchar(255) not null,
+
+  primary key (RESOURCE_ID, ATTENDEE)
+);
+
+create index SCHEDULE_REFRESH_ATTENDEES_RESOURCE_ID_ATTENDEE on
+  SCHEDULE_REFRESH_ATTENDEES(RESOURCE_ID, ATTENDEE);
+
+------------------------------
+-- Schedule Auto Reply Work --
+------------------------------
+
+create table SCHEDULE_AUTO_REPLY_WORK (
+  WORK_ID                       integer      primary key references SCHEDULE_WORK on delete cascade, -- implicit index
+  HOME_RESOURCE_ID              integer      not null references CALENDAR_HOME on delete cascade,
+  RESOURCE_ID                   integer      not null references CALENDAR_OBJECT on delete cascade,
+  PARTSTAT                      varchar(255) not null
+);
+
+create index SCHEDULE_AUTO_REPLY_WORK_HOME_RESOURCE_ID on
+  SCHEDULE_AUTO_REPLY_WORK(HOME_RESOURCE_ID);
+create index SCHEDULE_AUTO_REPLY_WORK_RESOURCE_ID on
+  SCHEDULE_AUTO_REPLY_WORK(RESOURCE_ID);
+
+-----------------------------
+-- Schedule Organizer Work --
+-----------------------------
+
+create table SCHEDULE_ORGANIZER_WORK (
+  WORK_ID                       integer      primary key references SCHEDULE_WORK on delete cascade, -- implicit index
+  SCHEDULE_ACTION               integer      not null, -- Enum SCHEDULE_ACTION
+  HOME_RESOURCE_ID              integer      not null references CALENDAR_HOME on delete cascade,
+  RESOURCE_ID                   integer,     -- this references a possibly non-existent CALENDAR_OBJECT
+  ICALENDAR_TEXT_OLD            text,
+  ICALENDAR_TEXT_NEW            text,
+  ATTENDEE_COUNT                integer,
+  SMART_MERGE                   boolean
+);
+
+create index SCHEDULE_ORGANIZER_WORK_HOME_RESOURCE_ID on
+  SCHEDULE_ORGANIZER_WORK(HOME_RESOURCE_ID);
+create index SCHEDULE_ORGANIZER_WORK_RESOURCE_ID on
+  SCHEDULE_ORGANIZER_WORK(RESOURCE_ID);
+
+-- Enumeration of schedule actions
+
+create table SCHEDULE_ACTION (
+  ID          integer     primary key,
+  DESCRIPTION varchar(16) not null unique
+);
+
+insert into SCHEDULE_ACTION values (0, 'create');
+insert into SCHEDULE_ACTION values (1, 'modify');
+insert into SCHEDULE_ACTION values (2, 'modify-cancelled');
+insert into SCHEDULE_ACTION values (3, 'remove');
+
+----------------------------------
+-- Schedule Organizer Send Work --
+----------------------------------
+
+create table SCHEDULE_ORGANIZER_SEND_WORK (
+  WORK_ID                       integer      primary key references SCHEDULE_WORK on delete cascade, -- implicit index
+  SCHEDULE_ACTION               integer      not null, -- Enum SCHEDULE_ACTION
+  HOME_RESOURCE_ID              integer      not null references CALENDAR_HOME on delete cascade,
+  RESOURCE_ID                   integer,     -- this references a possibly non-existent CALENDAR_OBJECT
+  ATTENDEE                      varchar(255) not null,
+  ITIP_MSG                      text,
+  NO_REFRESH                    boolean
+);
+
+create index SCHEDULE_ORGANIZER_SEND_WORK_HOME_RESOURCE_ID on
+  SCHEDULE_ORGANIZER_SEND_WORK(HOME_RESOURCE_ID);
+create index SCHEDULE_ORGANIZER_SEND_WORK_RESOURCE_ID on
+  SCHEDULE_ORGANIZER_SEND_WORK(RESOURCE_ID);
+
+-------------------------
+-- Schedule Reply Work --
+-------------------------
+
+create table SCHEDULE_REPLY_WORK (
+  WORK_ID                       integer      primary key references SCHEDULE_WORK on delete cascade, -- implicit index
+  HOME_RESOURCE_ID              integer      not null references CALENDAR_HOME on delete cascade,
+  RESOURCE_ID                   integer      not null references CALENDAR_OBJECT on delete cascade,
+  CHANGED_RIDS                  text
+);
+
+create index SCHEDULE_REPLY_WORK_HOME_RESOURCE_ID on
+  SCHEDULE_REPLY_WORK(HOME_RESOURCE_ID);
+create index SCHEDULE_REPLY_WORK_RESOURCE_ID on
+  SCHEDULE_REPLY_WORK(RESOURCE_ID);
+
+--------------------------------
+-- Schedule Reply Cancel Work --
+--------------------------------
+
+create table SCHEDULE_REPLY_CANCEL_WORK (
+  WORK_ID                       integer      primary key references SCHEDULE_WORK on delete cascade, -- implicit index
+  HOME_RESOURCE_ID              integer      not null references CALENDAR_HOME on delete cascade,
+  ICALENDAR_TEXT                text         not null
+);
+
+create index SCHEDULE_REPLY_CANCEL_WORK_HOME_RESOURCE_ID on
+  SCHEDULE_REPLY_CANCEL_WORK(HOME_RESOURCE_ID);
+
+----------------------------------
+-- Principal Purge Polling Work --
+----------------------------------
+
+create table PRINCIPAL_PURGE_POLLING_WORK (
+  WORK_ID                       integer      primary key default nextval('WORKITEM_SEQ') not null, -- implicit index
+  JOB_ID                        integer      references JOB not null
+);
+
+create index PRINCIPAL_PURGE_POLLING_WORK_JOB_ID on
+  PRINCIPAL_PURGE_POLLING_WORK(JOB_ID);
+
+--------------------------------
+-- Principal Purge Check Work --
+--------------------------------
+
+create table PRINCIPAL_PURGE_CHECK_WORK (
+  WORK_ID                       integer      primary key default nextval('WORKITEM_SEQ') not null, -- implicit index
+  JOB_ID                        integer      references JOB not null,
+  UID                           varchar(255) not null
+);
+
+create index PRINCIPAL_PURGE_CHECK_WORK_JOB_ID on
+  PRINCIPAL_PURGE_CHECK_WORK(JOB_ID);
+create index PRINCIPAL_PURGE_CHECK_WORK_UID on
+  PRINCIPAL_PURGE_CHECK_WORK(UID);
+
+--------------------------
+-- Principal Purge Work --
+--------------------------
+
+create table PRINCIPAL_PURGE_WORK (
+  WORK_ID                       integer      primary key default nextval('WORKITEM_SEQ') not null, -- implicit index
+  JOB_ID                        integer      references JOB not null,
+  UID                           varchar(255) not null
+);
+
+create index PRINCIPAL_PURGE_WORK_JOB_ID on
+  PRINCIPAL_PURGE_WORK(JOB_ID);
+create index PRINCIPAL_PURGE_WORK_UID on
+  PRINCIPAL_PURGE_WORK(UID);
+
+
+--------------------------------
+-- Principal Home Remove Work --
+--------------------------------
+
+create table PRINCIPAL_PURGE_HOME_WORK (
+  WORK_ID                       integer      primary key default nextval('WORKITEM_SEQ') not null, -- implicit index
+  JOB_ID                        integer      references JOB not null,
+  HOME_RESOURCE_ID              integer      not null references CALENDAR_HOME on delete cascade
+);
+
+create index PRINCIPAL_PURGE_HOME_WORK_JOB_ID on
+  PRINCIPAL_PURGE_HOME_WORK(JOB_ID);
+create index PRINCIPAL_PURGE_HOME_HOME_RESOURCE_ID on
+  PRINCIPAL_PURGE_HOME_WORK(HOME_RESOURCE_ID);
+
+
+--------------------
+-- Schema Version --
+--------------------
+
+create table CALENDARSERVER (
+  NAME                          varchar(255) primary key, -- implicit index
+  VALUE                         varchar(255)
+);
+
+insert into CALENDARSERVER values ('VERSION', '49');
+insert into CALENDARSERVER values ('CALENDAR-DATAVERSION', '6');
+insert into CALENDARSERVER values ('ADDRESSBOOK-DATAVERSION', '2');
+insert into CALENDARSERVER values ('NOTIFICATION-DATAVERSION', '1');
+insert into CALENDARSERVER values ('MIN-VALID-REVISION', '1');
</ins></span></pre></div>
<a id="CalendarServertrunktxdavcommondatastoresql_schemaupgradesoracledialectupgrade_from_49_to_50sql"></a>
<div class="addfile"><h4>Added: CalendarServer/trunk/txdav/common/datastore/sql_schema/upgrades/oracle-dialect/upgrade_from_49_to_50.sql (0 => 14247)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/common/datastore/sql_schema/upgrades/oracle-dialect/upgrade_from_49_to_50.sql                                (rev 0)
+++ CalendarServer/trunk/txdav/common/datastore/sql_schema/upgrades/oracle-dialect/upgrade_from_49_to_50.sql        2015-01-06 16:44:21 UTC (rev 14247)
</span><span class="lines">@@ -0,0 +1,46 @@
</span><ins>+----
+-- Copyright (c) 2012-2014 Apple Inc. All rights reserved.
+--
+-- Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an &quot;AS IS&quot; BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+----
+
+---------------------------------------------------
+-- Upgrade database schema from VERSION 49 to 50 --
+---------------------------------------------------
+
+
+-- Update existing table
+alter table SCHEDULE_REPLY_WORK drop column CHANGED_RIDS;
+alter table SCHEDULE_REPLY_WORK add (&quot;ITIP_MSG&quot; nclob);
+
+begin
+    for i in (select constraint_name
+              from   user_cons_columns
+              where  table_name = 'SCHEDULE_REPLY_WORK' and
+                     column_name = 'RESOURCE_ID' ) loop
+        execute immediate 'alter table SCHEDULE_REPLY_WORK drop constraint '|| i.constraint_name;
+    end loop;
+end;
+alter table SCHEDULE_REPLY_WORK modify (&quot;RESOURCE_ID&quot; null);
+
+-- Copy over items from existing table about to be dropped
+insert into SCHEDULE_REPLY_WORK
+        (WORK_ID, HOME_RESOURCE_ID, RESOURCE_ID, ITIP_MSG)
+        (select WORK_ID, HOME_RESOURCE_ID, null, ICALENDAR_TEXT from SCHEDULE_REPLY_CANCEL_WORK);
+
+-- Delete existing table
+drop table SCHEDULE_REPLY_CANCEL_WORK;
+
+
+-- update the version
+update CALENDARSERVER set VALUE = '50' where NAME = 'VERSION';
</ins></span></pre></div>
<a id="CalendarServertrunktxdavcommondatastoresql_schemaupgradespostgresdialectupgrade_from_49_to_50sql"></a>
<div class="addfile"><h4>Added: CalendarServer/trunk/txdav/common/datastore/sql_schema/upgrades/postgres-dialect/upgrade_from_49_to_50.sql (0 => 14247)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/common/datastore/sql_schema/upgrades/postgres-dialect/upgrade_from_49_to_50.sql                                (rev 0)
+++ CalendarServer/trunk/txdav/common/datastore/sql_schema/upgrades/postgres-dialect/upgrade_from_49_to_50.sql        2015-01-06 16:44:21 UTC (rev 14247)
</span><span class="lines">@@ -0,0 +1,37 @@
</span><ins>+----
+-- Copyright (c) 2012-2014 Apple Inc. All rights reserved.
+--
+-- Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an &quot;AS IS&quot; BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+----
+
+---------------------------------------------------
+-- Upgrade database schema from VERSION 49 to 50 --
+---------------------------------------------------
+
+-- Update existing table
+alter table SCHEDULE_REPLY_WORK drop column CHANGED_RIDS;
+alter table SCHEDULE_REPLY_WORK add column ITIP_MSG text;
+alter table SCHEDULE_REPLY_WORK drop constraint SCHEDULE_REPLY_WORK_RESOURCE_ID_FKEY;
+alter table SCHEDULE_REPLY_WORK alter column RESOURCE_ID drop not null;
+
+-- Copy over items from existing table about to be dropped
+insert into SCHEDULE_REPLY_WORK
+        (WORK_ID, HOME_RESOURCE_ID, RESOURCE_ID, ITIP_MSG)
+        (select WORK_ID, HOME_RESOURCE_ID, null, ICALENDAR_TEXT from SCHEDULE_REPLY_CANCEL_WORK);
+
+-- Delete existing table
+drop table SCHEDULE_REPLY_CANCEL_WORK;
+
+
+-- update the version
+update CALENDARSERVER set VALUE = '50' where NAME = 'VERSION';
</ins></span></pre></div>
<a id="CalendarServertrunktxdavcommondatastoretesttest_sql_dumppy"></a>
<div class="addfile"><h4>Added: CalendarServer/trunk/txdav/common/datastore/test/test_sql_dump.py (0 => 14247)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/common/datastore/test/test_sql_dump.py                                (rev 0)
+++ CalendarServer/trunk/txdav/common/datastore/test/test_sql_dump.py        2015-01-06 16:44:21 UTC (rev 14247)
</span><span class="lines">@@ -0,0 +1,220 @@
</span><ins>+##
+# Copyright (c) 2010-2014 Apple Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an &quot;AS IS&quot; BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+##
+
+from txdav.common.datastore.sql_dump import dumpSchema
+from twext.enterprise.dal.parseschema import schemaFromString
+
+&quot;&quot;&quot;
+Tests for L{txdav.common.datastore.upgrade.sql.upgrade}.
+&quot;&quot;&quot;
+
+from twisted.internet.defer import inlineCallbacks
+from twisted.trial.unittest import TestCase
+from txdav.common.datastore.test.util import theStoreBuilder, \
+    StubNotifierFactory
+
+class SQLDump(TestCase):
+    &quot;&quot;&quot;
+    Tests for L{sql_dump}.
+    &quot;&quot;&quot;
+
+    @inlineCallbacks
+    def setUp(self):
+        TestCase.setUp(self)
+
+        self.store = yield theStoreBuilder.buildStore(
+            self, {&quot;push&quot;: StubNotifierFactory()}, enableJobProcessing=False
+        )
+
+
+    @inlineCallbacks
+    def cleanUp(self):
+        startTxn = self.store.newTransaction(&quot;test_sql_dump&quot;)
+        yield startTxn.execSQL(&quot;set search_path to public;&quot;)
+        yield startTxn.execSQL(&quot;drop schema test_sql_dump cascade;&quot;)
+        yield startTxn.commit()
+
+
+    @inlineCallbacks
+    def _loadSchema(self, schema):
+        &quot;&quot;&quot;
+        Use the postgres schema mechanism to do tests under a separate &quot;namespace&quot;
+        in postgres that we can quickly wipe clean afterwards.
+        &quot;&quot;&quot;
+        startTxn = self.store.newTransaction(&quot;test_sql_dump&quot;)
+        yield startTxn.execSQL(&quot;create schema test_sql_dump;&quot;)
+        yield startTxn.execSQL(&quot;set search_path to test_sql_dump;&quot;)
+        yield startTxn.execSQL(schema)
+        yield startTxn.commit()
+
+        self.addCleanup(self.cleanUp)
+
+
+    @inlineCallbacks
+    def _schemaCheck(self, schema, schema_bad):
+
+        # Load old schema and populate with data
+        yield self._loadSchema(schema)
+
+        txn = self.store.newTransaction(&quot;loadData&quot;)
+        dumped = yield dumpSchema(txn, &quot;test&quot;, schemaname=&quot;test_sql_dump&quot;)
+        yield txn.commit()
+
+        parsed = schemaFromString(schema)
+        self.assertEqual(parsed.compare(dumped), [])
+
+        parsed_bad = schemaFromString(schema_bad)
+        self.assertNotEqual(parsed_bad.compare(dumped), [])
+
+
+    @inlineCallbacks
+    def test_pkey_column(self):
+
+        schema = &quot;&quot;&quot;
+CREATE TABLE FOO (
+    ID1 integer primary key,
+    ID2 integer not null
+);
+&quot;&quot;&quot;
+
+        schema_bad = &quot;&quot;&quot;
+CREATE TABLE FOO (
+    ID1 integer primary key,
+    ID2 integer
+);
+&quot;&quot;&quot;
+
+        yield self._schemaCheck(schema, schema_bad)
+
+
+    @inlineCallbacks
+    def test_pkey_table(self):
+
+        schema = &quot;&quot;&quot;
+CREATE TABLE FOO (
+    ID1 integer not null,
+    ID2 integer not null,
+
+    primary key (ID1)
+);
+&quot;&quot;&quot;
+
+        schema_bad = &quot;&quot;&quot;
+CREATE TABLE FOO (
+    ID1 integer,
+    ID2 integer,
+
+    primary key (ID1)
+);
+&quot;&quot;&quot;
+
+        yield self._schemaCheck(schema, schema_bad)
+
+
+    @inlineCallbacks
+    def test_multiple_pkey_table(self):
+
+        schema = &quot;&quot;&quot;
+CREATE TABLE FOO (
+    ID1 integer not null,
+    ID2 integer not null,
+    ID3 integer not null,
+
+    primary key (ID1, ID2)
+);
+&quot;&quot;&quot;
+
+        schema_bad = &quot;&quot;&quot;
+CREATE TABLE FOO (
+    ID1 integer,
+    ID2 integer,
+    ID3 integer,
+
+    primary key (ID1, ID2)
+);
+&quot;&quot;&quot;
+
+        yield self._schemaCheck(schema, schema_bad)
+
+
+    @inlineCallbacks
+    def test_unique_column(self):
+
+        schema = &quot;&quot;&quot;
+CREATE TABLE FOO (
+    ID1 integer unique,
+    ID2 integer not null
+);
+&quot;&quot;&quot;
+
+        schema_bad = &quot;&quot;&quot;
+CREATE TABLE FOO (
+    ID1 integer unique,
+    ID2 integer
+);
+&quot;&quot;&quot;
+
+        yield self._schemaCheck(schema, schema_bad)
+
+
+    @inlineCallbacks
+    def test_unique_table(self):
+
+        schema = &quot;&quot;&quot;
+CREATE TABLE FOO (
+    ID1 integer,
+    ID2 integer not null,
+
+    unique (ID1)
+);
+&quot;&quot;&quot;
+
+        schema_bad = &quot;&quot;&quot;
+CREATE TABLE FOO (
+    ID1 integer,
+    ID2 integer,
+
+    unique (ID1)
+);
+&quot;&quot;&quot;
+
+        yield self._schemaCheck(schema, schema_bad)
+
+
+    @inlineCallbacks
+    def test_multiple_unique_table(self):
+
+        schema = &quot;&quot;&quot;
+CREATE TABLE FOO (
+    ID1 integer,
+    ID2 integer,
+    ID3 integer not null,
+
+    unique (ID1, ID2)
+);
+&quot;&quot;&quot;
+
+        schema_bad = &quot;&quot;&quot;
+CREATE TABLE FOO (
+    ID1 integer,
+    ID2 integer,
+    ID3 integer,
+
+    unique (ID1, ID2)
+);
+&quot;&quot;&quot;
+
+        yield self._schemaCheck(schema, schema_bad)
</ins></span></pre></div>
<a id="CalendarServertrunktxdavcommondatastoretesttest_sql_schema_filespy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/common/datastore/test/test_sql_schema_files.py (14246 => 14247)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/common/datastore/test/test_sql_schema_files.py        2015-01-06 16:42:48 UTC (rev 14246)
+++ CalendarServer/trunk/txdav/common/datastore/test/test_sql_schema_files.py        2015-01-06 16:44:21 UTC (rev 14247)
</span><span class="lines">@@ -14,6 +14,7 @@
</span><span class="cx"> # limitations under the License.
</span><span class="cx"> # #
</span><span class="cx"> 
</span><ins>+from twext.enterprise.dal.model import Constraint
</ins><span class="cx"> from twext.enterprise.dal.parseschema import schemaFromPath
</span><span class="cx"> from twisted.python.modules import getModule
</span><span class="cx"> from twisted.trial.unittest import TestCase
</span><span class="lines">@@ -102,7 +103,18 @@
</span><span class="cx"> 
</span><span class="cx">         self.assertEqual(current_version, current_oracle_version)
</span><span class="cx"> 
</span><del>-        mismatched = schemaFromPath(currentSchema).compare(schemaFromPath(currentOracleSchema))
</del><ins>+        schema_current = schemaFromPath(currentSchema)
+        schema_oracle = schemaFromPath(currentOracleSchema)
+
+        # Remove any not null constraints in the postgres schema for text columns as in
+        # Oracle nclob or nvarchar never uses not null
+        for table in schema_current.tables:
+            for constraint in tuple(table.constraints):
+                if constraint.type == Constraint.NOT_NULL and len(constraint.affectsColumns) == 1:
+                    if constraint.affectsColumns[0].type.name in (&quot;text&quot;, &quot;char&quot;, &quot;varchar&quot;):
+                        table.constraints.remove(constraint)
+
+        mismatched = schema_current.compare(schema_oracle)
</ins><span class="cx">         self.assertEqual(len(mismatched), 0, msg=&quot;, &quot;.join(mismatched))
</span><span class="cx"> 
</span><span class="cx"> 
</span></span></pre></div>
<a id="CalendarServertrunktxdavcommondatastoreupgradesqltesttest_upgradepy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/common/datastore/upgrade/sql/test/test_upgrade.py (14246 => 14247)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/common/datastore/upgrade/sql/test/test_upgrade.py        2015-01-06 16:42:48 UTC (rev 14246)
+++ CalendarServer/trunk/txdav/common/datastore/upgrade/sql/test/test_upgrade.py        2015-01-06 16:44:21 UTC (rev 14247)
</span><span class="lines">@@ -212,7 +212,9 @@
</span><span class="cx">         # These are special case exceptions
</span><span class="cx">         for i in (
</span><span class="cx">             &quot;Table: CALENDAR_HOME, column name DATAVERSION default mismatch&quot;,
</span><ins>+            &quot;Table: CALENDAR_HOME, mismatched constraints: set([&lt;Constraint: (NOT NULL ['DATAVERSION'] None)&gt;])&quot;,
</ins><span class="cx">             &quot;Table: ADDRESSBOOK_HOME, column name DATAVERSION default mismatch&quot;,
</span><ins>+            &quot;Table: ADDRESSBOOK_HOME, mismatched constraints: set([&lt;Constraint: (NOT NULL ['DATAVERSION'] None)&gt;])&quot;,
</ins><span class="cx">             &quot;Table: PUSH_NOTIFICATION_WORK, column name PUSH_PRIORITY default mismatch&quot;,
</span><span class="cx">         ):
</span><span class="cx">             try:
</span></span></pre></div>
<a id="CalendarServertrunktxdavcommondatastoreupgradesqltesttest_upgrade_with_datapy"></a>
<div class="addfile"><h4>Added: CalendarServer/trunk/txdav/common/datastore/upgrade/sql/test/test_upgrade_with_data.py (0 => 14247)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/common/datastore/upgrade/sql/test/test_upgrade_with_data.py                                (rev 0)
+++ CalendarServer/trunk/txdav/common/datastore/upgrade/sql/test/test_upgrade_with_data.py        2015-01-06 16:44:21 UTC (rev 14247)
</span><span class="lines">@@ -0,0 +1,274 @@
</span><ins>+##
+# Copyright (c) 2010-2014 Apple Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an &quot;AS IS&quot; BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+##
+from twext.enterprise.dal.syntax import Insert, Select
+from txdav.common.datastore.sql_tables import _populateSchema
+from datetime import datetime
+
+&quot;&quot;&quot;
+Tests for L{txdav.common.datastore.upgrade.sql.upgrade}.
+&quot;&quot;&quot;
+
+from twext.enterprise.ienterprise import POSTGRES_DIALECT
+from twisted.internet.defer import inlineCallbacks, returnValue
+from twisted.trial.unittest import TestCase
+from txdav.common.datastore.test.util import theStoreBuilder, \
+    StubNotifierFactory
+from txdav.common.datastore.upgrade.sql.upgrade import UpgradeDatabaseSchemaStep
+import re
+
+class SchemaUpgradeWithDataTests(TestCase):
+    &quot;&quot;&quot;
+    Tests for upgrading schema when data is present in the database to make sure data conversion
+    is done correctly.
+    &quot;&quot;&quot;
+
+    @staticmethod
+    def _getRawSchemaVersion(fp, versionKey):
+        schema = fp.getContent()
+        found = re.search(&quot;insert into CALENDARSERVER (\(NAME, VALUE\) )?values \('%s', '(\d+)'\);&quot; % (versionKey,), schema)
+        return int(found.group(2)) if found else None
+
+
+    def _getSchemaVersion(self, fp, versionKey):
+        found = self._getRawSchemaVersion(fp, versionKey)
+        if found is None:
+            if versionKey == &quot;VERSION&quot;:
+                self.fail(&quot;Could not determine schema version for: %s&quot; % (fp,))
+            else:
+                return 1
+        return found
+
+
+    @inlineCallbacks
+    def setUp(self):
+        TestCase.setUp(self)
+
+        test_upgrader = UpgradeDatabaseSchemaStep(None)
+        self.upgradePath = test_upgrader.schemaLocation.child(&quot;old&quot;).child(POSTGRES_DIALECT)
+        self.currentVersion = self._getSchemaVersion(test_upgrader.schemaLocation.child(&quot;current.sql&quot;), &quot;VERSION&quot;)
+
+        self.store = yield theStoreBuilder.buildStore(
+            self, {&quot;push&quot;: StubNotifierFactory()}, enableJobProcessing=False
+        )
+
+
+    @inlineCallbacks
+    def cleanUp(self):
+        startTxn = self.store.newTransaction(&quot;test_dbUpgrades&quot;)
+        yield startTxn.execSQL(&quot;set search_path to public;&quot;)
+        yield startTxn.execSQL(&quot;drop schema test_dbUpgrades cascade;&quot;)
+        yield startTxn.commit()
+
+
+    @inlineCallbacks
+    def _loadOldSchema(self, path):
+        &quot;&quot;&quot;
+        Use the postgres schema mechanism to do tests under a separate &quot;namespace&quot;
+        in postgres that we can quickly wipe clean afterwards.
+        &quot;&quot;&quot;
+        startTxn = self.store.newTransaction(&quot;test_dbUpgrades&quot;)
+        yield startTxn.execSQL(&quot;create schema test_dbUpgrades;&quot;)
+        yield startTxn.execSQL(&quot;set search_path to test_dbUpgrades;&quot;)
+        yield startTxn.execSQL(path.getContent())
+        yield startTxn.commit()
+
+        self.addCleanup(self.cleanUp)
+
+        returnValue(_populateSchema(path))
+
+
+    @inlineCallbacks
+    def _loadVersion(self):
+        startTxn = self.store.newTransaction(&quot;test_dbUpgrades&quot;)
+        new_version = yield startTxn.execSQL(&quot;select value from calendarserver where name = 'VERSION';&quot;)
+        yield startTxn.commit()
+        returnValue(int(new_version[0][0]))
+
+
+    @inlineCallbacks
+    def test_upgrade_SCHEDULE_REPLY_CANCEL(self):
+
+        cal1 = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+METHOD:REPLY
+BEGIN:VEVENT
+UID:1234-5678
+DTSTART:20071114T010000Z
+DURATION:PT1H
+DTSTAMP:20071114T000000Z
+ATTENDEE:mailto:user01@example.com
+ATTENDEE:mailto:user02@example.com
+ORGANIZER:mailto:user01@example.com
+SUMMARY:Test
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;
+
+        # Load old schema and populate with data
+        schema = yield self._loadOldSchema(self.upgradePath.child(&quot;v49.sql&quot;))
+
+        txn = self.store.newTransaction(&quot;loadData&quot;)
+        yield Insert(
+            {
+                schema.CALENDAR_HOME.RESOURCE_ID: 1,
+                schema.CALENDAR_HOME.OWNER_UID: &quot;abcdefg&quot;,
+            }
+        ).on(txn)
+        yield Insert(
+            {
+                schema.JOB.JOB_ID: 1,
+                schema.JOB.WORK_TYPE: &quot;SCHEDULE_REPLY_CANCEL_WORK&quot;,
+                schema.JOB.NOT_BEFORE: datetime.utcnow(),
+            }
+        ).on(txn)
+        yield Insert(
+            {
+                schema.SCHEDULE_WORK.WORK_ID: 1,
+                schema.SCHEDULE_WORK.JOB_ID: 1,
+                schema.SCHEDULE_WORK.ICALENDAR_UID: &quot;1234-5678&quot;,
+                schema.SCHEDULE_WORK.WORK_TYPE: &quot;SCHEDULE_REPLY_CANCEL_WORK&quot;,
+            }
+        ).on(txn)
+        yield Insert(
+            {
+                schema.SCHEDULE_REPLY_CANCEL_WORK.WORK_ID: 1,
+                schema.SCHEDULE_REPLY_CANCEL_WORK.HOME_RESOURCE_ID: 1,
+                schema.SCHEDULE_REPLY_CANCEL_WORK.ICALENDAR_TEXT: cal1,
+            }
+        ).on(txn)
+        yield txn.commit()
+
+        # Try to upgrade and verify new version afterwards
+        upgrader = UpgradeDatabaseSchemaStep(self.store)
+        yield upgrader.databaseUpgrade()
+
+        new_version = yield self._loadVersion()
+        self.assertEqual(new_version, self.currentVersion)
+
+        txn = self.store.newTransaction(&quot;loadData&quot;)
+        jobs = yield Select(
+            From=schema.JOB,
+        ).on(txn)
+        schedules = yield Select(
+            From=schema.SCHEDULE_WORK,
+        ).on(txn)
+        replies = yield Select(
+            From=schema.SCHEDULE_REPLY_WORK,
+        ).on(txn)
+        yield txn.commit()
+
+        self.assertEqual(len(jobs), 1)
+        self.assertEqual(len(schedules), 1)
+        self.assertEqual(len(replies), 1)
+
+        self.assertEqual(replies[0], [1, 1, None, cal1, ])
+
+
+    @inlineCallbacks
+    def test_upgrade_SCHEDULE_REPLY(self):
+
+        cal1 = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:1234-5678
+DTSTART:20071114T010000Z
+DURATION:PT1H
+DTSTAMP:20071114T000000Z
+ATTENDEE:mailto:user01@example.com
+ATTENDEE:mailto:user02@example.com
+ORGANIZER:mailto:user01@example.com
+SUMMARY:Test
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;
+
+        # Load old schema and populate with data
+        schema = yield self._loadOldSchema(self.upgradePath.child(&quot;v49.sql&quot;))
+
+        txn = self.store.newTransaction(&quot;loadData&quot;)
+        yield Insert(
+            {
+                schema.CALENDAR_HOME.RESOURCE_ID: 1,
+                schema.CALENDAR_HOME.OWNER_UID: &quot;abcdefg&quot;,
+            }
+        ).on(txn)
+        yield Insert(
+            {
+                schema.CALENDAR.RESOURCE_ID: 2,
+            }
+        ).on(txn)
+        yield Insert(
+            {
+                schema.CALENDAR_OBJECT.RESOURCE_ID: 3,
+                schema.CALENDAR_OBJECT.CALENDAR_RESOURCE_ID: 2,
+                schema.CALENDAR_OBJECT.RESOURCE_NAME: &quot;1.ics&quot;,
+                schema.CALENDAR_OBJECT.ICALENDAR_TEXT: cal1,
+                schema.CALENDAR_OBJECT.ICALENDAR_UID: &quot;1234-5678&quot;,
+                schema.CALENDAR_OBJECT.ICALENDAR_TYPE: &quot;VEVENT&quot;,
+                schema.CALENDAR_OBJECT.MD5: &quot;md5-1234567890&quot;,
+            }
+        ).on(txn)
+        yield Insert(
+            {
+                schema.JOB.JOB_ID: 1,
+                schema.JOB.WORK_TYPE: &quot;SCHEDULE_REPLY_WORK&quot;,
+                schema.JOB.NOT_BEFORE: datetime.utcnow(),
+            }
+        ).on(txn)
+        yield Insert(
+            {
+                schema.SCHEDULE_WORK.WORK_ID: 1,
+                schema.SCHEDULE_WORK.JOB_ID: 1,
+                schema.SCHEDULE_WORK.ICALENDAR_UID: &quot;1234-5678&quot;,
+                schema.SCHEDULE_WORK.WORK_TYPE: &quot;SCHEDULE_REPLY_WORK&quot;,
+            }
+        ).on(txn)
+        yield Insert(
+            {
+                schema.SCHEDULE_REPLY_WORK.WORK_ID: 1,
+                schema.SCHEDULE_REPLY_WORK.HOME_RESOURCE_ID: 1,
+                schema.SCHEDULE_REPLY_WORK.RESOURCE_ID: 3,
+                schema.SCHEDULE_REPLY_WORK.CHANGED_RIDS: None,
+            }
+        ).on(txn)
+        yield txn.commit()
+
+        # Try to upgrade and verify new version afterwards
+        upgrader = UpgradeDatabaseSchemaStep(self.store)
+        yield upgrader.databaseUpgrade()
+
+        new_version = yield self._loadVersion()
+        self.assertEqual(new_version, self.currentVersion)
+
+        txn = self.store.newTransaction(&quot;loadData&quot;)
+        jobs = yield Select(
+            From=schema.JOB,
+        ).on(txn)
+        schedules = yield Select(
+            From=schema.SCHEDULE_WORK,
+        ).on(txn)
+        replies = yield Select(
+            From=schema.SCHEDULE_REPLY_WORK,
+        ).on(txn)
+        yield txn.commit()
+
+        self.assertEqual(len(jobs), 1)
+        self.assertEqual(len(schedules), 1)
+        self.assertEqual(len(replies), 1)
+
+        self.assertEqual(replies[0], [1, 1, 3, None, ])
</ins></span></pre></div>
<a id="CalendarServertrunktxdavwhocachepy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/who/cache.py (14246 => 14247)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/who/cache.py        2015-01-06 16:42:48 UTC (rev 14246)
+++ CalendarServer/trunk/txdav/who/cache.py        2015-01-06 16:44:21 UTC (rev 14247)
</span><span class="lines">@@ -377,7 +377,7 @@
</span><span class="cx">                 # but there might be others in the directory service with that
</span><span class="cx">                 # same email address.
</span><span class="cx">                 self.cacheRecord(
</span><del>-                    records[0],
</del><ins>+                    list(records)[0],
</ins><span class="cx">                     (
</span><span class="cx">                         IndexType.uid, IndexType.guid,
</span><span class="cx">                         IndexType.shortName, IndexType.emailAddress
</span></span></pre></div>
<a id="CalendarServertrunktxdavwhotesttest_group_attendeespy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/who/test/test_group_attendees.py (14246 => 14247)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/who/test/test_group_attendees.py        2015-01-06 16:42:48 UTC (rev 14246)
+++ CalendarServer/trunk/txdav/who/test/test_group_attendees.py        2015-01-06 16:44:21 UTC (rev 14247)
</span><span class="lines">@@ -26,7 +26,7 @@
</span><span class="cx"> from twisted.internet.defer import inlineCallbacks, returnValue
</span><span class="cx"> from twisted.trial import unittest
</span><span class="cx"> from twistedcaldav.config import config
</span><del>-from twistedcaldav.ical import Component, normalize_iCalStr, ignoredComponents
</del><ins>+from twistedcaldav.ical import Component, normalize_iCalStr
</ins><span class="cx"> from txdav.caldav.datastore.test.util import populateCalendarsFrom, CommonCommonTests
</span><span class="cx"> from txdav.common.datastore.sql_tables import schema
</span><span class="cx"> from txdav.who.directory import CalendarDirectoryRecordMixin
</span><span class="lines">@@ -87,10 +87,7 @@
</span><span class="cx"> 
</span><span class="cx">         def orderMemberValues(event):
</span><span class="cx"> 
</span><del>-            for component in event.subcomponents():
-                if component.name() in ignoredComponents:
-                    continue
-
</del><ins>+            for component in event.subcomponents(ignore=True):
</ins><span class="cx">                 # remove all values and add them again
</span><span class="cx">                 # this is sort of a hack, better pycalendar has ordering
</span><span class="cx">                 for attendeeProp in tuple(component.properties(&quot;ATTENDEE&quot;)):
</span><span class="lines">@@ -1227,9 +1224,7 @@
</span><span class="cx">         cobjs = yield cal.objectResources()
</span><span class="cx">         for cobj in cobjs:
</span><span class="cx">             vcalendar = yield cobj.component()
</span><del>-            for component in vcalendar.subcomponents():
-                if component.name() in ignoredComponents:
-                    continue
</del><ins>+            for component in vcalendar.subcomponents(ignore=True):
</ins><span class="cx">                 props = {
</span><span class="cx">                     &quot;relatedTo&quot;: component.getProperty(&quot;RELATED-TO&quot;),
</span><span class="cx">                     &quot;start&quot;: component.getProperty(&quot;DTSTART&quot;),
</span><span class="lines">@@ -1406,9 +1401,7 @@
</span><span class="cx">         cobjs = yield cal.objectResources()
</span><span class="cx">         for cobj in cobjs:
</span><span class="cx">             vcalendar = yield cobj.component()
</span><del>-            for component in vcalendar.subcomponents():
-                if component.name() in ignoredComponents:
-                    continue
</del><ins>+            for component in vcalendar.subcomponents(ignore=True):
</ins><span class="cx">                 props = {
</span><span class="cx">                     &quot;relatedTo&quot;: component.getProperty(&quot;RELATED-TO&quot;),
</span><span class="cx">                     &quot;start&quot;: component.getProperty(&quot;DTSTART&quot;),
</span></span></pre>
</div>
</div>

</body>
</html>