[CalendarServer-changes] [8260] CalendarServer/branches/users/cdaboo/component-set-fixes/txdav
source_changes at macosforge.org
source_changes at macosforge.org
Tue Nov 8 07:01:50 PST 2011
Revision: 8260
http://trac.macosforge.org/projects/calendarserver/changeset/8260
Author: cdaboo at apple.com
Date: 2011-11-08 07:01:48 -0800 (Tue, 08 Nov 2011)
Log Message:
-----------
Add separate data upgrade for calendar and address book homes. Make sure creation of a home sets its data version.
Modified Paths:
--------------
CalendarServer/branches/users/cdaboo/component-set-fixes/txdav/caldav/datastore/sql.py
CalendarServer/branches/users/cdaboo/component-set-fixes/txdav/caldav/datastore/test/test_sql.py
CalendarServer/branches/users/cdaboo/component-set-fixes/txdav/carddav/datastore/sql.py
CalendarServer/branches/users/cdaboo/component-set-fixes/txdav/carddav/datastore/test/test_sql.py
CalendarServer/branches/users/cdaboo/component-set-fixes/txdav/common/datastore/sql.py
CalendarServer/branches/users/cdaboo/component-set-fixes/txdav/common/datastore/sql_schema/current.sql
CalendarServer/branches/users/cdaboo/component-set-fixes/txdav/common/datastore/sql_schema/upgrades/oracle-dialect/upgrade_from_5_to_6.sql
CalendarServer/branches/users/cdaboo/component-set-fixes/txdav/common/datastore/sql_schema/upgrades/postgres-dialect/upgrade_from_5_to_6.sql
CalendarServer/branches/users/cdaboo/component-set-fixes/txdav/common/datastore/upgrade/sql/test/test_upgrade.py
CalendarServer/branches/users/cdaboo/component-set-fixes/txdav/common/datastore/upgrade/sql/upgrade.py
CalendarServer/branches/users/cdaboo/component-set-fixes/txdav/common/datastore/upgrade/sql/upgrades/upgrade_from_1_to_2.py
CalendarServer/branches/users/cdaboo/component-set-fixes/txdav/common/datastore/upgrade/sql/upgrades/util.py
Modified: CalendarServer/branches/users/cdaboo/component-set-fixes/txdav/caldav/datastore/sql.py
===================================================================
--- CalendarServer/branches/users/cdaboo/component-set-fixes/txdav/caldav/datastore/sql.py 2011-11-08 00:19:55 UTC (rev 8259)
+++ CalendarServer/branches/users/cdaboo/component-set-fixes/txdav/caldav/datastore/sql.py 2011-11-08 15:01:48 UTC (rev 8260)
@@ -102,6 +102,8 @@
_notifierPrefix = "CalDAV"
_revisionsTable = CALENDAR_OBJECT_REVISIONS_TABLE
+ _dataVersionKey = "CALENDAR-DATAVERSION"
+
_cacher = Memcacher("SQL.calhome", pickle=True, key_normalization=False)
def __init__(self, transaction, ownerUID, notifiers):
Modified: CalendarServer/branches/users/cdaboo/component-set-fixes/txdav/caldav/datastore/test/test_sql.py
===================================================================
--- CalendarServer/branches/users/cdaboo/component-set-fixes/txdav/caldav/datastore/test/test_sql.py 2011-11-08 00:19:55 UTC (rev 8259)
+++ CalendarServer/branches/users/cdaboo/component-set-fixes/txdav/caldav/datastore/test/test_sql.py 2011-11-08 15:01:48 UTC (rev 8260)
@@ -223,6 +223,28 @@
self.assertPropertiesSimilar(fromHome, toHome, builtinProperties)
+ def test_calendarHomeVersion(self):
+ """
+ The DATAVERSION column for new calendar homes must match the
+ CALENDAR-DATAVERSION value.
+ """
+
+ home = yield self.transactionUnderTest().calendarHomeWithUID("home_version")
+ self.assertTrue(home is not None)
+ yield self.transactionUnderTest().commit
+
+ txn = yield self.transactionUnderTest()
+ version = yield txn.calendarserverValue("CALENDAR-DATAVERSION")[0][0]
+ ch = schema.CALENDAR_HOME
+ homeVersion = yield Select(
+ [ch.DATAVERSION,],
+ From=ch,
+ Where=ch.OWNER_UID == "home_version",
+ ).on(txn)[0][0]
+ self.assertEqual(int(homeVersion, version))
+
+
+
def test_eachCalendarHome(self):
"""
L{ICalendarStore.eachCalendarHome} is currently stubbed out by
Modified: CalendarServer/branches/users/cdaboo/component-set-fixes/txdav/carddav/datastore/sql.py
===================================================================
--- CalendarServer/branches/users/cdaboo/component-set-fixes/txdav/carddav/datastore/sql.py 2011-11-08 00:19:55 UTC (rev 8259)
+++ CalendarServer/branches/users/cdaboo/component-set-fixes/txdav/carddav/datastore/sql.py 2011-11-08 15:01:48 UTC (rev 8260)
@@ -82,6 +82,8 @@
_notifierPrefix = "CardDAV"
_revisionsTable = ADDRESSBOOK_OBJECT_REVISIONS_TABLE
+ _dataVersionKey = "ADDRESSBOOK-DATAVERSION"
+
_cacher = Memcacher("SQL.adbkhome", pickle=True, key_normalization=False)
def __init__(self, transaction, ownerUID, notifiers):
Modified: CalendarServer/branches/users/cdaboo/component-set-fixes/txdav/carddav/datastore/test/test_sql.py
===================================================================
--- CalendarServer/branches/users/cdaboo/component-set-fixes/txdav/carddav/datastore/test/test_sql.py 2011-11-08 00:19:55 UTC (rev 8259)
+++ CalendarServer/branches/users/cdaboo/component-set-fixes/txdav/carddav/datastore/test/test_sql.py 2011-11-08 15:01:48 UTC (rev 8260)
@@ -201,6 +201,28 @@
self.assertPropertiesSimilar(fromHome, toHome, builtinProperties)
+ def test_addressBookHomeVersion(self):
+ """
+ The DATAVERSION column for new calendar homes must match the
+ ADDRESSBOOK-DATAVERSION value.
+ """
+
+ home = yield self.transactionUnderTest().addressbookHomeWithUID("home_version")
+ self.assertTrue(home is not None)
+ yield self.transactionUnderTest().commit
+
+ txn = yield self.transactionUnderTest()
+ version = yield txn.calendarserverValue("ADDRESSBOOK-DATAVERSION")[0][0]
+ ch = schema.ADDRESSBOOK_HOME
+ homeVersion = yield Select(
+ [ch.DATAVERSION,],
+ From=ch,
+ Where=ch.OWNER_UID == "home_version",
+ ).on(txn)[0][0]
+ self.assertEqual(int(homeVersion, version))
+
+
+
def test_eachAddressbookHome(self):
"""
L{IAddressbookStore.eachAddressbookHome} is currently stubbed out by
Modified: CalendarServer/branches/users/cdaboo/component-set-fixes/txdav/common/datastore/sql.py
===================================================================
--- CalendarServer/branches/users/cdaboo/component-set-fixes/txdav/common/datastore/sql.py 2011-11-08 00:19:55 UTC (rev 8259)
+++ CalendarServer/branches/users/cdaboo/component-set-fixes/txdav/common/datastore/sql.py 2011-11-08 15:01:48 UTC (rev 8260)
@@ -592,6 +592,9 @@
_revisionsTable = None
_notificationRevisionsTable = NOTIFICATION_OBJECT_REVISIONS_TABLE
+ _dataVersionKey = None
+ _dataVersionValue = None
+
_cacher = None # Initialize in derived classes
def __init__(self, transaction, ownerUID, notifiers):
@@ -674,9 +677,14 @@
savepoint = SavepointAction("homeWithUID")
yield savepoint.acquire(txn)
+ if cls._dataVersionValue is None:
+ cls._dataVersionValue = yield txn.calendarserverValue(cls._dataVersionKey)
try:
resourceid = (yield Insert(
- {cls._homeSchema.OWNER_UID: uid},
+ {
+ cls._homeSchema.OWNER_UID: uid,
+ cls._homeSchema.DATAVERSION: cls._dataVersionValue,
+ },
Return=cls._homeSchema.RESOURCE_ID).on(txn))[0][0]
yield Insert(
{cls._homeMetaDataSchema.RESOURCE_ID: resourceid}).on(txn)
Modified: CalendarServer/branches/users/cdaboo/component-set-fixes/txdav/common/datastore/sql_schema/current.sql
===================================================================
--- CalendarServer/branches/users/cdaboo/component-set-fixes/txdav/common/datastore/sql_schema/current.sql 2011-11-08 00:19:55 UTC (rev 8259)
+++ CalendarServer/branches/users/cdaboo/component-set-fixes/txdav/common/datastore/sql_schema/current.sql 2011-11-08 15:01:48 UTC (rev 8260)
@@ -314,7 +314,8 @@
create table ADDRESSBOOK_HOME (
RESOURCE_ID integer primary key default nextval('RESOURCE_ID_SEQ'), -- implicit index
- OWNER_UID varchar(255) not null unique -- implicit index
+ OWNER_UID varchar(255) not null unique, -- implicit index
+ DATAVERSION integer default 0 not null
);
--------------------------------
@@ -447,4 +448,5 @@
);
insert into CALENDARSERVER values ('VERSION', '6');
-insert into CALENDARSERVER values ('DATAVERSION', '2');
+insert into CALENDARSERVER values ('CALENDAR-DATAVERSION', '2');
+insert into CALENDARSERVER values ('ADDRESSBOOK-DATAVERSION', '1');
Modified: CalendarServer/branches/users/cdaboo/component-set-fixes/txdav/common/datastore/sql_schema/upgrades/oracle-dialect/upgrade_from_5_to_6.sql
===================================================================
--- CalendarServer/branches/users/cdaboo/component-set-fixes/txdav/common/datastore/sql_schema/upgrades/oracle-dialect/upgrade_from_5_to_6.sql 2011-11-08 00:19:55 UTC (rev 8259)
+++ CalendarServer/branches/users/cdaboo/component-set-fixes/txdav/common/datastore/sql_schema/upgrades/oracle-dialect/upgrade_from_5_to_6.sql 2011-11-08 15:01:48 UTC (rev 8260)
@@ -26,8 +26,13 @@
alter table CALENDAR_OBJECT
add ("SUPPORTED_COMPONENTS" nvarchar2(255) default null);
+-- Just need to add one column
+alter table ADDRESSBOOK_HOME
+ add ("DATAVERSION" integer default 1 null);
+
-- Now update the version
update CALENDARSERVER set VALUE = '6' where NAME = 'VERSION';
-- Also insert the initial data version which we will use in the data upgrade
-insert into CALENDARSERVER values ('DATAVERSION', '1');
+insert into CALENDARSERVER values ('CALENDAR-DATAVERSION', '1');
+insert into CALENDARSERVER values ('ADDRESSBOOK-DATAVERSION', '1');
Modified: CalendarServer/branches/users/cdaboo/component-set-fixes/txdav/common/datastore/sql_schema/upgrades/postgres-dialect/upgrade_from_5_to_6.sql
===================================================================
--- CalendarServer/branches/users/cdaboo/component-set-fixes/txdav/common/datastore/sql_schema/upgrades/postgres-dialect/upgrade_from_5_to_6.sql 2011-11-08 00:19:55 UTC (rev 8259)
+++ CalendarServer/branches/users/cdaboo/component-set-fixes/txdav/common/datastore/sql_schema/upgrades/postgres-dialect/upgrade_from_5_to_6.sql 2011-11-08 15:01:48 UTC (rev 8260)
@@ -26,8 +26,13 @@
alter table CALENDAR
add column SUPPORTED_COMPONENTS varchar(255) default null;
+-- Just need to add one column
+alter table ADDRESSBOOK_HOME
+ add column DATAVERSION integer default 1 null;
+
-- Now update the version
update CALENDARSERVER set VALUE = '6' where NAME = 'VERSION';
-- Also insert the initial data version which we will use in the data upgrade
-insert into CALENDARSERVER values ('DATAVERSION', '1');
+insert into CALENDARSERVER values ('CALENDAR-DATAVERSION', '1');
+insert into CALENDARSERVER values ('ADDRESSBOOK-DATAVERSION', '1');
Modified: CalendarServer/branches/users/cdaboo/component-set-fixes/txdav/common/datastore/upgrade/sql/test/test_upgrade.py
===================================================================
--- CalendarServer/branches/users/cdaboo/component-set-fixes/txdav/common/datastore/upgrade/sql/test/test_upgrade.py 2011-11-08 00:19:55 UTC (rev 8259)
+++ CalendarServer/branches/users/cdaboo/component-set-fixes/txdav/common/datastore/upgrade/sql/test/test_upgrade.py 2011-11-08 15:01:48 UTC (rev 8260)
@@ -13,7 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
##
-import types
"""
Tests for L{txdav.common.datastore.upgrade.sql.upgrade}.
@@ -186,9 +185,12 @@
@inlineCallbacks
def test_dbDataUpgrades(self):
"""
- This does a full DB test of all possible upgrade paths. For each old schema, it loads it into the DB
- then runs the upgrade service. This ensures all the upgrade.sql files work correctly - at least for
+ This does a full DB test of all possible data upgrade paths. For each old schema, it loads it into the DB
+ then runs the data upgrade service. This ensures all the upgrade_XX.py files work correctly - at least for
postgres.
+
+ TODO: this currently does not create any calendar data to test with. It simply runs the upgrade on an empty
+ store.
"""
store = yield theStoreBuilder.buildStore(
@@ -205,13 +207,13 @@
yield startTxn.execSQL("create schema test_dbUpgrades;")
yield startTxn.execSQL("set search_path to test_dbUpgrades;")
yield startTxn.execSQL(path.getContent())
- yield startTxn.execSQL("update CALENDARSERVER set VALUE = '%s' where NAME = 'DATAVERSION';" % (oldVersion,))
+ yield startTxn.execSQL("update CALENDARSERVER set VALUE = '%s' where NAME = 'CALENDAR-DATAVERSION';" % (oldVersion,))
yield startTxn.commit()
@inlineCallbacks
def _loadVersion():
startTxn = store.newTransaction("test_dbUpgrades")
- new_version = yield startTxn.execSQL("select value from calendarserver where name = 'DATAVERSION';")
+ new_version = yield startTxn.execSQL("select value from calendarserver where name = 'CALENDAR-DATAVERSION';")
yield startTxn.commit()
returnValue(int(new_version[0][0]))
@@ -232,10 +234,10 @@
self.addCleanup(_cleanupOldData)
test_upgrader = UpgradeDatabaseSchemaService(None, None)
- expected_version = self._getSchemaVersion(test_upgrader.schemaLocation.child("current.sql"), "DATAVERSION")
+ expected_version = self._getSchemaVersion(test_upgrader.schemaLocation.child("current.sql"), "CALENDAR-DATAVERSION")
versions = set()
for child in test_upgrader.schemaLocation.child("old").globChildren("*.sql"):
- versions.add(self._getSchemaVersion(child, "DATAVERSION"))
+ versions.add(self._getSchemaVersion(child, "CALENDAR-DATAVERSION"))
for oldVersion in sorted(versions):
upgrader = UpgradeDatabaseDataService(store, None)
Modified: CalendarServer/branches/users/cdaboo/component-set-fixes/txdav/common/datastore/upgrade/sql/upgrade.py
===================================================================
--- CalendarServer/branches/users/cdaboo/component-set-fixes/txdav/common/datastore/upgrade/sql/upgrade.py 2011-11-08 00:19:55 UTC (rev 8259)
+++ CalendarServer/branches/users/cdaboo/component-set-fixes/txdav/common/datastore/upgrade/sql/upgrade.py 2011-11-08 15:01:48 UTC (rev 8260)
@@ -283,7 +283,7 @@
"""
super(UpgradeDatabaseDataService, self).__init__(sqlStore, service, uid, gid)
- self.versionKey = "DATAVERSION"
+ self.versionKey = "CALENDAR-DATAVERSION"
self.versionDescriptor = "data"
self.upgradeFileSuffix = ".py"
Modified: CalendarServer/branches/users/cdaboo/component-set-fixes/txdav/common/datastore/upgrade/sql/upgrades/upgrade_from_1_to_2.py
===================================================================
--- CalendarServer/branches/users/cdaboo/component-set-fixes/txdav/common/datastore/upgrade/sql/upgrades/upgrade_from_1_to_2.py 2011-11-08 00:19:55 UTC (rev 8259)
+++ CalendarServer/branches/users/cdaboo/component-set-fixes/txdav/common/datastore/upgrade/sql/upgrades/upgrade_from_1_to_2.py 2011-11-08 15:01:48 UTC (rev 8260)
@@ -38,7 +38,7 @@
yield splitCalendars(sqlStore)
# Always bump the DB value
- yield updateDataVersion(sqlStore, UPGRADE_TO_VERSION)
+ yield updateDataVersion(sqlStore, "CALENDAR-DATAVERSION", UPGRADE_TO_VERSION)
@inlineCallbacks
def moveSupportedComponentSetProperties(sqlStore):
Modified: CalendarServer/branches/users/cdaboo/component-set-fixes/txdav/common/datastore/upgrade/sql/upgrades/util.py
===================================================================
--- CalendarServer/branches/users/cdaboo/component-set-fixes/txdav/common/datastore/upgrade/sql/upgrades/util.py 2011-11-08 00:19:55 UTC (rev 8259)
+++ CalendarServer/branches/users/cdaboo/component-set-fixes/txdav/common/datastore/upgrade/sql/upgrades/util.py 2011-11-08 15:01:48 UTC (rev 8260)
@@ -43,16 +43,22 @@
).on(txn)
@inlineCallbacks
-def updateDataVersion(store, version):
+def updateDataVersion(store, key, version):
txn = store.newTransaction("updateDataVersion")
cs = schema.CALENDARSERVER
yield Update(
{cs.VALUE: version},
- Where=cs.NAME == "DATAVERSION",
+ Where=cs.NAME == key,
).on(txn)
yield txn.commit()
+def updateCalendarDataVersion(store, version):
+ return updateDataVersion(store, "CALENDAR-DATAVERSION", version)
+
+def updateAddressBookDataVersion(store, version):
+ return updateDataVersion(store, "ADDRESSBOOK-DATAVERSION", version)
+
@inlineCallbacks
def doToEachCalendarHomeNotAtVersion(store, version, doIt):
"""
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20111108/76c417bd/attachment-0001.html>
More information about the calendarserver-changes
mailing list