[CalendarServer-changes] [11531] CalendarServer/trunk

source_changes at macosforge.org source_changes at macosforge.org
Thu Jul 18 09:17:01 PDT 2013


Revision: 11531
          http://trac.calendarserver.org//changeset/11531
Author:   cdaboo at apple.com
Date:     2013-07-18 09:17:01 -0700 (Thu, 18 Jul 2013)
Log Message:
-----------
Add a unit test to make sure all columns that are references are also indexed.

Modified Paths:
--------------
    CalendarServer/trunk/twext/enterprise/dal/model.py
    CalendarServer/trunk/txdav/common/datastore/test/test_sql_schema_files.py
    CalendarServer/trunk/txdav/common/datastore/upgrade/sql/upgrade.py

Modified: CalendarServer/trunk/twext/enterprise/dal/model.py
===================================================================
--- CalendarServer/trunk/twext/enterprise/dal/model.py	2013-07-18 16:16:04 UTC (rev 11530)
+++ CalendarServer/trunk/twext/enterprise/dal/model.py	2013-07-18 16:17:01 UTC (rev 11531)
@@ -433,6 +433,9 @@
 
     def __init__(self, table, columns, unique=False):
         self.name = "%s%s:(%s)" % (table.name, "-unique" if unique else "", ",".join([col.name for col in columns]))
+        self.table = table
+        self.unique = unique
+        self.columns = columns
 
 
     def compare(self, other):

Modified: CalendarServer/trunk/txdav/common/datastore/test/test_sql_schema_files.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/test/test_sql_schema_files.py	2013-07-18 16:16:04 UTC (rev 11530)
+++ CalendarServer/trunk/txdav/common/datastore/test/test_sql_schema_files.py	2013-07-18 16:17:01 UTC (rev 11531)
@@ -118,3 +118,28 @@
         v5Schema = schemaFromPath(sqlSchema.child("old").child("postgres-dialect").child("v5.sql"))
         mismatched = v6Schema.compare(v5Schema)
         self.assertEqual(len(mismatched), 3, msg="\n".join(mismatched))
+
+
+    def test_references_index(self):
+        """
+        Make sure current-oracle-dialect.sql matches current.sql
+        """
+
+        schema = schemaFromPath(getModule(__name__).filePath.parent().sibling("sql_schema").child("current.sql"))
+
+        # Get index details
+        indexed_columns = set()
+        for index in schema.pseudoIndexes():
+            indexed_columns.add("%s.%s" % (index.table.name, index.columns[0].name,))
+        #print indexed_columns
+
+        # Look at each table
+        failures = []
+        for table in schema.tables:
+            for column in table.columns:
+                if column.references is not None:
+                    id = "%s.%s" % (table.name, column.name,)
+                    if id not in indexed_columns:
+                        failures.append(id)
+
+        self.assertEqual(len(failures), 0, msg="Missing index for references columns: %s" % (", ".join(sorted(failures))))

Modified: CalendarServer/trunk/txdav/common/datastore/upgrade/sql/upgrade.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/upgrade/sql/upgrade.py	2013-07-18 16:16:04 UTC (rev 11530)
+++ CalendarServer/trunk/txdav/common/datastore/upgrade/sql/upgrade.py	2013-07-18 16:17:01 UTC (rev 11531)
@@ -16,7 +16,7 @@
 ##
 
 """
-Utilities, mostly related to upgrading, common to calendar and addresbook
+Utilities, mostly related to upgrading, common to calendar and addressbook
 data stores.
 """
 
@@ -45,6 +45,7 @@
     def __init__(self, sqlStore):
         self.sqlStore = sqlStore
 
+
     @inlineCallbacks
     def stepWithResult(self, result):
         sqlTxn = self.sqlStore.newTransaction()
@@ -52,6 +53,7 @@
         yield sqlTxn.commit()
 
 
+
 class UpgradeReleaseLockStep(object):
     """
     A Step which releases the upgrade lock.
@@ -64,16 +66,19 @@
     def __init__(self, sqlStore):
         self.sqlStore = sqlStore
 
+
     @inlineCallbacks
     def stepWithResult(self, result):
         sqlTxn = self.sqlStore.newTransaction()
         yield sqlTxn.releaseUpgradeLock()
         yield sqlTxn.commit()
 
+
     def stepWithFailure(self, failure):
         return self.stepWithResult(None)
 
 
+
 class UpgradeDatabaseCoreStep(object):
     """
     Base class for either schema or data upgrades on the database.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20130718/f291ca95/attachment-0001.html>


More information about the calendarserver-changes mailing list