[cig-commits] r14469 - cs/portal/trunk/northridge/SeismoWebPortal

leif at geodynamics.org leif at geodynamics.org
Thu Mar 26 11:28:00 PDT 2009


Author: leif
Date: 2009-03-26 11:28:00 -0700 (Thu, 26 Mar 2009)
New Revision: 14469

Modified:
   cs/portal/trunk/northridge/SeismoWebPortal/management.py
   cs/portal/trunk/northridge/SeismoWebPortal/models.py
Log:
Wrote database migration code for new Specfem3DGlobeModel table, in
preparation for deployment.  Reverted MySQL-related schema change from
r14394.


Modified: cs/portal/trunk/northridge/SeismoWebPortal/management.py
===================================================================
--- cs/portal/trunk/northridge/SeismoWebPortal/management.py	2009-03-26 15:40:47 UTC (rev 14468)
+++ cs/portal/trunk/northridge/SeismoWebPortal/management.py	2009-03-26 18:28:00 UTC (rev 14469)
@@ -351,6 +351,77 @@
     return
 
 
+def upgradeDatabaseFromRevision12986():
+    # Migrate from v3.2.1 to v3.3.0.  Assumes the following SQL
+    # command has already been performed manually:
+    #
+    #     alter table SeismoWebPortal_specfem3dglobeparameters rename to SeismoWebPortal_specfem3dglobeparameters_old;
+    #
+    # (A new Specfem3DGlobeParameters table will be created by 'syncdb'.)
+    
+    # In r12986 and earlier, Specfem3DGlobeModel did not exist.
+    # Specfem3DGlobeParameters.model was simply an enumerated
+    # IntegerField, instead of a ForeignKey.
+    
+    model_types = [
+        #   id (*)                        display name
+        ("transversely_isotropic_prem_plus_3D_crust_2.0", "crust2.0+prem"),
+        ("s20rts",                        "s20rts"),
+        ("s362ani",                       "s362ani"),
+        #("s362iso",                       "s362iso"), # undocumented
+        ("s362wmani",                     "s362wmani"),
+        ("s362ani_prem",                  "s362ani+prem"),
+        ("s29ea",                         "s29ea"),
+        # (*) ^^^ 'id' must be a name understood by the code
+        ]
+    
+    #MODEL_TYPES = tuple([(num+1, model_types[num][1]) for num in xrange(0, len(model_types))])
+    #model = models.IntegerField(choices=MODEL_TYPES, core=True, default=2)
+    
+    from pysqlite2 import dbapi2 as sqlite
+    from django.contrib.auth.models import User
+    from django.conf import settings
+    
+    print "Upgrading database from r12986"
+    
+    con = sqlite.connect(settings.DATABASE_NAME)
+    cur = con.cursor()
+    cur.execute("select * from SeismoWebPortal_specfem3dglobeparameters_old")
+    oldParamsList = list(cur)
+    con = cur = None # unlock DB
+    
+    for oldParams in oldParamsList:
+        (id, name, mesh_id, model_int,
+         oceans, gravity, attenuation,
+         topography, rotation, ellipticity) = oldParams
+
+        mesh = models.Specfem3DGlobeMesh.objects.get(id = mesh_id)
+
+        model_id = model_types[model_int-1][0]
+        model = models.Specfem3DGlobeModel.objects.get(name = model_id)
+
+        models.Specfem3DGlobeParameters.objects.create(
+            id = id,
+            name = name,
+            mesh = mesh,
+            model = model,
+            oceans = oceans,
+            gravity = gravity,
+            attenuation = attenuation,
+            topography = topography,
+            rotation = rotation,
+            ellipticity = ellipticity,
+            )
+
+    # We've assumed that createExamplesForExistingUsers() will not
+    # fire.  Make sure we are right.
+    def bomb():
+        assert False
+    globals()['createExamplesForExistingUsers'] = bomb
+
+    return
+
+
 def createUserInfo():
     from django.contrib.auth.models import User
 
@@ -492,6 +563,7 @@
             importLegacyDatabase(legacyDB)
     elif hook:
         # upgradeDatabaseFromRevision12467()
+        # upgradeDatabaseFromRevision12986()
         globals()[hook]()
 
     createUserInfo()

Modified: cs/portal/trunk/northridge/SeismoWebPortal/models.py
===================================================================
--- cs/portal/trunk/northridge/SeismoWebPortal/models.py	2009-03-26 15:40:47 UTC (rev 14468)
+++ cs/portal/trunk/northridge/SeismoWebPortal/models.py	2009-03-26 18:28:00 UTC (rev 14469)
@@ -163,12 +163,13 @@
     latitude = models.FloatField(max_digits=19, decimal_places=10)
     longitude = models.FloatField(max_digits=19, decimal_places=10)
     depth = models.FloatField(max_digits=19, decimal_places=10)
-    Mrr = models.FloatField(max_digits=40, decimal_places=10)
-    Mtt = models.FloatField(max_digits=40, decimal_places=10)
-    Mpp = models.FloatField(max_digits=40, decimal_places=10)
-    Mrt = models.FloatField(max_digits=40, decimal_places=10)
-    Mrp = models.FloatField(max_digits=40, decimal_places=10)
-    Mtp = models.FloatField(max_digits=40, decimal_places=10)
+    # XXX: 'max_digits' must be about 40 for non-SQLite
+    Mrr = models.FloatField(max_digits=19, decimal_places=10)
+    Mtt = models.FloatField(max_digits=19, decimal_places=10)
+    Mpp = models.FloatField(max_digits=19, decimal_places=10)
+    Mrt = models.FloatField(max_digits=19, decimal_places=10)
+    Mrp = models.FloatField(max_digits=19, decimal_places=10)
+    Mtp = models.FloatField(max_digits=19, decimal_places=10)
 
     def __str__(self): return self.eventName
 



More information about the CIG-COMMITS mailing list