From: richard Date: Thu, 8 Apr 2004 00:40:20 +0000 (+0000) Subject: mysql and postgresql schema mutation now handle added Multilinks; fixed test too X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=1f6a5e3fc573129daa9f02556eb907e78fc5a798;p=roundup.git mysql and postgresql schema mutation now handle added Multilinks; fixed test too git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@2267 57a73879-2fb5-44c3-a270-3262357dd7e2 --- diff --git a/CHANGES.txt b/CHANGES.txt index 14d8a92..c9a0566 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -13,6 +13,7 @@ Feature: - 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) diff --git a/roundup/backends/rdbms_common.py b/roundup/backends/rdbms_common.py index ab43ecd..e468a0f 100644 --- a/roundup/backends/rdbms_common.py +++ b/roundup/backends/rdbms_common.py @@ -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 @@ class Database(FileStorage, hyperdb.Database, roundupdb.Database): 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) - - # 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'] + 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 we didn't add the key prop just then, but the key prop has # changed, we still need to add the new index diff --git a/test/db_test_base.py b/test/db_test_base.py index a69b859..007ef9f 100644 --- a/test/db_test_base.py +++ b/test/db_test_base.py @@ -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 @@ class SchemaTest(MyTestCase): 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 @@ class SchemaTest(MyTestCase): # 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 @@ class SchemaTest(MyTestCase): 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 @@ class SchemaTest(MyTestCase): def init_ml(self): 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(), + a = self.module.Class(self.db, "a", name=String(), fooz=Multilink('a')) - b.setkey("name") + a.setkey('name') self.db.post_init() def test_makeNewMultilink(self): @@ -1189,20 +1189,20 @@ class SchemaTest(MyTestCase): # 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