[CalendarServer-changes] [11106] CalendarServer/branches/users/gaya/sharedgroups-3/txdav/common/ datastore
source_changes at macosforge.org
source_changes at macosforge.org
Fri Apr 26 13:01:06 PDT 2013
Revision: 11106
http://trac.calendarserver.org//changeset/11106
Author: gaya at apple.com
Date: 2013-04-26 13:01:06 -0700 (Fri, 26 Apr 2013)
Log Message:
-----------
fix txdav.common.datastore.upgrade.sql.test.test_upgrade.SchemaUpgradeTests
Modified Paths:
--------------
CalendarServer/branches/users/gaya/sharedgroups-3/txdav/common/datastore/sql_schema/upgrades/postgres-dialect/upgrade_from_18_to_19.sql
CalendarServer/branches/users/gaya/sharedgroups-3/txdav/common/datastore/upgrade/sql/test/test_upgrade.py
CalendarServer/branches/users/gaya/sharedgroups-3/txdav/common/datastore/upgrade/sql/upgrade.py
CalendarServer/branches/users/gaya/sharedgroups-3/txdav/common/datastore/upgrade/sql/upgrades/addressbook_upgrade_from_1_to_2.py
CalendarServer/branches/users/gaya/sharedgroups-3/txdav/common/datastore/upgrade/sql/upgrades/calendar_upgrade_from_1_to_2.py
CalendarServer/branches/users/gaya/sharedgroups-3/txdav/common/datastore/upgrade/sql/upgrades/calendar_upgrade_from_2_to_3.py
CalendarServer/branches/users/gaya/sharedgroups-3/txdav/common/datastore/upgrade/sql/upgrades/util.py
Added Paths:
-----------
CalendarServer/branches/users/gaya/sharedgroups-3/txdav/common/datastore/sql_schema/upgrades/oracle-dialect/upgrade_from_18_to_19.sql
Added: CalendarServer/branches/users/gaya/sharedgroups-3/txdav/common/datastore/sql_schema/upgrades/oracle-dialect/upgrade_from_18_to_19.sql
===================================================================
--- CalendarServer/branches/users/gaya/sharedgroups-3/txdav/common/datastore/sql_schema/upgrades/oracle-dialect/upgrade_from_18_to_19.sql (rev 0)
+++ CalendarServer/branches/users/gaya/sharedgroups-3/txdav/common/datastore/sql_schema/upgrades/oracle-dialect/upgrade_from_18_to_19.sql 2013-04-26 20:01:06 UTC (rev 11106)
@@ -0,0 +1,22 @@
+----
+-- Copyright (c) 2011-2013 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 18 to 19 --
+---------------------------------------------------
+
+-- Now update the version
+update CALENDARSERVER set VALUE = '19' where NAME = 'VERSION';
Modified: CalendarServer/branches/users/gaya/sharedgroups-3/txdav/common/datastore/sql_schema/upgrades/postgres-dialect/upgrade_from_18_to_19.sql
===================================================================
--- CalendarServer/branches/users/gaya/sharedgroups-3/txdav/common/datastore/sql_schema/upgrades/postgres-dialect/upgrade_from_18_to_19.sql 2013-04-26 18:34:47 UTC (rev 11105)
+++ CalendarServer/branches/users/gaya/sharedgroups-3/txdav/common/datastore/sql_schema/upgrades/postgres-dialect/upgrade_from_18_to_19.sql 2013-04-26 20:01:06 UTC (rev 11106)
@@ -21,5 +21,4 @@
-- Now update the version
--- FIXME: Do nothing now!
-update CALENDARSERVER set VALUE = '18' where NAME = 'VERSION';
+update CALENDARSERVER set VALUE = '19' where NAME = 'VERSION';
Modified: CalendarServer/branches/users/gaya/sharedgroups-3/txdav/common/datastore/upgrade/sql/test/test_upgrade.py
===================================================================
--- CalendarServer/branches/users/gaya/sharedgroups-3/txdav/common/datastore/upgrade/sql/test/test_upgrade.py 2013-04-26 18:34:47 UTC (rev 11105)
+++ CalendarServer/branches/users/gaya/sharedgroups-3/txdav/common/datastore/upgrade/sql/test/test_upgrade.py 2013-04-26 20:01:06 UTC (rev 11106)
@@ -1,4 +1,4 @@
-##
+# #
# Copyright (c) 2010-2013 Apple Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -12,7 +12,7 @@
# 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}.
@@ -24,7 +24,7 @@
from twisted.trial.unittest import TestCase
from txdav.common.datastore.test.util import theStoreBuilder, StubNotifierFactory
from txdav.common.datastore.upgrade.sql.upgrade import UpgradeDatabaseSchemaService, \
- UpgradeDatabaseDataService
+ UpgradeDatabaseCalendarDataService, UpgradeDatabaseAddressBookDataService
import re
class SchemaUpgradeTests(TestCase):
@@ -207,7 +207,7 @@
@inlineCallbacks
- def test_dbDataUpgrades(self):
+ def test_dbCalendarDataUpgrades(self):
"""
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
@@ -264,10 +264,78 @@
versions.add(self._getSchemaVersion(child, "CALENDAR-DATAVERSION"))
for oldVersion in sorted(versions):
- upgrader = UpgradeDatabaseDataService(store, None)
+ upgrader = UpgradeDatabaseCalendarDataService(store, None)
yield _loadOldData(test_upgrader.schemaLocation.child("current.sql"), oldVersion)
yield upgrader.databaseUpgrade()
new_version = yield _loadVersion()
yield _unloadOldData()
self.assertEqual(new_version, expected_version)
+
+
+ @inlineCallbacks
+ def test_dbAddressBookDataUpgrades(self):
+ """
+ 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(
+ self, StubNotifierFactory()
+ )
+
+ @inlineCallbacks
+ def _loadOldData(path, oldVersion):
+ """
+ Use the postgres schema mechanism to do tests under a separate "namespace"
+ in postgres that we can quickly wipe clean afterwards.
+ """
+ startTxn = store.newTransaction("test_dbUpgrades")
+ 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 = 'ADDRESSBOOK-DATAVERSION';" % (oldVersion,))
+ yield startTxn.commit()
+
+ @inlineCallbacks
+ def _loadVersion():
+ startTxn = store.newTransaction("test_dbUpgrades")
+ new_version = yield startTxn.execSQL("select value from calendarserver where name = 'ADDRESSBOOK-DATAVERSION';")
+ yield startTxn.commit()
+ returnValue(int(new_version[0][0]))
+
+ @inlineCallbacks
+ def _unloadOldData():
+ startTxn = store.newTransaction("test_dbUpgrades")
+ yield startTxn.execSQL("set search_path to public;")
+ yield startTxn.execSQL("drop schema test_dbUpgrades cascade;")
+ yield startTxn.commit()
+
+ @inlineCallbacks
+ def _cleanupOldData():
+ startTxn = store.newTransaction("test_dbUpgrades")
+ yield startTxn.execSQL("set search_path to public;")
+ yield startTxn.execSQL("drop schema if exists test_dbUpgrades cascade;")
+ yield startTxn.commit()
+
+ self.addCleanup(_cleanupOldData)
+
+ test_upgrader = UpgradeDatabaseSchemaService(None, None)
+ expected_version = self._getSchemaVersion(test_upgrader.schemaLocation.child("current.sql"), "ADDRESSBOOK-DATAVERSION")
+ versions = set()
+ for child in test_upgrader.schemaLocation.child("old").child(POSTGRES_DIALECT).globChildren("*.sql"):
+ versions.add(self._getSchemaVersion(child, "ADDRESSBOOK-DATAVERSION"))
+
+ for oldVersion in sorted(versions):
+ upgrader = UpgradeDatabaseAddressBookDataService(store, None)
+ yield _loadOldData(test_upgrader.schemaLocation.child("current.sql"), oldVersion)
+ yield upgrader.databaseUpgrade()
+ new_version = yield _loadVersion()
+ yield _unloadOldData()
+
+ self.assertEqual(new_version, expected_version)
+
Modified: CalendarServer/branches/users/gaya/sharedgroups-3/txdav/common/datastore/upgrade/sql/upgrade.py
===================================================================
--- CalendarServer/branches/users/gaya/sharedgroups-3/txdav/common/datastore/upgrade/sql/upgrade.py 2013-04-26 18:34:47 UTC (rev 11105)
+++ CalendarServer/branches/users/gaya/sharedgroups-3/txdav/common/datastore/upgrade/sql/upgrade.py 2013-04-26 20:01:06 UTC (rev 11106)
@@ -316,7 +316,7 @@
-class UpgradeDatabaseDataService(UpgradeDatabaseCoreService):
+class _UpgradeDatabaseDataService(UpgradeDatabaseCoreService):
"""
Checks and upgrades the database data. This assumes there are a bunch of
upgrade python modules that we can execute against the database to
@@ -345,7 +345,6 @@
Apply the data upgrade .py files to the database.
"""
-
# Find the module function we need to execute
try:
module = getModule(__name__)
@@ -361,7 +360,7 @@
-class UpgradeDatabaseCalendarDataService(UpgradeDatabaseDataService):
+class UpgradeDatabaseCalendarDataService(_UpgradeDatabaseDataService):
"""
Checks and upgrades the database data. This assumes there are a bunch of
upgrade python modules that we can execute against the database to
@@ -395,7 +394,7 @@
-class UpgradeDatabaseAddressBookDataService(UpgradeDatabaseDataService):
+class UpgradeDatabaseAddressBookDataService(_UpgradeDatabaseDataService):
"""
Checks and upgrades the database data. This assumes there are a bunch of
upgrade python modules that we can execute against the database to
Modified: CalendarServer/branches/users/gaya/sharedgroups-3/txdav/common/datastore/upgrade/sql/upgrades/addressbook_upgrade_from_1_to_2.py
===================================================================
--- CalendarServer/branches/users/gaya/sharedgroups-3/txdav/common/datastore/upgrade/sql/upgrades/addressbook_upgrade_from_1_to_2.py 2013-04-26 18:34:47 UTC (rev 11105)
+++ CalendarServer/branches/users/gaya/sharedgroups-3/txdav/common/datastore/upgrade/sql/upgrades/addressbook_upgrade_from_1_to_2.py 2013-04-26 20:01:06 UTC (rev 11106)
@@ -30,6 +30,5 @@
Do the required upgrade steps.
"""
- # FIXME: do nothing for now!
- # Always bump the DB value
- yield updateAddressBookDataVersion(sqlStore, UPGRADE_TO_VERSION - 1)
+ # bump data version
+ yield updateAddressBookDataVersion(sqlStore, UPGRADE_TO_VERSION)
Modified: CalendarServer/branches/users/gaya/sharedgroups-3/txdav/common/datastore/upgrade/sql/upgrades/calendar_upgrade_from_1_to_2.py
===================================================================
--- CalendarServer/branches/users/gaya/sharedgroups-3/txdav/common/datastore/upgrade/sql/upgrades/calendar_upgrade_from_1_to_2.py 2013-04-26 18:34:47 UTC (rev 11105)
+++ CalendarServer/branches/users/gaya/sharedgroups-3/txdav/common/datastore/upgrade/sql/upgrades/calendar_upgrade_from_1_to_2.py 2013-04-26 20:01:06 UTC (rev 11106)
@@ -21,7 +21,7 @@
from twistedcaldav import caldavxml
from txdav.common.datastore.sql_tables import schema
from txdav.common.datastore.upgrade.sql.upgrades.util import rowsForProperty,\
- removeProperty, updateDataVersion, doToEachCalendarHomeNotAtVersion
+ removeProperty, updateCalendarDataVersion, doToEachHomeNotAtVersion
"""
Data upgrade from database version 1 to 2
@@ -38,7 +38,7 @@
yield splitCalendars(sqlStore)
# Always bump the DB value
- yield updateDataVersion(sqlStore, "CALENDAR-DATAVERSION", UPGRADE_TO_VERSION)
+ yield updateCalendarDataVersion(sqlStore, UPGRADE_TO_VERSION)
@@ -86,4 +86,4 @@
yield home.splitCalendars()
# Do this to each calendar home not already at version 2
- yield doToEachCalendarHomeNotAtVersion(sqlStore, schema.CALENDAR_HOME, UPGRADE_TO_VERSION, doIt)
+ yield doToEachHomeNotAtVersion(sqlStore, schema.CALENDAR_HOME, UPGRADE_TO_VERSION, doIt)
Modified: CalendarServer/branches/users/gaya/sharedgroups-3/txdav/common/datastore/upgrade/sql/upgrades/calendar_upgrade_from_2_to_3.py
===================================================================
--- CalendarServer/branches/users/gaya/sharedgroups-3/txdav/common/datastore/upgrade/sql/upgrades/calendar_upgrade_from_2_to_3.py 2013-04-26 18:34:47 UTC (rev 11105)
+++ CalendarServer/branches/users/gaya/sharedgroups-3/txdav/common/datastore/upgrade/sql/upgrades/calendar_upgrade_from_2_to_3.py 2013-04-26 20:01:06 UTC (rev 11106)
@@ -23,7 +23,7 @@
from txdav.common.datastore.sql import fixUUIDNormalization
from twisted.internet.defer import inlineCallbacks
-from txdav.common.datastore.upgrade.sql.upgrades.util import updateDataVersion
+from txdav.common.datastore.upgrade.sql.upgrades.util import updateCalendarDataVersion
UPGRADE_TO_VERSION = 3
@@ -36,7 +36,7 @@
yield fixUUIDNormalization(sqlStore)
# Always bump the DB value
- yield updateDataVersion(
- sqlStore, "CALENDAR-DATAVERSION", UPGRADE_TO_VERSION
+ yield updateCalendarDataVersion(
+ sqlStore, UPGRADE_TO_VERSION
)
Modified: CalendarServer/branches/users/gaya/sharedgroups-3/txdav/common/datastore/upgrade/sql/upgrades/util.py
===================================================================
--- CalendarServer/branches/users/gaya/sharedgroups-3/txdav/common/datastore/upgrade/sql/upgrades/util.py 2013-04-26 18:34:47 UTC (rev 11105)
+++ CalendarServer/branches/users/gaya/sharedgroups-3/txdav/common/datastore/upgrade/sql/upgrades/util.py 2013-04-26 20:01:06 UTC (rev 11106)
@@ -43,9 +43,9 @@
).on(txn)
@inlineCallbacks
-def updateDataVersion(store, key, version):
+def _updateDataVersion(store, key, version):
- txn = store.newTransaction("updateDataVersion")
+ txn = store.newTransaction("update " + key)
cs = schema.CALENDARSERVER
yield Update(
{cs.VALUE: version},
@@ -54,13 +54,13 @@
yield txn.commit()
def updateCalendarDataVersion(store, version):
- return updateDataVersion(store, "CALENDAR-DATAVERSION", version)
+ return _updateDataVersion(store, "CALENDAR-DATAVERSION", version)
def updateAddressBookDataVersion(store, version):
- return updateDataVersion(store, "ADDRESSBOOK-DATAVERSION", version)
+ return _updateDataVersion(store, "ADDRESSBOOK-DATAVERSION", version)
@inlineCallbacks
-def doToEachCalendarHomeNotAtVersion(store, homeSchema, version, doIt):
+def doToEachHomeNotAtVersion(store, homeSchema, version, doIt):
"""
Do something to each home whose version column indicates it is older
than the specified version. Do this in batches as there may be a lot of work to do.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20130426/4bfa7461/attachment-0001.html>
More information about the calendarserver-changes
mailing list