[CalendarServer-changes] [15006] CalendarServer/trunk/txdav/common/datastore

source_changes at macosforge.org source_changes at macosforge.org
Mon Jul 27 17:51:26 PDT 2015


Revision: 15006
          http://trac.calendarserver.org//changeset/15006
Author:   sagen at apple.com
Date:     2015-07-27 17:51:26 -0700 (Mon, 27 Jul 2015)
Log Message:
-----------
Convert old-style (urn:uuid:) CUAs to new-style (urn:x-uid:) in the imip_tokens table.

Modified Paths:
--------------
    CalendarServer/trunk/txdav/common/datastore/sql_schema/current.sql
    CalendarServer/trunk/txdav/common/datastore/upgrade/sql/test/test_upgrade_with_data.py

Added Paths:
-----------
    CalendarServer/trunk/txdav/common/datastore/sql_schema/upgrades/oracle-dialect/upgrade_from_56_to_57.sql
    CalendarServer/trunk/txdav/common/datastore/sql_schema/upgrades/postgres-dialect/upgrade_from_56_to_57.sql

Modified: CalendarServer/trunk/txdav/common/datastore/sql_schema/current.sql
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/sql_schema/current.sql	2015-07-27 19:39:05 UTC (rev 15005)
+++ CalendarServer/trunk/txdav/common/datastore/sql_schema/current.sql	2015-07-28 00:51:26 UTC (rev 15006)
@@ -1282,7 +1282,7 @@
   VALUE                         varchar(255)
 );
 
-insert into CALENDARSERVER values ('VERSION', '56');
+insert into CALENDARSERVER values ('VERSION', '57');
 insert into CALENDARSERVER values ('CALENDAR-DATAVERSION', '6');
 insert into CALENDARSERVER values ('ADDRESSBOOK-DATAVERSION', '2');
 insert into CALENDARSERVER values ('NOTIFICATION-DATAVERSION', '1');

Added: CalendarServer/trunk/txdav/common/datastore/sql_schema/upgrades/oracle-dialect/upgrade_from_56_to_57.sql
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/sql_schema/upgrades/oracle-dialect/upgrade_from_56_to_57.sql	                        (rev 0)
+++ CalendarServer/trunk/txdav/common/datastore/sql_schema/upgrades/oracle-dialect/upgrade_from_56_to_57.sql	2015-07-28 00:51:26 UTC (rev 15006)
@@ -0,0 +1,28 @@
+----
+-- Copyright (c) 2012-2015 Apple Inc. All rights reserved.
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- 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 "AS IS" 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 56 to 57 --
+---------------------------------------------------
+
+-- pre-delete any that would conflict during the update
+delete from IMIP_TOKENS where (ORGANIZER, ATTENDEE, ICALUID) in (select concat('urn:uuid:', substr(ORGANIZER, 11)), ATTENDEE, ICALUID from IMIP_TOKENS where substr(ORGANIZER, 1, 10) = 'urn:x-uid:');
+
+-- convert the old-style urn:uuid: CUAs to new style urn:x-uid:
+update IMIP_TOKENS set ORGANIZER = concat('urn:x-uid:', substr(ORGANIZER, 10)) where substr(ORGANIZER, 1, 9) = 'urn:uuid:';
+
+-- update the version
+update CALENDARSERVER set VALUE = '57' where NAME = 'VERSION';

Added: CalendarServer/trunk/txdav/common/datastore/sql_schema/upgrades/postgres-dialect/upgrade_from_56_to_57.sql
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/sql_schema/upgrades/postgres-dialect/upgrade_from_56_to_57.sql	                        (rev 0)
+++ CalendarServer/trunk/txdav/common/datastore/sql_schema/upgrades/postgres-dialect/upgrade_from_56_to_57.sql	2015-07-28 00:51:26 UTC (rev 15006)
@@ -0,0 +1,25 @@
+----
+-- Copyright (c) 2012-2015 Apple Inc. All rights reserved.
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- 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 "AS IS" 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 56 to 57 --
+---------------------------------------------------
+
+delete from IMIP_TOKENS where (ORGANIZER, ATTENDEE, ICALUID) in (select concat('urn:uuid:', substr(ORGANIZER, 11)), ATTENDEE, ICALUID from IMIP_TOKENS where substr(ORGANIZER, 1, 10) = 'urn:x-uid:');
+update IMIP_TOKENS set ORGANIZER = concat('urn:x-uid:', substr(ORGANIZER, 10)) where substr(ORGANIZER, 1, 9) = 'urn:uuid:';
+
+-- update the version
+update CALENDARSERVER set VALUE = '57' where NAME = 'VERSION';

Modified: CalendarServer/trunk/txdav/common/datastore/upgrade/sql/test/test_upgrade_with_data.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/upgrade/sql/test/test_upgrade_with_data.py	2015-07-27 19:39:05 UTC (rev 15005)
+++ CalendarServer/trunk/txdav/common/datastore/upgrade/sql/test/test_upgrade_with_data.py	2015-07-28 00:51:26 UTC (rev 15006)
@@ -298,3 +298,45 @@
         self.assertEqual(workers[0].workType, "SCHEDULE_REPLY_WORK")
 
         yield txn.commit()
+
+
+    @inlineCallbacks
+    def test_upgrade_imipTokens(self):
+        """
+        Old-style canonical CUAs (urn:uuid:) are converted to new style (urn:x-uid:)
+        """
+        schema = yield self._loadOldSchema(self.upgradePath.child("v56.sql"))
+
+        txn = self.store.newTransaction("loadData")
+
+        # Add two tokens records crafted to simulate conflicting old-style and
+        # new style CUAs -- the result should be only the new-style copy.
+        yield Insert(
+            {
+                schema.IMIP_TOKENS.TOKEN: "123",
+                schema.IMIP_TOKENS.ORGANIZER: "urn:uuid:PLUGH",
+                schema.IMIP_TOKENS.ATTENDEE: "mailto:user at example.com",
+                schema.IMIP_TOKENS.ICALUID: "XYZZY",
+            }
+        ).on(txn)
+        yield Insert(
+            {
+                schema.IMIP_TOKENS.TOKEN: "456",
+                schema.IMIP_TOKENS.ORGANIZER: "urn:x-uid:PLUGH",
+                schema.IMIP_TOKENS.ATTENDEE: "mailto:user at example.com",
+                schema.IMIP_TOKENS.ICALUID: "XYZZY",
+            }
+        ).on(txn)
+
+        yield txn.commit()
+        upgrader = UpgradeDatabaseSchemaStep(self.store)
+        yield upgrader.databaseUpgrade()
+
+        txn = self.store.newTransaction("loadData")
+        tokens = yield Select(
+            From=schema.IMIP_TOKENS,
+        ).on(txn)
+
+        self.assertEqual(len(tokens), 1)
+        self.assertEqual(list(tokens[0])[1], "urn:x-uid:PLUGH")
+        yield txn.commit()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20150727/c5e85a47/attachment-0001.html>


More information about the calendarserver-changes mailing list