changeset 2196:85954067e496

mysql and postgresql schema mutation now handle added Multilinks; fixed test too
author Richard Jones <richard@users.sourceforge.net>
date Thu, 08 Apr 2004 00:40:20 +0000
parents 638600b0d682
children c3baae58d56f
files CHANGES.txt roundup/backends/rdbms_common.py test/db_test_base.py
diffstat 3 files changed, 28 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/CHANGES.txt	Wed Apr 07 23:32:59 2004 +0000
+++ b/CHANGES.txt	Thu Apr 08 00:40:20 2004 +0000
@@ -13,6 +13,7 @@
 - added search_checkboxes as an option for the search form
 
 Fixed:
+- mysql and postgresql schema mutation now handle added Multilinks
 - web CSV export was busted (as was any action returning a result)
 - MultiMapping deviated from the Zope C implementation in a number of
   places (thanks Toby Sargeant)
--- a/roundup/backends/rdbms_common.py	Wed Apr 07 23:32:59 2004 +0000
+++ b/roundup/backends/rdbms_common.py	Thu Apr 08 00:40:20 2004 +0000
@@ -1,4 +1,4 @@
-# $Id: rdbms_common.py,v 1.89 2004-04-05 07:13:10 richard Exp $
+# $Id: rdbms_common.py,v 1.90 2004-04-08 00:40:20 richard Exp $
 ''' Relational database (SQL) backend common code.
 
 Basics:
@@ -320,19 +320,23 @@
                 keyprop_changes['remove'])
 
         # add new columns
-        for propname, x in new_spec[1]:
+        for propname, prop in new_spec[1]:
             if old_has(propname):
                 continue
-            sql = 'alter table _%s add column _%s varchar(255)'%(
-                spec.classname, propname)
-            if __debug__:
-                print >>hyperdb.DEBUG, 'update_class', (self, sql)
-            self.cursor.execute(sql)
+            prop = spec.properties[propname]
+            if isinstance(prop, Multilink):
+                self.create_multilink_table(spec, propname)
+            else:
+                sql = 'alter table _%s add column _%s varchar(255)'%(
+                    spec.classname, propname)
+                if __debug__:
+                    print >>hyperdb.DEBUG, 'update_class', (self, sql)
+                self.cursor.execute(sql)
 
-            # if the new column is a key prop, we need an index!
-            if new_spec[0] == propname:
-                self.create_class_table_key_index(spec.classname, propname)
-                del keyprop_changes['add']
+                # if the new column is a key prop, we need an index!
+                if new_spec[0] == propname:
+                    self.create_class_table_key_index(spec.classname, propname)
+                    del keyprop_changes['add']
 
         # if we didn't add the key prop just then, but the key prop has
         # changed, we still need to add the new index
--- a/test/db_test_base.py	Wed Apr 07 23:32:59 2004 +0000
+++ b/test/db_test_base.py	Thu Apr 08 00:40:20 2004 +0000
@@ -15,7 +15,7 @@
 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 # 
-# $Id: db_test_base.py,v 1.21 2004-04-05 07:13:10 richard Exp $ 
+# $Id: db_test_base.py,v 1.22 2004-04-08 00:40:20 richard Exp $ 
 
 import unittest, os, shutil, errno, imp, sys, time, pprint
 
@@ -1075,7 +1075,8 @@
         self.db = self.module.Database(config, 'admin')
         a = self.module.Class(self.db, "a", name=String())
         a.setkey("name")
-        b = self.module.Class(self.db, "b", name=String())
+        b = self.module.Class(self.db, "b", name=String(),
+            fooz=Multilink('a'))
         b.setkey("name")
         self.db.post_init()
 
@@ -1091,7 +1092,7 @@
         # add a new class to the schema and check creation of new items
         # (and existence of old ones)
         self.init_ab()
-        bid = self.db.b.create(name='bear')
+        bid = self.db.b.create(name='bear', fooz=[aid])
         self.assertEqual(self.db.a.get(aid, 'name'), 'apple')
         self.db.commit()
         self.db.close()
@@ -1101,6 +1102,7 @@
         self.assertEqual(self.db.a.get(aid, 'name'), 'apple')
         self.assertEqual(self.db.a.lookup('apple'), aid)
         self.assertEqual(self.db.b.get(bid, 'name'), 'bear')
+        self.assertEqual(self.db.b.get(bid, 'fooz'), [aid])
         self.assertEqual(self.db.b.lookup('bear'), bid)
 
         # confirm journal's ok
@@ -1174,11 +1176,9 @@
 
     def init_ml(self):
         self.db = self.module.Database(config, 'admin')
-        a = self.module.Class(self.db, "a", name=String())
+        a = self.module.Class(self.db, "a", name=String(),
+            fooz=Multilink('a'))
         a.setkey('name')
-        b = self.module.Class(self.db, "b", name=String(),
-            fooz=Multilink('a'))
-        b.setkey("name")
         self.db.post_init()
 
     def test_makeNewMultilink(self):
@@ -1189,20 +1189,20 @@
 
         # add a multilink prop
         self.init_ml()
-        bid = self.db.b.create(name='bear', fooz=[aid])
-        self.assertEqual(self.db.b.find(fooz=aid), [bid])
+        bid = self.db.a.create(name='bear', fooz=[aid])
+        self.assertEqual(self.db.a.find(fooz=aid), [bid])
         self.assertEqual(self.db.a.lookup('apple'), aid)
         self.db.commit(); self.db.close()
 
         # check
         self.init_ml()
-        self.assertEqual(self.db.b.find(fooz=aid), [bid])
+        self.assertEqual(self.db.a.find(fooz=aid), [bid])
         self.assertEqual(self.db.a.lookup('apple'), aid)
-        self.assertEqual(self.db.b.lookup('bear'), bid)
+        self.assertEqual(self.db.a.lookup('bear'), bid)
 
         # confirm journal's ok
         self.db.getjournal('a', aid)
-        self.db.getjournal('b', bid)
+        self.db.getjournal('a', bid)
 
     def test_removeMultilink(self):
         # add a multilink prop

Roundup Issue Tracker: http://roundup-tracker.org/