Skip to content

Commit cfb3cae

Browse files
author
Richard Jones
committed
mysql and postgresql schema mutation now handle added Multilinks; fixed test too
1 parent a408566 commit cfb3cae

File tree

3 files changed

+29
-24
lines changed

3 files changed

+29
-24
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Feature:
1313
- added search_checkboxes as an option for the search form
1414

1515
Fixed:
16+
- mysql and postgresql schema mutation now handle added Multilinks
1617
- web CSV export was busted (as was any action returning a result)
1718
- MultiMapping deviated from the Zope C implementation in a number of
1819
places (thanks Toby Sargeant)

roundup/backends/rdbms_common.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: rdbms_common.py,v 1.89 2004-04-05 07:13:10 richard Exp $
1+
# $Id: rdbms_common.py,v 1.90 2004-04-08 00:40:20 richard Exp $
22
''' Relational database (SQL) backend common code.
33
44
Basics:
@@ -320,19 +320,23 @@ def update_class(self, spec, old_spec, force=0):
320320
keyprop_changes['remove'])
321321

322322
# add new columns
323-
for propname, x in new_spec[1]:
323+
for propname, prop in new_spec[1]:
324324
if old_has(propname):
325325
continue
326-
sql = 'alter table _%s add column _%s varchar(255)'%(
327-
spec.classname, propname)
328-
if __debug__:
329-
print >>hyperdb.DEBUG, 'update_class', (self, sql)
330-
self.cursor.execute(sql)
331-
332-
# if the new column is a key prop, we need an index!
333-
if new_spec[0] == propname:
334-
self.create_class_table_key_index(spec.classname, propname)
335-
del keyprop_changes['add']
326+
prop = spec.properties[propname]
327+
if isinstance(prop, Multilink):
328+
self.create_multilink_table(spec, propname)
329+
else:
330+
sql = 'alter table _%s add column _%s varchar(255)'%(
331+
spec.classname, propname)
332+
if __debug__:
333+
print >>hyperdb.DEBUG, 'update_class', (self, sql)
334+
self.cursor.execute(sql)
335+
336+
# if the new column is a key prop, we need an index!
337+
if new_spec[0] == propname:
338+
self.create_class_table_key_index(spec.classname, propname)
339+
del keyprop_changes['add']
336340

337341
# if we didn't add the key prop just then, but the key prop has
338342
# changed, we still need to add the new index

test/db_test_base.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: db_test_base.py,v 1.21 2004-04-05 07:13:10 richard Exp $
18+
# $Id: db_test_base.py,v 1.22 2004-04-08 00:40:20 richard Exp $
1919

2020
import unittest, os, shutil, errno, imp, sys, time, pprint
2121

@@ -1075,7 +1075,8 @@ def init_ab(self):
10751075
self.db = self.module.Database(config, 'admin')
10761076
a = self.module.Class(self.db, "a", name=String())
10771077
a.setkey("name")
1078-
b = self.module.Class(self.db, "b", name=String())
1078+
b = self.module.Class(self.db, "b", name=String(),
1079+
fooz=Multilink('a'))
10791080
b.setkey("name")
10801081
self.db.post_init()
10811082

@@ -1091,7 +1092,7 @@ def test_addNewClass(self):
10911092
# add a new class to the schema and check creation of new items
10921093
# (and existence of old ones)
10931094
self.init_ab()
1094-
bid = self.db.b.create(name='bear')
1095+
bid = self.db.b.create(name='bear', fooz=[aid])
10951096
self.assertEqual(self.db.a.get(aid, 'name'), 'apple')
10961097
self.db.commit()
10971098
self.db.close()
@@ -1101,6 +1102,7 @@ def test_addNewClass(self):
11011102
self.assertEqual(self.db.a.get(aid, 'name'), 'apple')
11021103
self.assertEqual(self.db.a.lookup('apple'), aid)
11031104
self.assertEqual(self.db.b.get(bid, 'name'), 'bear')
1105+
self.assertEqual(self.db.b.get(bid, 'fooz'), [aid])
11041106
self.assertEqual(self.db.b.lookup('bear'), bid)
11051107

11061108
# confirm journal's ok
@@ -1174,11 +1176,9 @@ def test_changeClassKey(self):
11741176

11751177
def init_ml(self):
11761178
self.db = self.module.Database(config, 'admin')
1177-
a = self.module.Class(self.db, "a", name=String())
1178-
a.setkey('name')
1179-
b = self.module.Class(self.db, "b", name=String(),
1179+
a = self.module.Class(self.db, "a", name=String(),
11801180
fooz=Multilink('a'))
1181-
b.setkey("name")
1181+
a.setkey('name')
11821182
self.db.post_init()
11831183

11841184
def test_makeNewMultilink(self):
@@ -1189,20 +1189,20 @@ def test_makeNewMultilink(self):
11891189

11901190
# add a multilink prop
11911191
self.init_ml()
1192-
bid = self.db.b.create(name='bear', fooz=[aid])
1193-
self.assertEqual(self.db.b.find(fooz=aid), [bid])
1192+
bid = self.db.a.create(name='bear', fooz=[aid])
1193+
self.assertEqual(self.db.a.find(fooz=aid), [bid])
11941194
self.assertEqual(self.db.a.lookup('apple'), aid)
11951195
self.db.commit(); self.db.close()
11961196

11971197
# check
11981198
self.init_ml()
1199-
self.assertEqual(self.db.b.find(fooz=aid), [bid])
1199+
self.assertEqual(self.db.a.find(fooz=aid), [bid])
12001200
self.assertEqual(self.db.a.lookup('apple'), aid)
1201-
self.assertEqual(self.db.b.lookup('bear'), bid)
1201+
self.assertEqual(self.db.a.lookup('bear'), bid)
12021202

12031203
# confirm journal's ok
12041204
self.db.getjournal('a', aid)
1205-
self.db.getjournal('b', bid)
1205+
self.db.getjournal('a', bid)
12061206

12071207
def test_removeMultilink(self):
12081208
# add a multilink prop

0 commit comments

Comments
 (0)