From: richard Date: Fri, 26 Mar 2004 05:16:03 +0000 (+0000) Subject: Fix for sqlite backend migration. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=d0b5a7ff5a42233684fa78d4eca06623ea007856;hp=a1ad36d2123d336983fe7df47f8f7f0aff2ba9c2;p=roundup.git Fix for sqlite backend migration. Change Cookie -> SimpleCookie git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@2205 57a73879-2fb5-44c3-a270-3262357dd7e2 --- diff --git a/CHANGES.txt b/CHANGES.txt index 952d337..d7b3d19 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -4,8 +4,8 @@ are given with the most recent entry first. 2004-??-?? 0.7.0b2 Feature: - added CSV export to index pages -- added new auditor, emailauditor.py, that works around a bug in IE. See - emailauditor.py for more info. +- added emailauditor.py which works around a bug in IE. See + "detectors/emailauditor.py" for more info. - added dispatcher functionality - see upgrading.txt for more info - added Reject exception which may be raised by auditors. This is trapped by mailgw and may be used to veto creation of file attachments or @@ -15,9 +15,11 @@ Feature: Fixed: - Boolean HTML templating was broken - Link HTML templating field() was broken -- Fix reporting of test inclusion in postgresql test +- fix reporting of test inclusion in postgresql test - EditAction was confused about who "self" was -- Edit collision detection was broken for index-page edits +- edit collision detection was broken for index-page edits +- sqlite backend wasn't migrating multilink tables correctly +- use SimpleCookie instead of Cookie (is an alias for the evil SmartCookie) 2004-03-24 0.7.0b1 diff --git a/TODO.txt b/TODO.txt index 3d6ae74..b2f8f02 100644 --- a/TODO.txt +++ b/TODO.txt @@ -1,8 +1,5 @@ This file contains items that need doing before the next release: -- ensure index creation is triggered by the version 1->2 update - (and other upgrade tests) - Optionally: - have rdbms backends look up the journal for actor if it's not set - migrate to numeric ID values (fixes bug 817217) diff --git a/roundup/backends/back_sqlite.py b/roundup/backends/back_sqlite.py index 32f3d7c..de20022 100644 --- a/roundup/backends/back_sqlite.py +++ b/roundup/backends/back_sqlite.py @@ -1,4 +1,4 @@ -# $Id: back_sqlite.py,v 1.20 2004-03-22 07:45:39 richard Exp $ +# $Id: back_sqlite.py,v 1.21 2004-03-26 05:16:03 richard Exp $ '''Implements a backend for SQLite. See https://pysqlite.sourceforge.net/ for pysqlite info @@ -87,6 +87,8 @@ class Database(rdbms_common.Database): if tables.has_key(classname): dbspec = tables[classname] self.update_class(spec, dbspec, force=1, adding_actor=1) + # we've updated - don't try again + tables[classname] = spec.schema() def update_class(self, spec, old_spec, force=0, adding_actor=0): ''' Determine the differences between the current spec and the @@ -106,11 +108,12 @@ class Database(rdbms_common.Database): return 0 if __debug__: - print >>hyperdb.DEBUG, 'update_class FIRING' + print >>hyperdb.DEBUG, 'update_class FIRING for', spec.classname # detect multilinks that have been removed, and drop their table old_has = {} - for name,prop in old_spec[1]: + for name, prop in old_spec[1]: + print (name, prop) old_has[name] = 1 if new_has(name) or not isinstance(prop, hyperdb.Multilink): continue @@ -132,9 +135,31 @@ class Database(rdbms_common.Database): for propname,x in new_spec[1]: prop = properties[propname] if isinstance(prop, hyperdb.Multilink): - if force or not old_has(propname): + if not old_has(propname): # we need to create the new table self.create_multilink_table(spec, propname) + elif force: + tn = '%s_%s'%(spec.classname, propname) + # grabe the current values + sql = 'select linkid, nodeid from %s'%tn + if __debug__: + print >>hyperdb.DEBUG, 'update_class', (self, sql) + self.cursor.execute(sql) + rows = self.cursor.fetchall() + + # drop the old table + self.drop_multilink_table_indexes(spec.classname, propname) + sql = 'drop table %s'%tn + if __debug__: + print >>hyperdb.DEBUG, 'migration', (self, sql) + self.cursor.execute(sql) + + # re-create and populate the new table + self.create_multilink_table(spec, propname) + sql = '''insert into %s (linkid, nodeid) values + (%s, %s)'''%(tn, self.arg, self.arg) + for linkid, nodeid in rows: + self.cursor.execute(sql, (int(linkid), int(nodeid))) elif old_has(propname): # we copy this col over from the old table fetch.append('_'+propname) @@ -154,6 +179,8 @@ class Database(rdbms_common.Database): self.drop_class_table_indexes(cn, old_spec[0]) # drop the old table + if __debug__: + print >>hyperdb.DEBUG, 'update_class "drop table _%s"'%cn self.cursor.execute('drop table _%s'%cn) # create the new table diff --git a/roundup/cgi/client.py b/roundup/cgi/client.py index a07e721..c34d426 100644 --- a/roundup/cgi/client.py +++ b/roundup/cgi/client.py @@ -1,4 +1,4 @@ -# $Id: client.py,v 1.168 2004-03-25 00:44:28 richard Exp $ +# $Id: client.py,v 1.169 2004-03-26 05:16:03 richard Exp $ """WWW request handler (also used in the stand-alone server). """ @@ -283,7 +283,7 @@ class Client: pass # look up the user session cookie (may override the REMOTE_USER) - cookie = Cookie.Cookie(self.env.get('HTTP_COOKIE', '')) + cookie = Cookie.SimpleCookie(self.env.get('HTTP_COOKIE', '')) user = 'anonymous' if (cookie.has_key(self.cookie_name) and cookie[self.cookie_name].value != 'deleted'):