From 7873cc296ce28349302f8ffd9e66e0761fcad74d Mon Sep 17 00:00:00 2001 From: stefan Date: Fri, 9 Oct 2009 13:54:54 +0000 Subject: [PATCH] Add schema consistency checks. git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/roundup/trunk@4370 57a73879-2fb5-44c3-a270-3262357dd7e2 --- roundup/instance.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/roundup/instance.py b/roundup/instance.py index 06cff33..53fe56b 100644 --- a/roundup/instance.py +++ b/roundup/instance.py @@ -136,6 +136,27 @@ class Tracker: # or this is the first time the database is opened, # do database upgrade checks if not (self.optimize and self.db_open): + # As a consistency check, ensure that every link property is + # pointing at a defined class. Otherwise, the schema is + # internally inconsistent. This is an important safety + # measure as it protects against an accidental schema change + # dropping a table while there are still links to the table; + # once the table has been dropped, there is no way to get it + # back, so it is important to drop it only if we are as sure + # as possible that it is no longer needed. + classes = db.getclasses() + for classname in classes: + cl = db.getclass(classname) + for propname, prop in cl.getprops().iteritems(): + if not isinstance(prop, (hyperdb.Link, + hyperdb.Multilink)): + continue + linkto = prop.classname + if linkto not in classes: + raise ValueError, \ + ("property %s.%s links to non-existent class %s" + % (classname, propname, linkto)) + db.post_init() self.db_open = 1 return db -- 2.30.2