[CalendarServer-changes] [7858] CalendarServer/trunk/txdav/common/datastore
source_changes at macosforge.org
source_changes at macosforge.org
Mon Aug 8 18:19:07 PDT 2011
Revision: 7858
http://trac.macosforge.org/projects/calendarserver/changeset/7858
Author: glyph at apple.com
Date: 2011-08-08 18:19:06 -0700 (Mon, 08 Aug 2011)
Log Message:
-----------
uniqueness-checking of shortened table names for oracle
Modified Paths:
--------------
CalendarServer/trunk/txdav/common/datastore/sql_tables.py
CalendarServer/trunk/txdav/common/datastore/test/test_sql_tables.py
Modified: CalendarServer/trunk/txdav/common/datastore/sql_tables.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/sql_tables.py 2011-08-08 19:27:42 UTC (rev 7857)
+++ CalendarServer/trunk/txdav/common/datastore/sql_tables.py 2011-08-09 01:19:06 UTC (rev 7858)
@@ -202,12 +202,20 @@
-def _translateSchema(out):
+class SchemaBroken(Exception):
"""
+ The schema is broken and cannot be translated.
+ """
+
+
+
+def _translateSchema(out, schema=schema):
+ """
When run as a script, translate the schema to another dialect. Currently
only postgres and oracle are supported, and native format is postgres, so
emit in oracle format.
"""
+ shortNames = {}
for sequence in schema.model.sequences:
out.write('create sequence %s;\n' % (sequence.name,))
for table in schema:
@@ -215,6 +223,10 @@
# is CALENDAR_OBJECT_ATTACHMENTS_MODE, which isn't actually _used_
# anywhere, so we can fake it for now.
shortName = table.model.name[:30]
+ if shortName in shortNames:
+ raise SchemaBroken("short-name conflict between %s and %s" %
+ (table.model.name, shortNames[shortName]))
+ shortNames[shortName] = table.model.name
out.write('create table %s (\n' % (shortName,))
first = True
for column in table:
Modified: CalendarServer/trunk/txdav/common/datastore/test/test_sql_tables.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/test/test_sql_tables.py 2011-08-08 19:27:42 UTC (rev 7857)
+++ CalendarServer/trunk/txdav/common/datastore/test/test_sql_tables.py 2011-08-09 01:19:06 UTC (rev 7858)
@@ -26,6 +26,10 @@
from cStringIO import StringIO
from txdav.common.datastore.sql_tables import schema, _translateSchema
+from txdav.common.datastore.sql_tables import SchemaBroken
+from twext.enterprise.dal.parseschema import addSQLToSchema
+from twext.enterprise.dal.model import Schema
+from twext.enterprise.dal.syntax import SchemaSyntax
from twisted.trial.unittest import TestCase
class SampleSomeColumns(TestCase):
@@ -61,4 +65,27 @@
io.getvalue())
+ def test_youBrokeTheSchema(self):
+ """
+ Oracle table names have a 30-character limit. Our schema translator
+ simply truncates the names if necessary, but that means that you can't
+ have tables whose first 30 characters differ. L{_translateSchema}
+ raises a SchemaBroken() exception if this happens. (This test is to
+ make sure L{test_schemaTranslation}, above, will actually fail if this
+ happens.)
+ """
+ # TODO: same thing for sequences.
+ schema = Schema()
+ addSQLToSchema(
+ schema, """
+ create table same_012345678012345678990123456789_1 (foo integer);
+ create table same_012345678012345678990123456789_1 (bar text);
+ """
+ )
+ io = StringIO()
+ self.assertRaises(
+ SchemaBroken, _translateSchema, io, SchemaSyntax(schema)
+ )
+
+
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110808/ad8e5385/attachment-0001.html>
More information about the calendarserver-changes
mailing list