<!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>[13198] CalendarServer/trunk/txdav</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/13198">13198</a></dd>
<dt>Author</dt> <dd>sagen@apple.com</dd>
<dt>Date</dt> <dd>2014-04-08 11:01:59 -0700 (Tue, 08 Apr 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>make addDelegate idempotent; add delegation-related indices to schema</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServertrunktxdavcommondatastoresqlpy">CalendarServer/trunk/txdav/common/datastore/sql.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="#CalendarServertrunktxdavcommondatastoresql_schemaupgradesoracledialectupgrade_from_34_to_35sql">CalendarServer/trunk/txdav/common/datastore/sql_schema/upgrades/oracle-dialect/upgrade_from_34_to_35.sql</a></li>
<li><a href="#CalendarServertrunktxdavcommondatastoresql_schemaupgradespostgresdialectupgrade_from_34_to_35sql">CalendarServer/trunk/txdav/common/datastore/sql_schema/upgrades/postgres-dialect/upgrade_from_34_to_35.sql</a></li>
<li><a href="#CalendarServertrunktxdavwhotesttest_delegatespy">CalendarServer/trunk/txdav/who/test/test_delegates.py</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServertrunktxdavcommondatastoresqlpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/common/datastore/sql.py (13197 => 13198)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/common/datastore/sql.py        2014-04-08 16:31:32 UTC (rev 13197)
+++ CalendarServer/trunk/txdav/common/datastore/sql.py        2014-04-08 18:01:59 UTC (rev 13198)
</span><span class="lines">@@ -1452,6 +1452,7 @@
</span><span class="cx"> )
</span><span class="cx">
</span><span class="cx">
</span><ins>+ @inlineCallbacks
</ins><span class="cx"> def addDelegate(self, delegator, delegate, readWrite):
</span><span class="cx"> """
</span><span class="cx"> Adds a row to the DELEGATES table. The delegate should not be a
</span><span class="lines">@@ -1465,14 +1466,21 @@
</span><span class="cx"> read-only access
</span><span class="cx"> @type readWrite: C{boolean}
</span><span class="cx"> """
</span><del>- return self._addDelegateQuery.on(
- self,
- delegator=delegator.encode("utf-8"),
- delegate=delegate.encode("utf-8"),
- readWrite=1 if readWrite else 0
- )
</del><ins>+ savepoint = SavepointAction("addDelegate")
+ yield savepoint.acquire(self)
+ try:
+ yield self._addDelegateQuery.on(
+ self,
+ delegator=delegator.encode("utf-8"),
+ delegate=delegate.encode("utf-8"),
+ readWrite=1 if readWrite else 0
+ )
+ except Exception:
+ # Row already exists
+ yield savepoint.rollback(self)
</ins><span class="cx">
</span><span class="cx">
</span><ins>+ @inlineCallbacks
</ins><span class="cx"> def addDelegateGroup(self, delegator, delegateGroupID, readWrite,
</span><span class="cx"> isExternal=False):
</span><span class="cx"> """
</span><span class="lines">@@ -1487,13 +1495,19 @@
</span><span class="cx"> read-only access
</span><span class="cx"> @type readWrite: C{boolean}
</span><span class="cx"> """
</span><del>- return self._addDelegateGroupQuery.on(
- self,
- delegator=delegator.encode("utf-8"),
- groupID=delegateGroupID,
- readWrite=1 if readWrite else 0,
- isExternal=1 if isExternal else 0
- )
</del><ins>+ savepoint = SavepointAction("addDelegateGroup")
+ yield savepoint.acquire(self)
+ try:
+ yield self._addDelegateGroupQuery.on(
+ self,
+ delegator=delegator.encode("utf-8"),
+ groupID=delegateGroupID,
+ readWrite=1 if readWrite else 0,
+ isExternal=1 if isExternal else 0
+ )
+ except Exception:
+ # Row already exists
+ yield savepoint.rollback(self)
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx"> def removeDelegate(self, delegator, delegate, readWrite):
</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 (13197 => 13198)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/common/datastore/sql_schema/current-oracle-dialect.sql        2014-04-08 16:31:32 UTC (rev 13197)
+++ CalendarServer/trunk/txdav/common/datastore/sql_schema/current-oracle-dialect.sql        2014-04-08 18:01:59 UTC (rev 13198)
</span><span class="lines">@@ -8,7 +8,7 @@
</span><span class="cx"> "HOSTNAME" nvarchar2(255),
</span><span class="cx"> "PID" integer not null,
</span><span class="cx"> "PORT" integer not null,
</span><del>- "TIME" timestamp default CURRENT_TIMESTAMP at time zone 'UTC' not null,
</del><ins>+ "TIME" timestamp default CURRENT_TIMESTAMP at time zone 'UTC' not null,
</ins><span class="cx"> primary key("HOSTNAME", "PORT")
</span><span class="cx"> );
</span><span class="cx">
</span><span class="lines">@@ -80,7 +80,7 @@
</span><span class="cx"> "NOTIFICATION_DATA" nclob,
</span><span class="cx"> "MD5" nchar(32),
</span><span class="cx"> "CREATED" timestamp default CURRENT_TIMESTAMP at time zone 'UTC',
</span><del>- "MODIFIED" timestamp default CURRENT_TIMESTAMP at time zone 'UTC',
</del><ins>+ "MODIFIED" timestamp default CURRENT_TIMESTAMP at time zone 'UTC',
</ins><span class="cx"> unique("NOTIFICATION_UID", "NOTIFICATION_HOME_RESOURCE_ID")
</span><span class="cx"> );
</span><span class="cx">
</span><span class="lines">@@ -98,8 +98,8 @@
</span><span class="cx"> "ALARM_VEVENT_ALLDAY" nclob default null,
</span><span class="cx"> "ALARM_VTODO_TIMED" nclob default null,
</span><span class="cx"> "ALARM_VTODO_ALLDAY" nclob default null,
</span><del>- "TIMEZONE" nclob default null,
- primary key("CALENDAR_HOME_RESOURCE_ID", "CALENDAR_RESOURCE_ID"),
</del><ins>+ "TIMEZONE" nclob default null,
+ primary key("CALENDAR_HOME_RESOURCE_ID", "CALENDAR_RESOURCE_ID"),
</ins><span class="cx"> unique("CALENDAR_HOME_RESOURCE_ID", "CALENDAR_RESOURCE_NAME")
</span><span class="cx"> );
</span><span class="cx">
</span><span class="lines">@@ -149,7 +149,7 @@
</span><span class="cx"> "PRIVATE_COMMENTS" integer default 0 not null,
</span><span class="cx"> "MD5" nchar(32),
</span><span class="cx"> "CREATED" timestamp default CURRENT_TIMESTAMP at time zone 'UTC',
</span><del>- "MODIFIED" timestamp default CURRENT_TIMESTAMP at time zone 'UTC',
</del><ins>+ "MODIFIED" timestamp default CURRENT_TIMESTAMP at time zone 'UTC',
</ins><span class="cx"> unique("CALENDAR_RESOURCE_ID", "RESOURCE_NAME")
</span><span class="cx"> );
</span><span class="cx">
</span><span class="lines">@@ -213,8 +213,8 @@
</span><span class="cx"> create table ATTACHMENT_CALENDAR_OBJECT (
</span><span class="cx"> "ATTACHMENT_ID" integer not null references ATTACHMENT on delete cascade,
</span><span class="cx"> "MANAGED_ID" nvarchar2(255),
</span><del>- "CALENDAR_OBJECT_RESOURCE_ID" integer not null references CALENDAR_OBJECT on delete cascade,
- primary key("ATTACHMENT_ID", "CALENDAR_OBJECT_RESOURCE_ID"),
</del><ins>+ "CALENDAR_OBJECT_RESOURCE_ID" integer not null references CALENDAR_OBJECT on delete cascade,
+ primary key("ATTACHMENT_ID", "CALENDAR_OBJECT_RESOURCE_ID"),
</ins><span class="cx"> unique("MANAGED_ID", "CALENDAR_OBJECT_RESOURCE_ID")
</span><span class="cx"> );
</span><span class="cx">
</span><span class="lines">@@ -222,7 +222,7 @@
</span><span class="cx"> "RESOURCE_ID" integer not null,
</span><span class="cx"> "NAME" nvarchar2(255),
</span><span class="cx"> "VALUE" nclob,
</span><del>- "VIEWER_UID" nvarchar2(255),
</del><ins>+ "VIEWER_UID" nvarchar2(255),
</ins><span class="cx"> primary key("RESOURCE_ID", "NAME", "VIEWER_UID")
</span><span class="cx"> );
</span><span class="cx">
</span><span class="lines">@@ -249,8 +249,8 @@
</span><span class="cx"> "BIND_MODE" integer not null,
</span><span class="cx"> "BIND_STATUS" integer not null,
</span><span class="cx"> "BIND_REVISION" integer default 0 not null,
</span><del>- "MESSAGE" nclob,
- primary key("ADDRESSBOOK_HOME_RESOURCE_ID", "OWNER_HOME_RESOURCE_ID"),
</del><ins>+ "MESSAGE" nclob,
+ primary key("ADDRESSBOOK_HOME_RESOURCE_ID", "OWNER_HOME_RESOURCE_ID"),
</ins><span class="cx"> unique("ADDRESSBOOK_HOME_RESOURCE_ID", "ADDRESSBOOK_RESOURCE_NAME")
</span><span class="cx"> );
</span><span class="cx">
</span><span class="lines">@@ -263,8 +263,8 @@
</span><span class="cx"> "KIND" integer not null,
</span><span class="cx"> "MD5" nchar(32),
</span><span class="cx"> "CREATED" timestamp default CURRENT_TIMESTAMP at time zone 'UTC',
</span><del>- "MODIFIED" timestamp default CURRENT_TIMESTAMP at time zone 'UTC',
- unique("ADDRESSBOOK_HOME_RESOURCE_ID", "RESOURCE_NAME"),
</del><ins>+ "MODIFIED" timestamp default CURRENT_TIMESTAMP at time zone 'UTC',
+ unique("ADDRESSBOOK_HOME_RESOURCE_ID", "RESOURCE_NAME"),
</ins><span class="cx"> unique("ADDRESSBOOK_HOME_RESOURCE_ID", "VCARD_UID")
</span><span class="cx"> );
</span><span class="cx">
</span><span class="lines">@@ -283,14 +283,14 @@
</span><span class="cx"> "MEMBER_ID" integer not null,
</span><span class="cx"> "REVISION" integer not null,
</span><span class="cx"> "REMOVED" integer default 0 not null,
</span><del>- "MODIFIED" timestamp default CURRENT_TIMESTAMP at time zone 'UTC',
</del><ins>+ "MODIFIED" timestamp default CURRENT_TIMESTAMP at time zone 'UTC',
</ins><span class="cx"> primary key("GROUP_ID", "MEMBER_ID", "REVISION")
</span><span class="cx"> );
</span><span class="cx">
</span><span class="cx"> create table ABO_FOREIGN_MEMBERS (
</span><span class="cx"> "GROUP_ID" integer not null references ADDRESSBOOK_OBJECT on delete cascade,
</span><span class="cx"> "ADDRESSBOOK_ID" integer not null references ADDRESSBOOK_HOME on delete cascade,
</span><del>- "MEMBER_ADDRESS" nvarchar2(255),
</del><ins>+ "MEMBER_ADDRESS" nvarchar2(255),
</ins><span class="cx"> primary key("GROUP_ID", "MEMBER_ADDRESS")
</span><span class="cx"> );
</span><span class="cx">
</span><span class="lines">@@ -302,8 +302,8 @@
</span><span class="cx"> "BIND_MODE" integer not null,
</span><span class="cx"> "BIND_STATUS" integer not null,
</span><span class="cx"> "BIND_REVISION" integer default 0 not null,
</span><del>- "MESSAGE" nclob,
- primary key("ADDRESSBOOK_HOME_RESOURCE_ID", "GROUP_RESOURCE_ID"),
</del><ins>+ "MESSAGE" nclob,
+ primary key("ADDRESSBOOK_HOME_RESOURCE_ID", "GROUP_RESOURCE_ID"),
</ins><span class="cx"> unique("ADDRESSBOOK_HOME_RESOURCE_ID", "GROUP_ADDRESSBOOK_NAME")
</span><span class="cx"> );
</span><span class="cx">
</span><span class="lines">@@ -333,7 +333,7 @@
</span><span class="cx"> "RESOURCE_NAME" nvarchar2(255),
</span><span class="cx"> "REVISION" integer not null,
</span><span class="cx"> "DELETED" integer not null,
</span><del>- "MODIFIED" timestamp default CURRENT_TIMESTAMP at time zone 'UTC',
</del><ins>+ "MODIFIED" timestamp default CURRENT_TIMESTAMP at time zone 'UTC',
</ins><span class="cx"> unique("NOTIFICATION_HOME_RESOURCE_ID", "RESOURCE_NAME")
</span><span class="cx"> );
</span><span class="cx">
</span><span class="lines">@@ -343,7 +343,7 @@
</span><span class="cx"> "MODIFIED" integer not null,
</span><span class="cx"> "SUBSCRIBER_GUID" nvarchar2(255),
</span><span class="cx"> "USER_AGENT" nvarchar2(255) default null,
</span><del>- "IP_ADDR" nvarchar2(255) default null,
</del><ins>+ "IP_ADDR" nvarchar2(255) default null,
</ins><span class="cx"> primary key("TOKEN", "RESOURCE_KEY")
</span><span class="cx"> );
</span><span class="cx">
</span><span class="lines">@@ -352,7 +352,7 @@
</span><span class="cx"> "ORGANIZER" nvarchar2(255),
</span><span class="cx"> "ATTENDEE" nvarchar2(255),
</span><span class="cx"> "ICALUID" nvarchar2(255),
</span><del>- "ACCESSED" timestamp default CURRENT_TIMESTAMP at time zone 'UTC',
</del><ins>+ "ACCESSED" timestamp default CURRENT_TIMESTAMP at time zone 'UTC',
</ins><span class="cx"> primary key("ORGANIZER", "ATTENDEE", "ICALUID")
</span><span class="cx"> );
</span><span class="cx">
</span><span class="lines">@@ -426,18 +426,20 @@
</span><span class="cx"> create table DELEGATES (
</span><span class="cx"> "DELEGATOR" nvarchar2(255),
</span><span class="cx"> "DELEGATE" nvarchar2(255),
</span><del>- "READ_WRITE" integer not null
</del><ins>+ "READ_WRITE" integer not null,
+ primary key("DELEGATOR", "READ_WRITE", "DELEGATE")
</ins><span class="cx"> );
</span><span class="cx">
</span><span class="cx"> create table DELEGATE_GROUPS (
</span><span class="cx"> "DELEGATOR" nvarchar2(255),
</span><span class="cx"> "GROUP_ID" integer not null,
</span><span class="cx"> "READ_WRITE" integer not null,
</span><del>- "IS_EXTERNAL" integer not null
</del><ins>+ "IS_EXTERNAL" integer not null,
+ primary key("DELEGATOR", "READ_WRITE", "GROUP_ID")
</ins><span class="cx"> );
</span><span class="cx">
</span><span class="cx"> create table EXTERNAL_DELEGATE_GROUPS (
</span><del>- "DELEGATOR" nvarchar2(255),
</del><ins>+ "DELEGATOR" nvarchar2(255) primary key,
</ins><span class="cx"> "GROUP_UID_READ" nvarchar2(255),
</span><span class="cx"> "GROUP_UID_WRITE" nvarchar2(255)
</span><span class="cx"> );
</span><span class="lines">@@ -698,7 +700,7 @@
</span><span class="cx"> JOB_ID
</span><span class="cx"> );
</span><span class="cx">
</span><del>-create index GROUPS_GROUP_UID_ebf7a1d4 on GROUPS (
</del><ins>+create index GROUPS_GROUP_UID_b35cce23 on GROUPS (
</ins><span class="cx"> GROUP_UID
</span><span class="cx"> );
</span><span class="cx">
</span><span class="lines">@@ -710,6 +712,12 @@
</span><span class="cx"> MEMBER_UID
</span><span class="cx"> );
</span><span class="cx">
</span><ins>+create index DELEGATE_TO_DELEGATOR_5e149b11 on DELEGATES (
+ DELEGATE,
+ READ_WRITE,
+ DELEGATOR
+);
+
</ins><span class="cx"> create index CALENDAR_OBJECT_SPLIT_af71dcda on CALENDAR_OBJECT_SPLITTER_WORK (
</span><span class="cx"> RESOURCE_ID
</span><span class="cx"> );
</span><span class="lines">@@ -800,12 +808,12 @@
</span><span class="cx"> -- Extras
</span><span class="cx">
</span><span class="cx"> create or replace function next_job return integer is
</span><del>- cursor c1 is select ID from JOB for update skip locked;
</del><ins>+ cursor c1 is select JOB_ID from JOB for update skip locked;
</ins><span class="cx"> result integer;
</span><span class="cx"> begin
</span><span class="cx"> open c1;
</span><span class="cx"> fetch c1 into result;
</span><del>- select ID from JOB where ID = result for update;
</del><ins>+ select JOB_ID from JOB where ID = result for update;
</ins><span class="cx"> return result;
</span><span class="cx"> end;
</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 (13197 => 13198)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/common/datastore/sql_schema/current.sql        2014-04-08 16:31:32 UTC (rev 13197)
+++ CalendarServer/trunk/txdav/common/datastore/sql_schema/current.sql        2014-04-08 18:01:59 UTC (rev 13198)
</span><span class="lines">@@ -806,18 +806,24 @@
</span><span class="cx"> create table DELEGATES (
</span><span class="cx"> DELEGATOR varchar(255) not null,
</span><span class="cx"> DELEGATE varchar(255) not null,
</span><del>- READ_WRITE integer not null -- 1 = ReadWrite, 0 = ReadOnly
</del><ins>+ READ_WRITE integer not null, -- 1 = ReadWrite, 0 = ReadOnly
+
+ primary key (DELEGATOR, READ_WRITE, DELEGATE)
</ins><span class="cx"> );
</span><ins>+create index DELEGATE_TO_DELEGATOR on
+ DELEGATES(DELEGATE, READ_WRITE, DELEGATOR);
</ins><span class="cx">
</span><span class="cx"> create table DELEGATE_GROUPS (
</span><span class="cx"> DELEGATOR varchar(255) not null,
</span><span class="cx"> GROUP_ID integer not null,
</span><span class="cx"> READ_WRITE integer not null, -- 1 = ReadWrite, 0 = ReadOnly
</span><del>- IS_EXTERNAL integer not null -- 1 = ReadWrite, 0 = ReadOnly
</del><ins>+ IS_EXTERNAL integer not null, -- 1 = ReadWrite, 0 = ReadOnly
+
+ primary key (DELEGATOR, READ_WRITE, GROUP_ID)
</ins><span class="cx"> );
</span><span class="cx">
</span><span class="cx"> create table EXTERNAL_DELEGATE_GROUPS (
</span><del>- DELEGATOR varchar(255) not null,
</del><ins>+ DELEGATOR varchar(255) primary key not null,
</ins><span class="cx"> GROUP_UID_READ varchar(255),
</span><span class="cx"> GROUP_UID_WRITE varchar(255)
</span><span class="cx"> );
</span></span></pre></div>
<a id="CalendarServertrunktxdavcommondatastoresql_schemaupgradesoracledialectupgrade_from_34_to_35sql"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/common/datastore/sql_schema/upgrades/oracle-dialect/upgrade_from_34_to_35.sql (13197 => 13198)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/common/datastore/sql_schema/upgrades/oracle-dialect/upgrade_from_34_to_35.sql        2014-04-08 16:31:32 UTC (rev 13197)
+++ CalendarServer/trunk/txdav/common/datastore/sql_schema/upgrades/oracle-dialect/upgrade_from_34_to_35.sql        2014-04-08 18:01:59 UTC (rev 13198)
</span><span class="lines">@@ -55,24 +55,26 @@
</span><span class="cx"> create table DELEGATES (
</span><span class="cx"> "DELEGATOR" nvarchar2(255),
</span><span class="cx"> "DELEGATE" nvarchar2(255),
</span><del>- "READ_WRITE" integer not null
</del><ins>+ "READ_WRITE" integer not null,
+ primary key("DELEGATOR", "READ_WRITE", "DELEGATE")
</ins><span class="cx"> );
</span><span class="cx">
</span><span class="cx"> create table DELEGATE_GROUPS (
</span><span class="cx"> "DELEGATOR" nvarchar2(255),
</span><span class="cx"> "GROUP_ID" integer not null,
</span><span class="cx"> "READ_WRITE" integer not null,
</span><del>- "IS_EXTERNAL" integer not null
</del><ins>+ "IS_EXTERNAL" integer not null,
+ primary key("DELEGATOR", "READ_WRITE", "GROUP_ID")
</ins><span class="cx"> );
</span><span class="cx">
</span><span class="cx"> create table EXTERNAL_DELEGATE_GROUPS (
</span><del>- "DELEGATOR" nvarchar2(255),
</del><ins>+ "DELEGATOR" nvarchar2(255) primary key,
</ins><span class="cx"> "GROUP_UID_READ" nvarchar2(255),
</span><span class="cx"> "GROUP_UID_WRITE" nvarchar2(255)
</span><span class="cx"> );
</span><span class="cx">
</span><span class="cx">
</span><del>-create index GROUPS_GROUP_UID_ebf7a1d4 on GROUPS (
</del><ins>+create index GROUPS_GROUP_UID_b35cce23 on GROUPS (
</ins><span class="cx"> GROUP_UID
</span><span class="cx"> );
</span><span class="cx">
</span><span class="lines">@@ -84,7 +86,13 @@
</span><span class="cx"> MEMBER_UID
</span><span class="cx"> );
</span><span class="cx">
</span><ins>+create index DELEGATE_TO_DELEGATOR_5e149b11 on DELEGATES (
+ DELEGATE,
+ READ_WRITE,
+ DELEGATOR
+);
</ins><span class="cx">
</span><ins>+
</ins><span class="cx"> -- Now update the version
</span><span class="cx"> -- No data upgrades
</span><span class="cx"> update CALENDARSERVER set VALUE = '35' where NAME = 'VERSION';
</span></span></pre></div>
<a id="CalendarServertrunktxdavcommondatastoresql_schemaupgradespostgresdialectupgrade_from_34_to_35sql"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/common/datastore/sql_schema/upgrades/postgres-dialect/upgrade_from_34_to_35.sql (13197 => 13198)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/common/datastore/sql_schema/upgrades/postgres-dialect/upgrade_from_34_to_35.sql        2014-04-08 16:31:32 UTC (rev 13197)
+++ CalendarServer/trunk/txdav/common/datastore/sql_schema/upgrades/postgres-dialect/upgrade_from_34_to_35.sql        2014-04-08 18:01:59 UTC (rev 13198)
</span><span class="lines">@@ -38,7 +38,7 @@
</span><span class="cx"> create table GROUPS (
</span><span class="cx"> GROUP_ID integer primary key default nextval('RESOURCE_ID_SEQ'), -- implicit index
</span><span class="cx"> NAME varchar(255) not null,
</span><del>- GROUP_UID varchar(255) not null,
</del><ins>+ GROUP_UID varchar(255) not null,
</ins><span class="cx"> MEMBERSHIP_HASH varchar(255) not null,
</span><span class="cx"> EXTANT integer default 1,
</span><span class="cx"> CREATED timestamp default timezone('UTC', CURRENT_TIMESTAMP),
</span><span class="lines">@@ -48,7 +48,7 @@
</span><span class="cx">
</span><span class="cx"> create table GROUP_MEMBERSHIP (
</span><span class="cx"> GROUP_ID integer,
</span><del>- MEMBER_UID varchar(255) not null
</del><ins>+ MEMBER_UID varchar(255) not null
</ins><span class="cx"> );
</span><span class="cx"> create index GROUP_MEMBERSHIP_GROUP on GROUP_MEMBERSHIP(GROUP_ID);
</span><span class="cx"> create index GROUP_MEMBERSHIP_MEMBER on GROUP_MEMBERSHIP(MEMBER_UID);
</span><span class="lines">@@ -66,20 +66,27 @@
</span><span class="cx"> create table DELEGATES (
</span><span class="cx"> DELEGATOR varchar(255) not null,
</span><span class="cx"> DELEGATE varchar(255) not null,
</span><del>- READ_WRITE integer not null -- 1 = ReadWrite, 0 = ReadOnly
</del><ins>+ READ_WRITE integer not null, -- 1 = ReadWrite, 0 = ReadOnly
+
+ primary key (DELEGATOR, READ_WRITE, DELEGATE)
</ins><span class="cx"> );
</span><ins>+create index DELEGATE_TO_DELEGATOR on
+ DELEGATES(DELEGATE, READ_WRITE, DELEGATOR);
</ins><span class="cx">
</span><ins>+
</ins><span class="cx"> create table DELEGATE_GROUPS (
</span><span class="cx"> DELEGATOR varchar(255) not null,
</span><span class="cx"> GROUP_ID integer not null,
</span><span class="cx"> READ_WRITE integer not null, -- 1 = ReadWrite, 0 = ReadOnly
</span><del>- IS_EXTERNAL integer not null -- 1 = ReadWrite, 0 = ReadOnly
</del><ins>+ IS_EXTERNAL integer not null, -- 1 = ReadWrite, 0 = ReadOnly
+
+ primary key (DELEGATOR, READ_WRITE, GROUP_ID)
</ins><span class="cx"> );
</span><span class="cx">
</span><span class="cx"> create table EXTERNAL_DELEGATE_GROUPS (
</span><del>- DELEGATOR varchar(255) not null,
- GROUP_UID_READ varchar(255),
- GROUP_UID_WRITE varchar(255)
</del><ins>+ DELEGATOR varchar(255) primary key not null,
+ GROUP_UID_READ varchar(255),
+ GROUP_UID_WRITE varchar(255)
</ins><span class="cx"> );
</span><span class="cx">
</span><span class="cx"> -- Now update the version
</span></span></pre></div>
<a id="CalendarServertrunktxdavwhotesttest_delegatespy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/who/test/test_delegates.py (13197 => 13198)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/who/test/test_delegates.py        2014-04-08 16:31:32 UTC (rev 13197)
+++ CalendarServer/trunk/txdav/who/test/test_delegates.py        2014-04-08 18:01:59 UTC (rev 13198)
</span><span class="lines">@@ -39,7 +39,7 @@
</span><span class="cx">
</span><span class="cx"> @inlineCallbacks
</span><span class="cx"> def test_directDelegation(self):
</span><del>- txn = self.store.newTransaction()
</del><ins>+ txn = self.store.newTransaction(label="test_directDelegation")
</ins><span class="cx">
</span><span class="cx"> delegator = yield self.directory.recordWithUID(u"__wsanchez1__")
</span><span class="cx"> delegate1 = yield self.directory.recordWithUID(u"__sagen1__")
</span><span class="lines">@@ -53,7 +53,7 @@
</span><span class="cx"> self.assertEquals([u"__wsanchez1__"], [d.uid for d in delegators])
</span><span class="cx">
</span><span class="cx"> yield txn.commit() # So delegateService will see the changes
</span><del>- txn = self.store.newTransaction()
</del><ins>+ txn = self.store.newTransaction(label="test_directDelegation")
</ins><span class="cx">
</span><span class="cx"> # The "proxy-write" pseudoGroup will have one member
</span><span class="cx"> pseudoGroup = yield self.directory.recordWithShortName(
</span><span class="lines">@@ -130,7 +130,7 @@
</span><span class="cx"> yield pseudoGroup.setMembers([delegate1, delegate2])
</span><span class="cx">
</span><span class="cx"> # Verify the assignments were made
</span><del>- txn = self.store.newTransaction()
</del><ins>+ txn = self.store.newTransaction(label="test_directDelegation")
</ins><span class="cx"> delegates = (yield delegatesOf(txn, delegator, True))
</span><span class="cx"> self.assertEquals(
</span><span class="cx"> set([u"__sagen1__", u"__cdaboo1__"]),
</span><span class="lines">@@ -142,7 +142,7 @@
</span><span class="cx"> yield pseudoGroup.setMembers([delegate2])
</span><span class="cx">
</span><span class="cx"> # Verify the assignments were made
</span><del>- txn = self.store.newTransaction()
</del><ins>+ txn = self.store.newTransaction(label="test_directDelegation")
</ins><span class="cx"> delegates = (yield delegatesOf(txn, delegator, True))
</span><span class="cx"> self.assertEquals(
</span><span class="cx"> set([u"__cdaboo1__"]),
</span><span class="lines">@@ -153,7 +153,7 @@
</span><span class="cx">
</span><span class="cx"> @inlineCallbacks
</span><span class="cx"> def test_indirectDelegation(self):
</span><del>- txn = self.store.newTransaction()
</del><ins>+ txn = self.store.newTransaction(label="test_indirectDelegation")
</ins><span class="cx">
</span><span class="cx"> delegator = yield self.directory.recordWithUID(u"__wsanchez1__")
</span><span class="cx"> delegate1 = yield self.directory.recordWithUID(u"__sagen1__")
</span><span class="lines">@@ -233,3 +233,55 @@
</span><span class="cx"> set([d.uid for d in delegates])
</span><span class="cx"> )
</span><span class="cx"> yield txn.commit()
</span><ins>+
+
+ @inlineCallbacks
+ def test_noDuplication(self):
+ """
+ Make sure addDelegate( ) is idempotent
+ """
+ delegator = yield self.directory.recordWithUID(u"__wsanchez1__")
+
+ # Delegate users:
+ delegate1 = yield self.directory.recordWithUID(u"__sagen1__")
+
+ txn = self.store.newTransaction(label="test_noDuplication")
+ yield addDelegate(txn, delegator, delegate1, True)
+ yield txn.commit()
+
+ txn = self.store.newTransaction(label="test_noDuplication")
+ yield addDelegate(txn, delegator, delegate1, True)
+ yield txn.commit()
+
+ txn = self.store.newTransaction(label="test_noDuplication")
+ results = (
+ yield txn._selectDelegatesQuery.on(
+ txn,
+ delegator=delegator.uid.encode("utf-8"),
+ readWrite=1
+ )
+ )
+ yield txn.commit()
+ self.assertEquals([["__sagen1__"]], results)
+
+ # Delegate groups:
+ group1 = yield self.directory.recordWithUID(u"__top_group_1__")
+
+ txn = self.store.newTransaction(label="test_noDuplication")
+ yield addDelegate(txn, delegator, group1, True)
+ yield txn.commit()
+
+ txn = self.store.newTransaction(label="test_noDuplication")
+ yield addDelegate(txn, delegator, group1, True)
+ yield txn.commit()
+
+ txn = self.store.newTransaction(label="test_noDuplication")
+ results = (
+ yield txn._selectDelegateGroupsQuery.on(
+ txn,
+ delegator=delegator.uid.encode("utf-8"),
+ readWrite=1
+ )
+ )
+ yield txn.commit()
+ self.assertEquals([["__top_group_1__"]], results)
</ins></span></pre>
</div>
</div>
</body>
</html>