瀏覽代碼

Fixed bug in upgrade of T1 to T2 with setting default vocabs

Stephen Ficklin 9 年之前
父節點
當前提交
3bfb0691be

+ 19 - 7
tripal_analysis/tripal_analysis.install

@@ -300,13 +300,25 @@ function tripal_analysis_update_7200() {
   // set the analysis_property as default
   // set the analysis_property as default
   try {
   try {
     $cv_id = db_query("SELECT cv_id FROM chado.cv WHERE name = 'analysis_property'")->fetchField();
     $cv_id = db_query("SELECT cv_id FROM chado.cv WHERE name = 'analysis_property'")->fetchField();
-    db_insert('tripal_cv_defaults')
-      ->fields(array(
-        'table_name' => 'analysisprop',
-        'field_name' => 'type_id',
-        'cv_id' => $cv_id
-      ))
-      ->execute();
+
+    // Add in the default vocabulary.
+    // If a record already exists then don't change it.
+    $cdi = db_select('tripal_cv_defaults', 't')
+      ->fields('t', array('cv_default_id'))
+      ->condition('table_name', 'analysisprop')
+      ->condition('field_name', 'type_id')
+      ->execute()
+      ->fetchField();
+
+    if (!$cdi) {
+      db_insert('tripal_cv_defaults')
+        ->fields(array(
+          'table_name' => 'analysisprop',
+          'field_name' => 'type_id',
+          'cv_id' => $cv_id
+        ))
+        ->execute();
+    }
   }
   }
   catch (\PDOException $e) {
   catch (\PDOException $e) {
     $error = $e->getMessage();
     $error = $e->getMessage();

+ 49 - 22
tripal_contact/tripal_contact.install

@@ -255,21 +255,40 @@ function tripal_contact_update_7200() {
       ))
       ))
       ->execute();
       ->execute();
     }
     }
+
     // make this CV the defaults for the contact properties and contact types
     // make this CV the defaults for the contact properties and contact types
-    db_insert('tripal_cv_defaults')
-      ->fields(array(
-         'table_name' => 'contact',
-         'field_name' => 'type_id',
-         'cv_id' => $cv_id
-       ))
-      ->execute();
-    db_insert('tripal_cv_defaults')
-      ->fields(array(
-        'table_name' => 'contactprop',
-        'field_name' => 'type_id',
-        'cv_id' => $cv_id
-      ))
-      ->execute();
+    // If a record already exists then don't change it.
+    $cdi = db_select('tripal_cv_defaults', 't')
+      ->fields('t', array('cv_default_id'))
+      ->condition('table_name', 'contact')
+      ->condition('field_name', 'type_id')
+      ->execute()
+      ->fetchField();
+    if (!$cdi) {
+      db_insert('tripal_cv_defaults')
+        ->fields(array(
+           'table_name' => 'contact',
+           'field_name' => 'type_id',
+           'cv_id' => $cv_id
+         ))
+        ->execute();
+    }
+    $cdi = db_select('tripal_cv_defaults', 't')
+      ->fields('t', array('cv_default_id'))
+      ->condition('table_name', 'contactprop')
+      ->condition('field_name', 'type_id')
+      ->execute()
+      ->fetchField();
+
+    if (!$cdi) {
+      db_insert('tripal_cv_defaults')
+        ->fields(array(
+          'table_name' => 'contactprop',
+          'field_name' => 'type_id',
+          'cv_id' => $cv_id
+        ))
+        ->execute();
+    }
   }
   }
   catch (\PDOException $e) {
   catch (\PDOException $e) {
     $error = $e->getMessage();
     $error = $e->getMessage();
@@ -289,14 +308,22 @@ function tripal_contact_update_7200() {
       ))
       ))
       ->execute();
       ->execute();
     }
     }
-    // add the default
-    db_insert('tripal_cv_defaults')
-      ->fields(array(
-        'table_name' => 'contact_relationship',
-        'field_name' => 'type_id',
-        'cv_id' => $cv_id
-        ))
-      ->execute();
+    $cdi = db_select('tripal_cv_defaults', 't')
+      ->fields('t', array('cv_default_id'))
+      ->condition('table_name', 'contact_relationship')
+      ->condition('field_name', 'type_id')
+      ->execute()
+      ->fetchField();
+    if (!$cdi) {
+      // add the default
+      db_insert('tripal_cv_defaults')
+        ->fields(array(
+          'table_name' => 'contact_relationship',
+          'field_name' => 'type_id',
+          'cv_id' => $cv_id
+          ))
+        ->execute();
+    }
   }
   }
   catch (\PDOException $e) {
   catch (\PDOException $e) {
     $error = $e->getMessage();
     $error = $e->getMessage();

+ 13 - 13
tripal_cv/api/tripal_cv.api.inc

@@ -1025,30 +1025,30 @@ function tripal_set_default_cv($table, $field, $cv_name, $cv_id = FALSE) {
   if ($cv) {
   if ($cv) {
     // first delete any entries for this table and field
     // first delete any entries for this table and field
     $num_deleted = db_delete('tripal_cv_defaults')
     $num_deleted = db_delete('tripal_cv_defaults')
-    ->condition('table_name', $table)
-    ->condition('field_name', $field)
-    ->execute();
+      ->condition('table_name', $table)
+      ->condition('field_name', $field)
+      ->execute();
 
 
     // now add the default value
     // now add the default value
     $cv_default_id = db_insert('tripal_cv_defaults')
     $cv_default_id = db_insert('tripal_cv_defaults')
-    ->fields(array(
-      'table_name' => $table,
-      'field_name' => $field,
-      'cv_id'      => $cv->cv_id,
-    ))
-    ->execute();
+      ->fields(array(
+        'table_name' => $table,
+        'field_name' => $field,
+        'cv_id'      => $cv->cv_id,
+      ))
+      ->execute();
 
 
     if (!$cv_default_id) {
     if (!$cv_default_id) {
       tripal_report_error('tripal_cv', TRIPAL_WARNING,
       tripal_report_error('tripal_cv', TRIPAL_WARNING,
-      "Cannot set default vocabulary for %table.%field. Check the error logs.",
-      array('%table' => $table, '%field' => $field));
+        "Cannot set default vocabulary for %table.%field. Check the error logs.",
+        array('%table' => $table, '%field' => $field));
       return FALSE;
       return FALSE;
     }
     }
   }
   }
   else {
   else {
     tripal_report_error('tripal_cv', TRIPAL_WARNING,
     tripal_report_error('tripal_cv', TRIPAL_WARNING,
-    "Cannot set default vocabulary for %table.%field. The vocabulary name, '%cvname', doesn't exist.",
-    array('%table' => $table, '%field' => $field, '%cvname' => $cv_name));
+      "Cannot set default vocabulary for %table.%field. The vocabulary name, '%cvname', doesn't exist.",
+      array('%table' => $table, '%field' => $field, '%cvname' => $cv_name));
     return FALSE;
     return FALSE;
   }
   }
 }
 }

+ 46 - 22
tripal_feature/tripal_feature.install

@@ -375,13 +375,21 @@ function tripal_feature_update_7200() {
   // set the default feature property vocabulary
   // set the default feature property vocabulary
   try {
   try {
     $cv_id = db_query("SELECT cv_id FROM chado.cv WHERE name = 'feature_property'")->fetchField();
     $cv_id = db_query("SELECT cv_id FROM chado.cv WHERE name = 'feature_property'")->fetchField();
-    db_insert('tripal_cv_defaults')
-      ->fields(array(
-        'table_name' => 'featureprop',
-        'field_name' => 'type_id',
-        'cv_id' => $cv_id
-        ))
-      ->execute();
+    $cdi = db_select('tripal_cv_defaults', 't')
+      ->fields('t', array('cv_default_id'))
+      ->condition('table_name', 'featureprop')
+      ->condition('field_name', 'type_id')
+      ->execute()
+      ->fetchField();
+    if (!$cdi) {
+      db_insert('tripal_cv_defaults')
+        ->fields(array(
+          'table_name' => 'featureprop',
+          'field_name' => 'type_id',
+          'cv_id' => $cv_id
+          ))
+        ->execute();
+    }
   }
   }
   catch (\PDOException $e) {
   catch (\PDOException $e) {
     $error = $e->getMessage();
     $error = $e->getMessage();
@@ -400,14 +408,22 @@ function tripal_feature_update_7200() {
       ))
       ))
       ->execute();
       ->execute();
     }
     }
-    // use the new feature_relationship CV we just added
-    db_insert('tripal_cv_defaults')
-      ->fields(array(
-        'table_name' => 'feature_relationship',
-        'field_name' => 'type_id',
-        'cv_id' => $cv_id
-      ))
-      ->execute();
+    // use the new featureprop CV we just added
+    $cdi = db_select('tripal_cv_defaults', 't')
+      ->fields('t', array('cv_default_id'))
+      ->condition('table_name', 'feature_relationship')
+      ->condition('field_name', 'type_id')
+      ->execute()
+      ->fetchField();
+    if (!$cdi) {
+      db_insert('tripal_cv_defaults')
+        ->fields(array(
+          'table_name' => 'feature_relationship',
+          'field_name' => 'type_id',
+          'cv_id' => $cv_id
+        ))
+        ->execute();
+    }
   }
   }
   catch (\PDOException $e) {
   catch (\PDOException $e) {
     $error = $e->getMessage();
     $error = $e->getMessage();
@@ -426,13 +442,21 @@ function tripal_feature_update_7200() {
       ))
       ))
       ->execute();
       ->execute();
     }
     }
-    db_insert('tripal_cv_defaults')
-      ->fields(array(
-        'table_name' => 'feature',
-        'field_name' => 'type_id',
-        'cv_id' => $cv_id
-      ))
-      ->execute();
+    $cdi = db_select('tripal_cv_defaults', 't')
+      ->fields('t', array('cv_default_id'))
+      ->condition('table_name', 'feature')
+      ->condition('field_name', 'type_id')
+      ->execute()
+      ->fetchField();
+    if (!$cdi) {
+      db_insert('tripal_cv_defaults')
+        ->fields(array(
+          'table_name' => 'feature',
+          'field_name' => 'type_id',
+          'cv_id' => $cv_id
+        ))
+        ->execute();
+    }
   }
   }
   catch (\PDOException $e) {
   catch (\PDOException $e) {
     $error = $e->getMessage();
     $error = $e->getMessage();

+ 45 - 21
tripal_featuremap/tripal_featuremap.install

@@ -497,13 +497,21 @@ function tripal_featuremap_update_7200() {
   // featuremap_units
   // featuremap_units
   try {
   try {
     $cv_id = db_query("SELECT cv_id FROM chado.cv WHERE name = 'featuremap_units'")->fetchField();
     $cv_id = db_query("SELECT cv_id FROM chado.cv WHERE name = 'featuremap_units'")->fetchField();
-    db_insert('tripal_cv_defaults')
-      ->fields(array(
-        'table_name' => 'featuremap',
-        'field_name' => 'unittype_id',
-        'cv_id' => $cv_id
-      ))
-      ->execute();
+    $cdi = db_select('tripal_cv_defaults', 't')
+      ->fields('t', array('cv_default_id'))
+      ->condition('table_name', 'featuremap')
+      ->condition('field_name', 'type_id')
+      ->execute()
+      ->fetchField();
+    if (!$cdi) {
+      db_insert('tripal_cv_defaults')
+        ->fields(array(
+          'table_name' => 'featuremap',
+          'field_name' => 'unittype_id',
+          'cv_id' => $cv_id
+        ))
+        ->execute();
+    }
   }
   }
   catch (\PDOException $e) {
   catch (\PDOException $e) {
     $error = $e->getMessage();
     $error = $e->getMessage();
@@ -513,13 +521,21 @@ function tripal_featuremap_update_7200() {
   // featurepos_property
   // featurepos_property
   try {
   try {
     $cv_id = db_query("SELECT cv_id FROM chado.cv WHERE name = 'featurepos_property'")->fetchField();
     $cv_id = db_query("SELECT cv_id FROM chado.cv WHERE name = 'featurepos_property'")->fetchField();
-    db_insert('tripal_cv_defaults')
-      ->fields(array(
-        'table_name' => 'featureposprop',
-        'field_name' => 'type_id',
-        'cv_id' => $cv_id
-      ))
-      ->execute();
+    $cdi = db_select('tripal_cv_defaults', 't')
+      ->fields('t', array('cv_default_id'))
+      ->condition('table_name', 'featureposprop')
+      ->condition('field_name', 'type_id')
+      ->execute()
+      ->fetchField();
+    if (!$cdi) {
+      db_insert('tripal_cv_defaults')
+        ->fields(array(
+          'table_name' => 'featureposprop',
+          'field_name' => 'type_id',
+          'cv_id' => $cv_id
+        ))
+        ->execute();
+    }
   }
   }
   catch (\PDOException $e) {
   catch (\PDOException $e) {
     $error = $e->getMessage();
     $error = $e->getMessage();
@@ -529,13 +545,21 @@ function tripal_featuremap_update_7200() {
   // featuremap_property
   // featuremap_property
   try {
   try {
     $cv_id = db_query("SELECT cv_id FROM chado.cv WHERE name = 'featuremap_property'")->fetchField();
     $cv_id = db_query("SELECT cv_id FROM chado.cv WHERE name = 'featuremap_property'")->fetchField();
-    db_insert('tripal_cv_defaults')
-     ->fields(array(
-       'table_name' => 'featuremapprop',
-       'field_name' => 'type_id',
-       'cv_id' => $cv_id
-      ))
-      ->execute();
+    $cdi = db_select('tripal_cv_defaults', 't')
+      ->fields('t', array('cv_default_id'))
+      ->condition('table_name', 'featuremapprop')
+      ->condition('field_name', 'type_id')
+      ->execute()
+      ->fetchField();
+    if (!$cdi) {
+      db_insert('tripal_cv_defaults')
+       ->fields(array(
+         'table_name' => 'featuremapprop',
+         'field_name' => 'type_id',
+         'cv_id' => $cv_id
+        ))
+        ->execute();
+    }
   }
   }
   catch (\PDOException $e) {
   catch (\PDOException $e) {
     $error = $e->getMessage();
     $error = $e->getMessage();

+ 30 - 14
tripal_library/tripal_library.install

@@ -375,13 +375,21 @@ function tripal_library_update_7200() {
   // library_type
   // library_type
   try {
   try {
     $cv_id = db_query("SELECT cv_id FROM chado.cv WHERE name = 'library_type'")->fetchField();
     $cv_id = db_query("SELECT cv_id FROM chado.cv WHERE name = 'library_type'")->fetchField();
-    db_insert('tripal_cv_defaults')
-      ->fields(array(
-        'table_name' => 'library',
-        'field_name' => 'type_id',
-        'cv_id' => $cv_id
-      ))
-      ->execute();
+    $cdi = db_select('tripal_cv_defaults', 't')
+      ->fields('t', array('cv_default_id'))
+      ->condition('table_name', 'library')
+      ->condition('field_name', 'type_id')
+      ->execute()
+      ->fetchField();
+    if (!$cdi) {
+      db_insert('tripal_cv_defaults')
+        ->fields(array(
+          'table_name' => 'library',
+          'field_name' => 'type_id',
+          'cv_id' => $cv_id
+        ))
+        ->execute();
+    }
   }
   }
   catch (\PDOException $e) {
   catch (\PDOException $e) {
     $error = $e->getMessage();
     $error = $e->getMessage();
@@ -390,13 +398,21 @@ function tripal_library_update_7200() {
   // library_property
   // library_property
   try {
   try {
     $cv_id = db_query("SELECT cv_id FROM chado.cv WHERE name = 'library_property'")->fetchField();
     $cv_id = db_query("SELECT cv_id FROM chado.cv WHERE name = 'library_property'")->fetchField();
-    db_insert('tripal_cv_defaults')
-      ->fields(array(
-        'table_name' => 'libraryprop',
-        'field_name' => 'type_id',
-        'cv_id' => $cv_id
-      ))
-      ->execute();
+    $cdi = db_select('tripal_cv_defaults', 't')
+      ->fields('t', array('cv_default_id'))
+      ->condition('table_name', 'libraryprop')
+      ->condition('field_name', 'type_id')
+      ->execute()
+      ->fetchField();
+    if (!$cdi) {
+      db_insert('tripal_cv_defaults')
+        ->fields(array(
+          'table_name' => 'libraryprop',
+          'field_name' => 'type_id',
+          'cv_id' => $cv_id
+        ))
+        ->execute();
+    }
   }
   }
   catch (\PDOException $e) {
   catch (\PDOException $e) {
     $error = $e->getMessage();
     $error = $e->getMessage();

+ 19 - 9
tripal_organism/tripal_organism.install

@@ -130,7 +130,7 @@ function tripal_organism_add_cvterms() {
  */
  */
 function tripal_organism_update_7200() {
 function tripal_organism_update_7200() {
 
 
-  // add the new organism_property vocabulary
+  // Add the new organism_property vocabulary
   // We cannot use the Tripal API calls in the 7000 update
   // We cannot use the Tripal API calls in the 7000 update
   // because during upgrade the tripal_core should also be disabled
   // because during upgrade the tripal_core should also be disabled
   try {
   try {
@@ -142,14 +142,24 @@ function tripal_organism_update_7200() {
       ";
       ";
       db_query($sql);
       db_query($sql);
     }
     }
-    // add in the default vocabulary
-    db_insert('tripal_cv_defaults')
-      ->fields(array(
-        'table_name' => 'organismprop',
-        'field_name' => 'type_id',
-        'cv_id' => $cv_id
-      ))
-      ->execute();
+    // If a record already exists then don't change it.
+    $cdi = db_select('tripal_cv_defaults', 't')
+      ->fields('t', array('cv_default_id'))
+      ->condition('table_name', 'organismprop')
+      ->condition('field_name', 'type_id')
+      ->execute()
+      ->fetchField();
+
+    // Add in the default vocabulary.
+    if (!$cdi) {
+      db_insert('tripal_cv_defaults')
+        ->fields(array(
+          'table_name' => 'organismprop',
+          'field_name' => 'type_id',
+          'cv_id' => $cv_id
+        ))
+        ->execute();
+    }
   }
   }
   catch (\PDOException $e) {
   catch (\PDOException $e) {
     $error = $e->getMessage();
     $error = $e->getMessage();

+ 30 - 14
tripal_project/tripal_project.install

@@ -153,13 +153,21 @@ function tripal_project_update_7200() {
         ->execute();
         ->execute();
     }
     }
     // use the new project_property CV we just added
     // use the new project_property CV we just added
-    db_insert('tripal_cv_defaults')
-      ->fields(array(
-      'table_name' => 'projectprop',
-      'field_name' => 'type_id',
-      'cv_id' => $cv_id
-      ))
-      ->execute();
+    $cdi = db_select('tripal_cv_defaults', 't')
+      ->fields('t', array('cv_default_id'))
+      ->condition('table_name', 'projectprop')
+      ->condition('field_name', 'type_id')
+      ->execute()
+      ->fetchField();
+    if (!$cdi) {
+      db_insert('tripal_cv_defaults')
+        ->fields(array(
+        'table_name' => 'projectprop',
+        'field_name' => 'type_id',
+        'cv_id' => $cv_id
+        ))
+        ->execute();
+    }
   }
   }
   catch (\PDOException $e) {
   catch (\PDOException $e) {
     $error = $e->getMessage();
     $error = $e->getMessage();
@@ -179,13 +187,21 @@ function tripal_project_update_7200() {
       ->execute();
       ->execute();
     }
     }
     // use the new project_property CV we just added
     // use the new project_property CV we just added
-    db_insert('tripal_cv_defaults')
-      ->fields(array(
-        'table_name' => 'project_relationship',
-        'field_name' => 'type_id',
-        'cv_id' => $cv_id
-      ))
-      ->execute();
+    $cdi = db_select('tripal_cv_defaults', 't')
+      ->fields('t', array('cv_default_id'))
+      ->condition('table_name', 'project_relationship')
+      ->condition('field_name', 'type_id')
+      ->execute()
+      ->fetchField();
+    if (!$cdi) {
+      db_insert('tripal_cv_defaults')
+        ->fields(array(
+          'table_name' => 'project_relationship',
+          'field_name' => 'type_id',
+          'cv_id' => $cv_id
+        ))
+        ->execute();
+    }
   }
   }
   catch (\PDOException $e) {
   catch (\PDOException $e) {
     $error = $e->getMessage();
     $error = $e->getMessage();

+ 46 - 21
tripal_pub/tripal_pub.install

@@ -296,21 +296,38 @@ function tripal_pub_update_7200() {
         ->execute();
         ->execute();
     }
     }
     // use the new pub_property CV we just added
     // use the new pub_property CV we just added
-    db_insert('tripal_cv_defaults')
-      ->fields(array(
-        'table_name' => 'pub',
-        'field_name' => 'type_id',
-        'cv_id' => $cv_id
-      ))
-      ->execute();
+    $cdi = db_select('tripal_cv_defaults', 't')
+      ->fields('t', array('cv_default_id'))
+      ->condition('table_name', 'pub')
+      ->condition('field_name', 'type_id')
+      ->execute()
+      ->fetchField();
+    if (!$cdi) {
+      db_insert('tripal_cv_defaults')
+        ->fields(array(
+          'table_name' => 'pub',
+          'field_name' => 'type_id',
+          'cv_id' => $cv_id
+        ))
+        ->execute();
+    }
+
     // use the new pub_property CV we just added
     // use the new pub_property CV we just added
-    db_insert('tripal_cv_defaults')
-      ->fields(array(
-        'table_name' => 'pubprop',
-        'field_name' => 'type_id',
-        'cv_id' => $cv_id
-      ))
-      ->execute();
+    $cdi = db_select('tripal_cv_defaults', 't')
+      ->fields('t', array('cv_default_id'))
+      ->condition('table_name', 'pubprop')
+      ->condition('field_name', 'type_id')
+      ->execute()
+      ->fetchField();
+    if (!$cdi) {
+      db_insert('tripal_cv_defaults')
+        ->fields(array(
+          'table_name' => 'pubprop',
+          'field_name' => 'type_id',
+          'cv_id' => $cv_id
+        ))
+        ->execute();
+    }
   }
   }
   catch (\PDOException $e) {
   catch (\PDOException $e) {
     $error = $e->getMessage();
     $error = $e->getMessage();
@@ -366,13 +383,21 @@ function tripal_pub_update_7200() {
       ->execute();
       ->execute();
     }
     }
     // use the new pub_property CV we just added
     // use the new pub_property CV we just added
-    db_insert('tripal_cv_defaults')
-      ->fields(array(
-        'table_name' => 'pub_relationship',
-        'field_name' => 'type_id',
-        'cv_id' => $cv_id
-      ))
-      ->execute();
+    $cdi = db_select('tripal_cv_defaults', 't')
+      ->fields('t', array('cv_default_id'))
+      ->condition('table_name', 'pub_relationship')
+      ->condition('field_name', 'type_id')
+      ->execute()
+      ->fetchField();
+    if (!$cdi) {
+      db_insert('tripal_cv_defaults')
+        ->fields(array(
+          'table_name' => 'pub_relationship',
+          'field_name' => 'type_id',
+          'cv_id' => $cv_id
+        ))
+        ->execute();
+    }
   }
   }
   catch (\PDOException $e) {
   catch (\PDOException $e) {
     $error = $e->getMessage();
     $error = $e->getMessage();

+ 45 - 21
tripal_stock/tripal_stock.install

@@ -230,13 +230,21 @@ function tripal_stock_update_7200() {
     // for backwards compatibility, get the previously set stock relationship CV, otherwise
     // for backwards compatibility, get the previously set stock relationship CV, otherwise
     // use the new stock_relationship CV we just added
     // use the new stock_relationship CV we just added
     $default_stockrel_cv = variable_get('chado_stock_relationship_cv', $cv_id);
     $default_stockrel_cv = variable_get('chado_stock_relationship_cv', $cv_id);
-    db_insert('tripal_cv_defaults')
-      ->fields(array(
-        'table_name' => 'stock_relationship',
-        'field_name' => 'type_id',
-        'cv_id' => $default_stockrel_cv
-      ))
-      ->execute();
+    $cdi = db_select('tripal_cv_defaults', 't')
+      ->fields('t', array('cv_default_id'))
+      ->condition('table_name', 'stock_relationship')
+      ->condition('field_name', 'type_id')
+      ->execute()
+      ->fetchField();
+    if (!$cdi) {
+      db_insert('tripal_cv_defaults')
+        ->fields(array(
+          'table_name' => 'stock_relationship',
+          'field_name' => 'type_id',
+          'cv_id' => $default_stockrel_cv
+        ))
+        ->execute();
+    }
   }
   }
   catch (\PDOException $e) {
   catch (\PDOException $e) {
     $error = $e->getMessage();
     $error = $e->getMessage();
@@ -258,13 +266,21 @@ function tripal_stock_update_7200() {
     // for backwards compatibility, get the previously set stock property CV, otherwise
     // for backwards compatibility, get the previously set stock property CV, otherwise
     // use the new stock_property CV we just added
     // use the new stock_property CV we just added
     $default_stockprop_cv = variable_get('chado_stock_prop_types_cv', $cv_id);
     $default_stockprop_cv = variable_get('chado_stock_prop_types_cv', $cv_id);
-    db_insert('tripal_cv_defaults')
-      ->fields(array(
-      'table_name' => 'stockprop',
-      'field_name' => 'type_id',
-      'cv_id' => $default_stockprop_cv
-      ))
-      ->execute();
+    $cdi = db_select('tripal_cv_defaults', 't')
+      ->fields('t', array('cv_default_id'))
+      ->condition('table_name', 'stockprop')
+      ->condition('field_name', 'type_id')
+      ->execute()
+      ->fetchField();
+    if (!$cdi) {
+      db_insert('tripal_cv_defaults')
+        ->fields(array(
+        'table_name' => 'stockprop',
+        'field_name' => 'type_id',
+        'cv_id' => $default_stockprop_cv
+        ))
+        ->execute();
+    }
   }
   }
   catch (\PDOException $e) {
   catch (\PDOException $e) {
     $error = $e->getMessage();
     $error = $e->getMessage();
@@ -287,13 +303,21 @@ function tripal_stock_update_7200() {
     // for backwards compatibility, get the previously set stock types CV, otherwise
     // for backwards compatibility, get the previously set stock types CV, otherwise
     // use the new stock_type CV we just added
     // use the new stock_type CV we just added
     $default_stocktype_cv = variable_get('chado_stock_types_cv', $cv_id);
     $default_stocktype_cv = variable_get('chado_stock_types_cv', $cv_id);
-    db_insert('tripal_cv_defaults')
-      ->fields(array(
-      'table_name' => 'stock',
-      'field_name' => 'type_id',
-      'cv_id' => $default_stocktype_cv
-      ))
-      ->execute();
+    $cdi = db_select('tripal_cv_defaults', 't')
+      ->fields('t', array('cv_default_id'))
+      ->condition('table_name', 'stock')
+      ->condition('field_name', 'type_id')
+      ->execute()
+      ->fetchField();
+    if (!$cdi) {
+      db_insert('tripal_cv_defaults')
+        ->fields(array(
+        'table_name' => 'stock',
+        'field_name' => 'type_id',
+        'cv_id' => $default_stocktype_cv
+        ))
+        ->execute();
+    }
   }
   }
   catch (\PDOException $e) {
   catch (\PDOException $e) {
     $error = $e->getMessage();
     $error = $e->getMessage();