[CalendarServer-changes] [10242] CalendarServer/branches/users/glyph/queue-locking-and-timing

source_changes at macosforge.org source_changes at macosforge.org
Fri Jan 4 16:38:58 PST 2013


Revision: 10242
          http://trac.calendarserver.org//changeset/10242
Author:   glyph at apple.com
Date:     2013-01-04 16:38:58 -0800 (Fri, 04 Jan 2013)
Log Message:
-----------
As per TODO comment, automate discovery of tables that need to be cleared from parsed schema.

Modified Paths:
--------------
    CalendarServer/branches/users/glyph/queue-locking-and-timing/txdav/common/datastore/test/util.py

Property Changed:
----------------
    CalendarServer/branches/users/glyph/queue-locking-and-timing/

Modified: CalendarServer/branches/users/glyph/queue-locking-and-timing/txdav/common/datastore/test/util.py
===================================================================
--- CalendarServer/branches/users/glyph/queue-locking-and-timing/txdav/common/datastore/test/util.py	2013-01-05 00:38:57 UTC (rev 10241)
+++ CalendarServer/branches/users/glyph/queue-locking-and-timing/txdav/common/datastore/test/util.py	2013-01-05 00:38:58 UTC (rev 10242)
@@ -50,6 +50,7 @@
 from twistedcaldav.vcard import Component as ABComponent
 
 from pycalendar.datetime import PyCalendarDateTime
+from txdav.common.datastore.sql_tables import schema
 
 md5key = PropertyName.fromElement(TwistedGETContentMD5)
 
@@ -219,24 +220,17 @@
         cleanupTxn = storeToClean.sqlTxnFactory(
             "%s schema-cleanup" % (testCase.id(),)
         )
-        # TODO: should be getting these tables from a declaration of the schema
-        # somewhere.
-        tables = ['RESOURCE_PROPERTY',
-                  'NODE_INFO',
-                  'ATTACHMENT',
-                  'NOTIFICATION_OBJECT_REVISIONS',
-                  'ADDRESSBOOK_OBJECT_REVISIONS',
-                  'CALENDAR_OBJECT_REVISIONS',
-                  'ADDRESSBOOK_OBJECT',
-                  'CALENDAR_OBJECT',
-                  'CALENDAR_BIND',
-                  'ADDRESSBOOK_BIND',
-                  'CALENDAR',
-                  'ADDRESSBOOK',
-                  'CALENDAR_HOME',
-                  'ADDRESSBOOK_HOME',
-                  'NOTIFICATION',
-                  'NOTIFICATION_HOME']
+
+        # Tables are defined in the schema in the order in which the 'create
+        # table' statements are issued, so it's not possible to reference a
+        # later table.  Therefore it's OK to drop them in the (reverse) order
+        # that they happen to be in.
+        tables = [t.name for t in schema.model.tables
+                  # All tables with rows _in_ the schema are populated
+                  # exclusively _by_ the schema and shouldn't be manipulated
+                  # while the server is running, so we leave those populated.
+                  if not t.schemaRows][::-1]
+
         for table in tables:
             try:
                 yield cleanupTxn.execSQL("delete from " + table, [])
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20130104/1c1a246e/attachment.html>


More information about the calendarserver-changes mailing list