[CalendarServer-changes] [8110] CalendarServer/trunk/txdav/common/datastore

source_changes at macosforge.org source_changes at macosforge.org
Tue Sep 20 14:04:39 PDT 2011


Revision: 8110
          http://trac.macosforge.org/projects/calendarserver/changeset/8110
Author:   glyph at apple.com
Date:     2011-09-20 14:04:39 -0700 (Tue, 20 Sep 2011)
Log Message:
-----------
put PRIMARY_KEY first in schema translation.

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-09-20 19:43:00 UTC (rev 8109)
+++ CalendarServer/trunk/txdav/common/datastore/sql_tables.py	2011-09-20 21:04:39 UTC (rev 8110)
@@ -285,15 +285,15 @@
                 name, ", ".join('"' + col.name + '"' for col in cols)
             ))
 
+        pk = table.model.primaryKey
+        if pk is not None and len(pk) > 1:
+            writeConstraint("primary key", pk)
+
         for uniqueColumns in table.model.uniques():
             if len(uniqueColumns) == 1:
                 continue # already done inline, skip
             writeConstraint("unique", uniqueColumns)
 
-        pk = table.model.primaryKey
-        if pk is not None and len(pk) > 1:
-            writeConstraint("primary key", pk)
-
         out.write('\n);\n\n')
 
         fakeMeta = FixedPlaceholder(ORACLE_DIALECT, '%s')

Modified: CalendarServer/trunk/txdav/common/datastore/test/test_sql_tables.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/test/test_sql_tables.py	2011-09-20 19:43:00 UTC (rev 8109)
+++ CalendarServer/trunk/txdav/common/datastore/test/test_sql_tables.py	2011-09-20 21:04:39 UTC (rev 8110)
@@ -192,6 +192,27 @@
         )
 
 
+    def test_primaryKeyUniqueOrdering(self):
+        """
+        If a table specifies both a PRIMARY KEY and a UNIQUE constraint, the
+        PRIMARY KEY will always be emitted first.
+        """
+        stx = SchemaSyntax(
+            self.schemaFromString(
+                "create table alpha ("
+                "beta integer, gamma text, delta integer, "
+                "unique(beta, delta), primary key(beta, gamma))"
+            )
+        )
+        self.assertSortaEquals(
+            self.translated(stx),
+            'create table alpha ( '
+            '"beta" integer, "gamma" nclob, "delta" integer, '
+            'primary key("beta", "gamma"), unique("beta", "delta") );'
+        )
+
+
+
     def test_youBrokeTheSchema(self):
         """
         Oracle table names have a 30-character limit.  Our schema translator
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110920/dacdebe8/attachment.html>


More information about the calendarserver-changes mailing list