[CalendarServer-changes] [12798] CalendarServer/branches/release/CalendarServer-5.2-dev/txdav/common /datastore
source_changes at macosforge.org
source_changes at macosforge.org
Tue Mar 4 14:06:44 PST 2014
Revision: 12798
http://trac.calendarserver.org//changeset/12798
Author: cdaboo at apple.com
Date: 2014-03-04 14:06:44 -0800 (Tue, 04 Mar 2014)
Log Message:
-----------
Fix empty default alarms not set properly in an earlier upgrade.
Modified Paths:
--------------
CalendarServer/branches/release/CalendarServer-5.2-dev/txdav/common/datastore/sql_schema/current-oracle-dialect.sql
CalendarServer/branches/release/CalendarServer-5.2-dev/txdav/common/datastore/sql_schema/current.sql
Added Paths:
-----------
CalendarServer/branches/release/CalendarServer-5.2-dev/txdav/common/datastore/upgrade/sql/upgrades/calendar_upgrade_from_5_to_6.py
CalendarServer/branches/release/CalendarServer-5.2-dev/txdav/common/datastore/upgrade/sql/upgrades/test/test_upgrade_from_5_to_6.py
Modified: CalendarServer/branches/release/CalendarServer-5.2-dev/txdav/common/datastore/sql_schema/current-oracle-dialect.sql
===================================================================
--- CalendarServer/branches/release/CalendarServer-5.2-dev/txdav/common/datastore/sql_schema/current-oracle-dialect.sql 2014-03-04 21:57:49 UTC (rev 12797)
+++ CalendarServer/branches/release/CalendarServer-5.2-dev/txdav/common/datastore/sql_schema/current-oracle-dialect.sql 2014-03-04 22:06:44 UTC (rev 12798)
@@ -367,7 +367,7 @@
);
insert into CALENDARSERVER (NAME, VALUE) values ('VERSION', '28');
-insert into CALENDARSERVER (NAME, VALUE) values ('CALENDAR-DATAVERSION', '5');
+insert into CALENDARSERVER (NAME, VALUE) values ('CALENDAR-DATAVERSION', '6');
insert into CALENDARSERVER (NAME, VALUE) values ('ADDRESSBOOK-DATAVERSION', '2');
create index CALENDAR_HOME_METADAT_3cb9049e on CALENDAR_HOME_METADATA (
DEFAULT_EVENTS
Modified: CalendarServer/branches/release/CalendarServer-5.2-dev/txdav/common/datastore/sql_schema/current.sql
===================================================================
--- CalendarServer/branches/release/CalendarServer-5.2-dev/txdav/common/datastore/sql_schema/current.sql 2014-03-04 21:57:49 UTC (rev 12797)
+++ CalendarServer/branches/release/CalendarServer-5.2-dev/txdav/common/datastore/sql_schema/current.sql 2014-03-04 22:06:44 UTC (rev 12798)
@@ -700,5 +700,5 @@
);
insert into CALENDARSERVER values ('VERSION', '28');
-insert into CALENDARSERVER values ('CALENDAR-DATAVERSION', '5');
+insert into CALENDARSERVER values ('CALENDAR-DATAVERSION', '6');
insert into CALENDARSERVER values ('ADDRESSBOOK-DATAVERSION', '2');
Added: CalendarServer/branches/release/CalendarServer-5.2-dev/txdav/common/datastore/upgrade/sql/upgrades/calendar_upgrade_from_5_to_6.py
===================================================================
--- CalendarServer/branches/release/CalendarServer-5.2-dev/txdav/common/datastore/upgrade/sql/upgrades/calendar_upgrade_from_5_to_6.py (rev 0)
+++ CalendarServer/branches/release/CalendarServer-5.2-dev/txdav/common/datastore/upgrade/sql/upgrades/calendar_upgrade_from_5_to_6.py 2014-03-04 22:06:44 UTC (rev 12798)
@@ -0,0 +1,53 @@
+# -*- test-case-name: txdav.common.datastore.upgrade.sql.test -*-
+##
+# Copyright (c) 2011-2014 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.
+##
+
+from twext.enterprise.dal.syntax import Update
+
+from twisted.internet.defer import inlineCallbacks
+
+from txdav.common.datastore.sql_tables import schema, _BIND_MODE_OWN
+from txdav.common.datastore.upgrade.sql.upgrades.util import updateCalendarDataVersion, \
+ updateAllCalendarHomeDataVersions
+
+"""
+Data upgrade from database version 5 to 6
+"""
+
+UPGRADE_TO_VERSION = 6
+
+ at inlineCallbacks
+def doUpgrade(sqlStore):
+ """
+ Do the required upgrade steps.
+ """
+
+ sqlTxn = sqlStore.newTransaction()
+ cb = schema.CALENDAR_BIND
+ yield Update(
+ {
+ cb.ALARM_VEVENT_TIMED: "empty",
+ cb.ALARM_VEVENT_ALLDAY: "empty",
+ cb.ALARM_VTODO_TIMED: "empty",
+ cb.ALARM_VTODO_ALLDAY: "empty",
+ },
+ Where=(cb.BIND_MODE != _BIND_MODE_OWN)
+ ).on(sqlTxn)
+ yield sqlTxn.commit()
+
+ # Always bump the DB value
+ yield updateAllCalendarHomeDataVersions(sqlStore, UPGRADE_TO_VERSION)
+ yield updateCalendarDataVersion(sqlStore, UPGRADE_TO_VERSION)
Added: CalendarServer/branches/release/CalendarServer-5.2-dev/txdav/common/datastore/upgrade/sql/upgrades/test/test_upgrade_from_5_to_6.py
===================================================================
--- CalendarServer/branches/release/CalendarServer-5.2-dev/txdav/common/datastore/upgrade/sql/upgrades/test/test_upgrade_from_5_to_6.py (rev 0)
+++ CalendarServer/branches/release/CalendarServer-5.2-dev/txdav/common/datastore/upgrade/sql/upgrades/test/test_upgrade_from_5_to_6.py 2014-03-04 22:06:44 UTC (rev 12798)
@@ -0,0 +1,140 @@
+##
+# Copyright (c) 2010-2014 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.
+##
+
+"""
+Tests for L{txdav.common.datastore.upgrade.sql.upgrade}.
+"""
+
+from twisted.internet.defer import inlineCallbacks, returnValue
+
+from twext.enterprise.dal.syntax import Update
+
+from txdav.caldav.datastore.test.util import CommonStoreTests
+from txdav.common.datastore.sql_tables import _BIND_MODE_WRITE, _BIND_MODE_READ
+from txdav.common.datastore.upgrade.sql.upgrades.calendar_upgrade_from_5_to_6 import doUpgrade
+
+
+class Upgrade_from_5_to_6(CommonStoreTests):
+ """
+ Tests for L{DefaultCalendarPropertyUpgrade}.
+ """
+
+ @inlineCallbacks
+ def _upgrade_setup(self):
+
+ # Setup old properties
+ detailshome = (
+ (True, True, "boo",),
+ (True, False, "boo",),
+ (False, True, "boo",),
+ (False, False, "boo",),
+ )
+ detailscalendar = (
+ (True, True, "boo",),
+ (True, False, "boo",),
+ (False, True, "boo",),
+ (False, False, "boo",),
+ )
+ detailsshared = (
+ (True, True, "",),
+ (True, False, "boo",),
+ (False, True, "boo",),
+ (False, False, "",),
+ )
+
+ home = yield self.homeUnderTest(name="user01")
+ for vevent, timed, alarm in detailshome:
+ yield home.setDefaultAlarm(alarm, vevent, timed)
+
+ calendar = yield self.calendarUnderTest(name="calendar_1", home="user01")
+ for vevent, timed, alarm in detailscalendar:
+ yield calendar.setDefaultAlarm(alarm, vevent, timed)
+
+ home2 = yield self.homeUnderTest(name="user02")
+ shared_name2 = yield calendar.shareWith(home2, _BIND_MODE_WRITE)
+ shared = yield self.calendarUnderTest(name=shared_name2, home="user02")
+ for vevent, timed, alarm in detailsshared:
+ yield shared.setDefaultAlarm(alarm, vevent, timed)
+
+ home3 = yield self.homeUnderTest(name="user03")
+ shared_name3 = yield calendar.shareWith(home3, _BIND_MODE_READ)
+ shared = yield self.calendarUnderTest(name=shared_name3, home="user03")
+ for vevent, timed, alarm in detailsshared:
+ yield shared.setDefaultAlarm(alarm, vevent, timed)
+
+ for user in ("user01", "user02", "user03",):
+ # Force data version to previous
+ home = (yield self.homeUnderTest(name=user))
+ ch = home._homeSchema
+ yield Update(
+ {ch.DATAVERSION: 5},
+ Where=ch.RESOURCE_ID == home._resourceID,
+ ).on(self.transactionUnderTest())
+
+ yield self.commit()
+
+ # Re-adjust for empty changes
+ detailsshared = (
+ (True, True, "empty",),
+ (True, False, "empty",),
+ (False, True, "empty",),
+ (False, False, "empty",),
+ )
+
+ returnValue((detailshome, detailscalendar, detailsshared, shared_name2, shared_name3,))
+
+
+ @inlineCallbacks
+ def _upgrade_check(self, detailshome, detailscalendar, detailsshared, shared_name2, shared_name3):
+
+ # Check each type of collection
+ home = yield self.homeUnderTest(name="user01")
+ version = (yield home.dataVersion())
+ self.assertEqual(version, 6)
+ for vevent, timed, alarm in detailshome:
+ alarm_result = (yield home.getDefaultAlarm(vevent, timed))
+ self.assertEquals(alarm_result, alarm)
+
+ calendar = yield self.calendarUnderTest(name="calendar_1", home="user01")
+ for vevent, timed, alarm in detailscalendar:
+ alarm_result = (yield calendar.getDefaultAlarm(vevent, timed))
+ self.assertEquals(alarm_result, alarm)
+
+ home2 = (yield self.homeUnderTest(name="user02"))
+ version = (yield home2.dataVersion())
+ self.assertEqual(version, 6)
+ shared = yield self.calendarUnderTest(name=shared_name2, home="user02")
+ for vevent, timed, alarm in detailsshared:
+ alarm_result = (yield shared.getDefaultAlarm(vevent, timed))
+ self.assertEquals(alarm_result, alarm)
+
+ home3 = (yield self.homeUnderTest(name="user02"))
+ version = (yield home3.dataVersion())
+ self.assertEqual(version, 6)
+ shared = yield self.calendarUnderTest(name=shared_name3, home="user03")
+ for vevent, timed, alarm in detailsshared:
+ alarm_result = (yield shared.getDefaultAlarm(vevent, timed))
+ self.assertEquals(alarm_result, alarm)
+
+ version = yield self.transactionUnderTest().calendarserverValue("CALENDAR-DATAVERSION")
+ self.assertEqual(int(version), 6)
+
+
+ @inlineCallbacks
+ def test_defaultAlarmUpgrade(self):
+ detailshome, detailscalendar, detailsshared, shared_name2, shared_name3 = (yield self._upgrade_setup())
+ yield doUpgrade(self._sqlCalendarStore)
+ yield self._upgrade_check(detailshome, detailscalendar, detailsshared, shared_name2, shared_name3)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140304/0a79da4e/attachment-0001.html>
More information about the calendarserver-changes
mailing list