[cig-commits] r14578 - in cs/portal/trunk/northridge: . SeismoWebPortal SeismoWebPortal/templates/SeismoWebPortal

leif at geodynamics.org leif at geodynamics.org
Thu Apr 2 18:47:17 PDT 2009


Author: leif
Date: 2009-04-02 18:47:17 -0700 (Thu, 02 Apr 2009)
New Revision: 14578

Modified:
   cs/portal/trunk/northridge/SeismoWebPortal/management.py
   cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/splash.html
   cs/portal/trunk/northridge/setup.py
Log:
Wrote some code to clean-up the mess created in the database by the
bugs I've recently fixed.  The mess takes the form of duplicate
Ownership and Archive records.  In the case of Archive, the table
ballooned to 3114 records, 3062 of which were duplicates.


Modified: cs/portal/trunk/northridge/SeismoWebPortal/management.py
===================================================================
--- cs/portal/trunk/northridge/SeismoWebPortal/management.py	2009-04-03 01:00:02 UTC (rev 14577)
+++ cs/portal/trunk/northridge/SeismoWebPortal/management.py	2009-04-03 01:47:17 UTC (rev 14578)
@@ -422,6 +422,41 @@
     return
 
 
+def repairDamageFromArchiveAndDeleteBugs():
+    # Repair damage done to the database by certain bugs.  Cf. r14564, r14576.
+
+    for Model in (models.Ownership, models.Archive):
+        print "Checking", Model.__name__, "for duplicates"
+        l = []
+        for o in Model.objects.all():
+            l.append((o.objType.id, o.objId, o.id))
+        l.sort()
+        last = None
+        duplicates = []
+        for t in l:
+            if last is not None:
+                if t[:2] == last[:2]:
+                    orig = Model.objects.get(id = last[2])
+                    dup = Model.objects.get(id = t[2])
+                    if Model is models.Ownership:
+                        print "Duplicate", Model.__name__, t, last, orig.obj, dup.obj, orig.owner, dup.owner
+                        # delete the older object
+                        duplicates.append(last[2])
+                    else:
+                        # delete the newer object
+                        duplicates.append(t[2])
+            last = t
+
+        print "Deleting duplicates"
+        print "    %d objects, %d duplicates (%d)" % (len(l), len(duplicates), len(l) - len(duplicates))
+        for dup in duplicates:
+            dup = Model.objects.get(id = dup)
+            dup.delete()
+        print "    %d objects remain" % Model.objects.count()
+    
+    return
+
+
 def createUserInfo():
     from django.contrib.auth.models import User
 
@@ -564,6 +599,7 @@
     elif hook:
         # upgradeDatabaseFromRevision12467()
         # upgradeDatabaseFromRevision12986()
+        # repairDamageFromArchiveAndDeleteBugs()
         globals()[hook]()
 
     createUserInfo()

Modified: cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/splash.html
===================================================================
--- cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/splash.html	2009-04-03 01:00:02 UTC (rev 14577)
+++ cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/splash.html	2009-04-03 01:47:17 UTC (rev 14578)
@@ -7,7 +7,7 @@
 
     <h1><img src="{{root}}/images/cig.gif"> <img src="{{root}}/images/seismogram.gif"><br>CIG Seismology Web Portal</h1>
 
-    <p>Version 3.3.0</p>
+    <p>Version 3.3.1</p>
 
     <hr>
 

Modified: cs/portal/trunk/northridge/setup.py
===================================================================
--- cs/portal/trunk/northridge/setup.py	2009-04-03 01:00:02 UTC (rev 14577)
+++ cs/portal/trunk/northridge/setup.py	2009-04-03 01:47:17 UTC (rev 14578)
@@ -3,7 +3,7 @@
 
 setup(
     name = 'SeismoWebPortal', 
-    version = '3.3.0',
+    version = '3.3.1',
     url = 'http://www.geodynamics.org/',
     author = 'Leif Strand',
     author_email = 'leif at geodynamics.org',



More information about the CIG-COMMITS mailing list