Procházet zdrojové kódy

Merge branch '7.x-2.x' of git.drupal.org:sandbox/spficklin/1337878 into 7.x-2.x

Lacey Sanderson před 11 roky
rodič
revize
13ac267aa7

+ 37 - 0
tripal_contact/tripal_contact.install

@@ -356,4 +356,41 @@ function tripal_contact_update_dependencies() {
   );
 
   return $dependencies;
+}
+
+/**
+ * Adds missing foreign key constraints
+ *
+ */
+function tripal_contact_update_7201() {
+  // there was a bug in the function for creating a custom table that 
+  // kept foreign key constraints from being added.  So, we need to add those
+  // to keep from error messages appear, we will drop the FK if it already 
+  // exists and then re-add it.
+  try {
+    db_query('
+      ALTER TABLE chado.contactprop
+      DROP CONSTRAINT IF EXISTS contactprop_type_id_fkey CASCADE
+    ');
+    db_query('
+      ALTER TABLE chado.contactprop
+      DROP CONSTRAINT IF EXISTS contactprop_contact_id_fkey CASCADE
+    ');
+    db_query('
+      ALTER TABLE chado.contactprop
+      ADD CONSTRAINT contactprop_type_id_fkey
+      FOREIGN KEY (type_id) REFERENCES chado.cvterm (cvterm_id)
+      ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED
+    ');
+    db_query('
+      ALTER TABLE chado.contactprop
+      ADD CONSTRAINT contactprop_contact_id_fkey
+      FOREIGN KEY (contact_id) REFERENCES chado.contact (contact_id)
+      ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED
+    ');
+  }
+  catch (\PDOException $e) {
+    $error = $e->getMessage();
+    throw new DrupalUpdateException('Failed to update foriegn key: '. $error);
+  }
 }

+ 51 - 55
tripal_core/api/tripal_core.custom_tables.api.inc

@@ -22,67 +22,63 @@
  *   The name of the custom table
  * @param $schema
  *   Use the Schema API array to define the custom table.
- * @param $skip_creation
+ * @param $skip_if_exists
  *   Set as TRUE to skip dropping and re-creation of the table.  This is
  *   useful if the table was already created through another means and you
  *   simply want to make Tripal aware of the table schema.
  *
  * @ingroup tripal_custom_tables_api
  */
-function chado_edit_custom_table($table_id, $table_name, $schema, $skip_creation = 1) {
+function chado_edit_custom_table($table_id, $table_name, $schema, $skip_if_exists = 1) {
 
-  // Create a new record
-  $record = new stdClass();
-  $record->table_id = $table_id;
-  $record->table_name = $table_name;
-  $record->schema = serialize($schema);
-
-  // get the current custom table record
-  $sql = "SELECT * FROM {tripal_custom_tables} WHERE table_id = :table_id";
-  $results = db_query($sql, array(':table_id' => $table_id));
-  $custom_table = $results->fetchObject();
-
-  // if this is a materialized view then don't allow editing with this function
-  if ($custom_table->mview_id) {
-    tripal_report_error('tripal_core', TRIPAL_ERROR, "Please use the tripal_edit_mview() function to edit this custom table as it is a materialized view.", array());
-    drupal_set_message("This custom table is a materialized view. Please use the "  . l('Materialized View', 'admin/tripal/schema/mviews') . " interface to edit it.", 'error');
-    return FALSE;
-  }
+  $transaction = db_transaction();
+  try {
+    // Create a new record
+    $record = new stdClass();
+    $record->table_id = $table_id;
+    $record->table_name = $table_name;
+    $record->schema = serialize($schema);
   
-  // if the user changed the table name, we want to drop the old one and force
-  // creation of the new one.
-  if ($custom_table->table_name != $table_name) {
-    chado_query("DROP TABLE %s", $custom_table->table_name);
-    $skip_creation = 0; // we want to create the table
-  }
-
-  // if skip creation is not set, then drop the table from chado if it exists
-  if (!$skip_creation) {
-    if (db_table_exists($custom_table->table_name)) {
+    // get the current custom table record
+    $sql = "SELECT * FROM {tripal_custom_tables} WHERE table_id = :table_id";
+    $results = db_query($sql, array(':table_id' => $table_id));
+    $custom_table = $results->fetchObject();
+  
+    // if this is a materialized view then don't allow editing with this function
+    if ($custom_table->mview_id) {
+      tripal_report_error('tripal_core', TRIPAL_ERROR, "Please use the tripal_edit_mview() function to edit this custom table as it is a materialized view.", array());
+      drupal_set_message("This custom table is a materialized view. Please use the "  . l('Materialized View', 'admin/tripal/schema/mviews') . " interface to edit it.", 'error');
+      return FALSE;
+    }
+    
+    // if the user changed the table name, we want to drop the old one and force
+    // creation of the new one.
+    if ($custom_table->table_name != $table_name) {
       chado_query("DROP TABLE %s", $custom_table->table_name);
-      drupal_set_message(t("Custom Table '%name' dropped", array('%name' => $custom_table->table_name)));
+      $skip_if_exists = 0; // we want to create the table
     }
-  }
-
-  // update the custom table record and re-create the table in Chado
-  if (drupal_write_record('tripal_custom_tables', $record, 'table_id')) {
-
-    // drop the table from chado if it exists
-    if (!$skip_creation) {
+  
+    // if skip creation is not set, then drop the table from chado if it exists
+    if (!$skip_if_exists) {
       if (db_table_exists($custom_table->table_name)) {
         chado_query("DROP TABLE %s", $custom_table->table_name);
-        drupal_set_message(t("Custom Table '%name' dropped", array('%name' => $custom_table->table_name)));
-      }
-
-      // re-create the table
-      if (!chado_create_custom_table ($table_name, $schema)) {
-        drupal_set_message(t("Could not create the custom table. Check Drupal error report logs."));
-      }
-      else {
-        drupal_set_message(t("Custom table '%name' created", array('%name' => $table_name)));
+        drupal_set_message(t("Custom Table " . $custom_table->table_name . " dropped"));
       }
     }
+  
+    // update the custom table record and run the create custom table function
+    drupal_write_record('tripal_custom_tables', $record, 'table_id');
+    $success = chado_create_custom_table ($table_name, $schema, $skip_if_exists);
   }
+  catch (Exception $e) {
+    $transaction->rollback();
+    watchdog_exception('tripal_core', $e);
+    $error = _drupal_decode_exception($e);
+    drupal_set_message(t("Could not update custom table '%table_name': %message.",
+    array('%table_name' => $table, '%message' => $error['!message'])), 'error');
+    return FALSE;
+  }
+  return TRUE;
 }
 
 /**
@@ -92,7 +88,7 @@ function chado_edit_custom_table($table_id, $table_name, $schema, $skip_creation
  * exists then it will be dropped and recreated using the schema provided.
  * However, it will only drop a table if it exsits in the tripal_custom_tables
  * table. This way the function cannot be used to accidentally alter existing
- * non custom tables.  If $skip_creation is set then the table is simply
+ * non custom tables.  If $skip_if_exists is set then the table is simply
  * added to the tripal_custom_tables and no table is created in Chado.
  * 
  * If you are creating a materialized view do not use this function, but rather 
@@ -107,7 +103,7 @@ function chado_edit_custom_table($table_id, $table_name, $schema, $skip_creation
  *   The name of the table to create.
  * @param $schema
  *   A Drupal-style Schema API definition of the table
- * @param $skip_creation
+ * @param $skip_if_exists
  *   Set as TRUE to skip dropping and re-creation of the table if it already
  *   exists.  This is useful if the table was already created through another
  *   means and you simply want to make Tripal aware of the table schema.  If the
@@ -122,7 +118,7 @@ function chado_edit_custom_table($table_id, $table_name, $schema, $skip_creation
  *
  * @ingroup tripal_custom_tables_api
  */
-function chado_create_custom_table($table, $schema, $skip_creation = 1, $mview_id = NULL) {
+function chado_create_custom_table($table, $schema, $skip_if_exists = 1, $mview_id = NULL) {
   global $databases;
   $created = 0;
   $recreated = 0;
@@ -145,7 +141,7 @@ function chado_create_custom_table($table, $schema, $skip_creation = 1, $mview_i
   
     // if the table exists in Chado and in our custom table and
     // skip creation is turned off then drop and re-create the table
-    if ($exists and is_object($centry) and !$skip_creation) {
+    if ($exists and is_object($centry) and !$skip_if_exists) {
   
       // drop the table we'll recreate it with the new schema
       chado_query('DROP TABLE {' . $table . '}');
@@ -172,9 +168,9 @@ function chado_create_custom_table($table, $schema, $skip_creation = 1, $mview_i
       db_query($sql, array(':table_name' => $table));
     }
     $success = drupal_write_record('tripal_custom_tables', $record); 
-  
+
     // now add any foreign key constraints
-    if (!$skip_creation and array_key_exists('foreign keys', $schema)) {
+    if (($created or !$skip_if_exists) and array_key_exists('foreign keys', $schema)) {
   
       // iterate through the foreign keys and add each one
       $fkeys = $schema['foreign keys'];
@@ -201,13 +197,13 @@ function chado_create_custom_table($table, $schema, $skip_creation = 1, $mview_i
     return FALSE;
   }
   if ($created) {
-    drupal_set_message("Custom table created successfully.", 'status');
+    drupal_set_message("Custom table, '" . $table . "' ,  created successfully.", 'status');
   }
   elseif ($recreated) {
-    drupal_set_message("Custom table re-created successfully.", 'status');
+    drupal_set_message("Custom table, '" . $table . "' ,  re-created successfully.", 'status');
   }
   else {
-    drupal_set_message("Custom table already exists. Table structure not changed, but definition array has been saved.", 'status');
+    drupal_set_message("Custom table, '" . $table . "' , already exists. Table structure not changed, but definition array has been saved.", 'status');
   }
   return TRUE;
 }

+ 49 - 85
tripal_core/api/tripal_core.mviews.api.inc

@@ -211,60 +211,49 @@ function tripal_add_mview($name, $modulename, $mv_schema, $query, $comment = NUL
 function tripal_edit_mview($mview_id, $name, $modulename, $mv_table, $mv_specs,
   $indexed, $query, $special_index, $comment = NULL, $mv_schema = NULL) {
 
-  // get the table name from the schema array
-  $schema_arr = array();
-  if ($mv_schema) {
-    // get the schema from the mv_specs and use it to add the custom table
-    eval("\$schema_arr = $mv_schema;");
-    $mv_table = $schema_arr['table'];
-  }
-
-  $record = new stdClass();
-  $record->mview_id = $mview_id;
-  $record->name = $name;
-  $record->modulename = $modulename;
-  $record->query = $query;
-  $record->last_update = 0;
-  $record->status = '';
-  $record->comment = $comment;
-
-  // get the view before we update and check to see if the table structure has
-  // changed. IF so, then we want to drop and recreate the table. If not, then
-  // just save the updated SQL.
-  $create_table = 1;
-  $sql = "SELECT * FROM {tripal_mviews} WHERE mview_id = :mview_id";
-  $results = db_query($sql, array(':mview_id' => $mview_id));
-  $mview = $results->fetchObject();
-  if ($mview->mv_schema == $mv_schema and $mview->mv_table == $mv_table and
-     $mview->mv_specs == $mv_specs and $mview->indexed == $indexed and
-     $mview->special_index == $special_index) {
-    // nothing has changed so simpy update the SQL and other fields
-    $create_table = 0;
-  }
-  else {
-    // add in the table structure fields
-    $record->mv_schema = $mv_schema;
-    $record->mv_table = $mv_table;
-    $record->mv_specs = $mv_specs;
-    $record->indexed = $indexed;
-    $record->query = $query;
-    $record->special_index = $special_index;
-  }
-
-  // if we are going to create the table then we must first drop it if it exists
-  if ($create_table) {
-    $previous_db = chado_set_active('chado');  // use chado database
-    if (db_table_exists($mview->mv_table)) {
-      $sql = "DROP TABLE :table_name";
-      db_query($sql, array(':table_name' => $mview->mv_table));
-      drupal_set_message(t("View '%name' dropped", array('%name' => $name)));
+  $transaction = db_transaction();
+  try {
+    // get the table name from the schema array
+    $schema_arr = array();
+    if ($mv_schema) {
+      // get the schema from the mv_specs and use it to add the custom table
+      eval("\$schema_arr = $mv_schema;");
+      $mv_table = $schema_arr['table'];
     }
-    chado_set_active($previous_db);  // now use drupal database
-  }
-
-  // update the record to the tripal_mviews table and if successful
-  // create the new materialized view in the chado schema
-  if (drupal_write_record('tripal_mviews', $record, 'mview_id')) {
+  
+    $record = new stdClass();
+    $record->mview_id    = $mview_id;
+    $record->name        = $name;
+    $record->modulename  = $modulename;
+    $record->query       = $query;
+    $record->last_update = 0;
+    $record->status      = '';
+    $record->comment     = $comment;
+    $record->mv_schema   = $mv_schema;
+    $record->mv_table    = $mv_table;
+    
+    // update the record to the tripal_mviews table
+    drupal_write_record('tripal_mviews', $record, 'mview_id');
+  
+    // get the view before we update and check to see if the table structure has
+    // changed. If so, then we want to drop and recreate the table. If not, then
+    // just save the updated SQL.
+    $create_table = 1;
+    $sql = "SELECT * FROM {tripal_mviews} WHERE mview_id = :mview_id";
+    $results = db_query($sql, array(':mview_id' => $mview_id));
+    $mview = $results->fetchObject();
+    if ($mview->mv_schema == $mv_schema and $mview->mv_table == $mv_table) {
+      chado_create_custom_table($mv_table, $schema_arr, 0, $record->mview_id);
+        drupal_set_message(t("Materialized view '%name' created", array('%name' => $name)));
+    }
+    else {
+      $message = "View '%name' updated.  All records remain. ";
+      if ($query != $mview->query) {
+        $message .= "Please repopulate the view to use the updated query.";
+      }
+      drupal_set_message(t($message, array('%name' => $name)));
+    }
+      
     // construct the indexes SQL if needed
     $index = '';
     if ($indexed) {
@@ -277,39 +266,14 @@ function tripal_edit_mview($mview_id, $name, $modulename, $mv_table, $mv_specs,
       }
     }
 
-    // re-create the table differently depending on if it the traditional method
-    // or the Drupal Schema API method
-    if ($create_table and $mv_schema) {
-      if (!chado_create_custom_table($mv_table, $schema_arr, 0, $record->mview_id)) {
-        drupal_set_message(t("Could not create the materialized view. Check Drupal error report logs."));
-      }
-      else {
-        drupal_set_message(t("Materialized view '%name' created", array('%name' => $name)));
-      }
-    }
-    if ($create_table and !$mv_schema) {
-      $sql = "CREATE TABLE {$mv_table} ($mv_specs); $index";
-      $results = chado_query($sql);
-      if ($results) {
-        drupal_set_message(t("Materialized view '%name' created.  All records cleared. Please re-populate the view.",
-          array('%name' => $name)));
-      }
-      else {
-        drupal_set_message(t("Failed to create the materialized view table: '%mv_table'",
-          array('%mv_table' => $mv_table)), 'error');
-      }
-    }
-    if (!$create_table) {
-      $message = "View '%name' updated.  All records remain. ";
-      if ($query != $mview->query) {
-        $message .= "Please repopulate the view to use updated query.";
-      }
-      drupal_set_message(t($message, array('%name' => $name)));
-    }
   }
-  else {
-    drupal_set_message(t("Failed to update the materialized view: '%mv_table'",
-      array('%mv_table' => $mv_table)), 'error');
+  catch (Exception $e) {
+    $transaction->rollback();
+    watchdog_exception('tripal_core', $e);
+    $error = _drupal_decode_exception($e);
+    drupal_set_message(t("Could not update materialized view '%table_name': %message.",
+    array('%table_name' => $mv_table, '%message' => $error['!message'])), 'error');
+    return FALSE;
   }
 }
 

+ 1 - 1
tripal_core/includes/tripal_core.custom_tables.inc

@@ -142,7 +142,7 @@ function tripal_custom_tables_form($form, &$form_state = NULL, $table_id = NULL)
     $custom_table = $results->fetchObject();
     
     // if this is a materialized view then don't allow editing with this function
-    if ($custom_table->mview_id) {
+    if (property_exists($custom_table, 'mview_id') and $custom_table->mview_id) {
       drupal_set_message("This custom table is a materialized view. Please use the "  . l('Materialized View', 'admin/tripal/schema/mviews') . " interface to edit it.", 'error');
       drupal_goto("admin/tripal/schema/custom_tables");
       return array();

+ 4 - 4
tripal_core/includes/tripal_core.mviews.inc

@@ -304,10 +304,7 @@ function tripal_mviews_form($form, &$form_state = NULL, $mview_id = NULL) {
     $form['traditional'] = array(
       '#type' => 'fieldset',
       '#title' => 'Legacy MViews Setup',
-      '#description' => t('Traditionally MViews were created by specifying PostgreSQL style ' .
-                         'column types.  This method can be used but is deprecated in favor of the ' .
-                         'newer Drupal schema API method provided above. In rare cases where the Drupal Schema API ' .
-                         'does not support a desired data type the Legacy Mviews should be used'),
+      '#description' => t('<font color="red">Tripal no longer supports editing of legacy style materialized views. </font> This view will continue to function and you can populate it, however, to update you must convert this view to the newer Drupal Schema API format using the "Table Schema" section above.  Unfortunately, after converting this view to the Schema API and saving, the materialized view be recreated and emptied. You will need to re-populate it. Therefore, you may want to schedule update of this or any other legacy materialized during your next site maintenance.'),
       '#collapsible' => 1,
       '#collapsed' => $traditional_collapsed,
     );
@@ -318,6 +315,7 @@ function tripal_mviews_form($form, &$form_state = NULL, $mview_id = NULL) {
       '#description'   => t('Please enter the table name that this view will generate in the database.  You can use the schema and table name for querying the view'),
       '#required'      => FALSE,
       '#default_value' => $default_mv_table,
+      '#attributes'   => array('disabled' => 'disabled'),
     );
 
     $form['traditional']['mv_specs']= array(
@@ -326,6 +324,7 @@ function tripal_mviews_form($form, &$form_state = NULL, $mview_id = NULL) {
       '#description'   => t('Please enter the field definitions for this view. Each field should be separated by a comma or enter each field definition on each line.'),
       '#required'      => FALSE,
       '#default_value' => $default_mv_specs,
+      '#attributes'   => array('disabled' => 'disabled'),
     );
 
     $form['traditional']['indexed']= array(
@@ -334,6 +333,7 @@ function tripal_mviews_form($form, &$form_state = NULL, $mview_id = NULL) {
       '#description'   => t('Please enter the field names (as provided in the table definition above) that will be indexed for this view.  Separate by a comma or enter each field on a new line.'),
       '#required'      => FALSE,
       '#default_value' => $default_indexed,
+      '#attributes'    => array('disabled' => 'disabled'),
     );
 
     /**

+ 3 - 3
tripal_core/tripal_core.install

@@ -67,9 +67,9 @@ function tripal_core_uninstall() {
   // drop the foreign key between tripal_custom_tables and tripal_mviews
   // so that Drupal can then drop the tables
   db_query('
-      ALTER TABLE {tripal_custom_tables}
-      DROP CONSTRAINT IF EXISTS tripal_custom_tables_fk1 CASCADE
-    ');
+    ALTER TABLE {tripal_custom_tables}
+    DROP CONSTRAINT IF EXISTS tripal_custom_tables_fk1 CASCADE
+  ');
 }
 
 /**

+ 82 - 0
tripal_featuremap/tripal_featuremap.install

@@ -509,4 +509,86 @@ function tripal_featuremap_update_dependencies() {
   );
 
   return $dependencies;
+}
+
+/**
+ * Adds missing foreign key constraints
+ *
+ */
+function tripal_featuremap_update_7201() {
+  // there was a bug in the function for creating a custom table that
+  // kept foreign key constraints from being added.  So, we need to add those
+  // to keep from error messages appear, we will drop the FK if it already
+  // exists and then re-add it.
+  try {
+    // featuremapprop table
+    db_query('
+      ALTER TABLE chado.featuremapprop
+      DROP CONSTRAINT IF EXISTS featuremapprop_type_id_fkey CASCADE
+    ');
+    db_query('
+      ALTER TABLE chado.featuremapprop
+      DROP CONSTRAINT IF EXISTS featuremapprop_featuremap_id_fkey CASCADE
+    ');
+    db_query('
+      ALTER TABLE chado.featuremapprop
+      ADD CONSTRAINT featuremapprop_type_id_fkey
+      FOREIGN KEY (type_id) REFERENCES chado.cvterm (cvterm_id)
+      ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED
+    ');
+    db_query('
+      ALTER TABLE chado.featuremapprop
+      ADD CONSTRAINT featuremapprop_featuremap_id_fkey
+      FOREIGN KEY (featuremap_id) REFERENCES chado.featuremap (featuremap_id)
+      ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED
+    ');
+    
+    // featuremap_dbref table
+    db_query('
+      ALTER TABLE chado.featuremap_dbxref
+      DROP CONSTRAINT IF EXISTS featuremap_dbxref_dbxref_id_fkey CASCADE
+    ');
+    db_query('
+      ALTER TABLE chado.featuremap_dbxref
+      DROP CONSTRAINT IF EXISTS featuremap_dbxref_featuremap_id_fkey CASCADE
+    ');
+    db_query('
+      ALTER TABLE chado.featuremap_dbxref
+      ADD CONSTRAINT featuremap_dbxref_dbxref_id_fkey
+      FOREIGN KEY (dbxref_id) REFERENCES chado.dbxref (dbxref_id)
+      ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED
+    ');
+    db_query('
+      ALTER TABLE chado.featuremap_dbxref
+      ADD CONSTRAINT featuremap_dbxref_featuremap_id_fkey
+      FOREIGN KEY (featuremap_id) REFERENCES chado.featuremap (featuremap_id)
+      ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED
+    ');
+    
+    // featureposprop
+    db_query('
+      ALTER TABLE chado.featureposprop
+      DROP CONSTRAINT IF EXISTS featureposprop_type_id_fkey CASCADE
+    ');
+    db_query('
+      ALTER TABLE chado.featureposprop
+      DROP CONSTRAINT IF EXISTS featureposprop_featurepos_id_fkey CASCADE
+    ');
+    db_query('
+      ALTER TABLE chado.featureposprop
+      ADD CONSTRAINT featureposprop_type_id_fkey
+      FOREIGN KEY (type_id) REFERENCES chado.cvterm (cvterm_id)
+      ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED
+    ');
+    db_query('
+      ALTER TABLE chado.featureposprop
+      ADD CONSTRAINT featureposprop_featurepos_id_fkey
+      FOREIGN KEY (featurepos_id) REFERENCES chado.featurepos (featurepos_id)
+      ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED
+    ');
+  }
+  catch (\PDOException $e) {
+    $error = $e->getMessage();
+    throw new DrupalUpdateException('Failed to update foriegn key: '. $error);
+  }
 }

+ 37 - 0
tripal_pub/tripal_pub.install

@@ -381,4 +381,41 @@ function tripal_pub_update_dependencies() {
   );
 
   return $dependencies;
+}
+
+/**
+ * Adds missing foreign key constraints
+ *
+ */
+function tripal_pub_update_7201() {
+  // there was a bug in the function for creating a custom table that
+  // kept foreign key constraints from being added.  So, we need to add those
+  // to keep from error messages appear, we will drop the FK if it already
+  // exists and then re-add it.
+  try {
+    db_query('
+      ALTER TABLE chado.pubauthor_contact
+      DROP CONSTRAINT IF EXISTS pubauthor_contact_pubauthor_id_fkey CASCADE
+    ');
+    db_query('
+      ALTER TABLE chado.pubauthor_contact
+      DROP CONSTRAINT IF EXISTS pubauthor_contact_contact_id_fkey CASCADE
+    ');
+    db_query('
+      ALTER TABLE chado.pubauthor_contact
+      ADD CONSTRAINT pubauthor_contact_pubauthor_id_fkey
+      FOREIGN KEY (pubauthor_id) REFERENCES chado.pubauthor (pubauthor_id)
+      ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED
+    ');
+    db_query('
+      ALTER TABLE chado.pubauthor_contact
+      ADD CONSTRAINT pubauthor_contact_contact_id_fkey
+      FOREIGN KEY (contact_id) REFERENCES chado.contact (contact_id)
+      ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED
+    ');
+  }
+  catch (\PDOException $e) {
+    $error = $e->getMessage();
+    throw new DrupalUpdateException('Failed to update foriegn key: '. $error);
+  }
 }