Selaa lähdekoodia

Issue #2567053: Added tripal_get_schema_name() function and hooks to allow changing of the chado schema name. Furthermore, I cleaned up all hard-coding of the chado schema name that I could find.

Lacey Sanderson 9 vuotta sitten
vanhempi
commit
1bf62fee22

+ 1 - 1
tripal_analysis/tripal_analysis.install

@@ -85,7 +85,7 @@ function tripal_analysis_create_analysisfeatureprop() {
 
 
   // Create analysisfeatureprop table in chado.  This is needed for Chado
   // Create analysisfeatureprop table in chado.  This is needed for Chado
   // version 1.11, the table exists in Chado 1.2.
   // version 1.11, the table exists in Chado 1.2.
-  if (!db_table_exists('chado.analysisfeatureprop')) {
+  if (!chado_table_exists('analysisfeatureprop')) {
     $sql = "
     $sql = "
       CREATE TABLE {analysisfeatureprop} (
       CREATE TABLE {analysisfeatureprop} (
         analysisfeatureprop_id SERIAL PRIMARY KEY,
         analysisfeatureprop_id SERIAL PRIMARY KEY,

+ 5 - 2
tripal_core/api/tripal_core.chado_general.api.inc

@@ -66,12 +66,15 @@ function chado_set_active($dbname = 'default') {
   }
   }
 
 
   $previous_db = $active_db = $GLOBALS['chado_active_db'];
   $previous_db = $active_db = $GLOBALS['chado_active_db'];
-  $search_path = 'public';
+  $search_path = tripal_get_schema_name('drupal');
 
 
   // Change only if 'chado' has been specified.
   // Change only if 'chado' has been specified.
+  // Notice that we leave the active_db set as chado but use the possibly user-altered
+  // schema name for the actual search path. This is to keep outward facing mentions of
+  // chado as "chado" while still allowing the user to alter the schema name used.
   if ($dbname == 'chado') {
   if ($dbname == 'chado') {
     $active_db = 'chado';
     $active_db = 'chado';
-    $search_path = 'chado,public';
+    $search_path = tripal_get_schema_name('chado') . ',' . tripal_get_schema_name('drupal');
   }
   }
 
 
   $settings = array(
   $settings = array(

+ 5 - 2
tripal_core/api/tripal_core.chado_nodes.relationships.api.inc

@@ -1046,7 +1046,10 @@ function chado_add_node_form_relationships_name_to_id_callback($base_table, $nam
 
 
   $base_key = $base_table.'_id';
   $base_key = $base_table.'_id';
 
 
-  $query = db_select('chado.'.$base_table, 'b')
+  // determine the chado schema.
+  $chado = tripal_get_schema_name('chado');
+
+  $query = db_select($chado.'.'.$base_table, 'b')
     ->fields('b', array($base_key, $name_field))
     ->fields('b', array($base_key, $name_field))
     ->condition($name_field, '%' . db_like($string) . '%', 'LIKE');
     ->condition($name_field, '%' . db_like($string) . '%', 'LIKE');
 
 
@@ -1065,4 +1068,4 @@ function chado_add_node_form_relationships_name_to_id_callback($base_table, $nam
 
 
   // return for JS
   // return for JS
   drupal_json_output($matches);
   drupal_json_output($matches);
-}
+}

+ 69 - 5
tripal_core/api/tripal_core.chado_query.api.inc

@@ -1510,16 +1510,16 @@ function chado_query($sql, $args = array()) {
     // Prefix the tables with their correct schema.
     // Prefix the tables with their correct schema.
     // Chado tables should be enclosed in curly brackets (ie: {feature} )
     // Chado tables should be enclosed in curly brackets (ie: {feature} )
     // and Drupal tables should be enclosed in square brackets (ie: [tripal_jobs] ).
     // and Drupal tables should be enclosed in square brackets (ie: [tripal_jobs] ).
-    // @todo: remove assumption that the chado schema is called 'chado' and the
-    // drupal schema is called 'public'.
-    $sql = preg_replace('/\{(.*?)\}/', 'chado.$1', $sql);
-    $sql = preg_replace('/\[(\w+)\]/', 'public.$1', $sql);
+    $chado_schema_name = tripal_get_schema_name('chado');
+    $drupal_schema_name = tripal_get_schema_name('drupal');
+    $sql = preg_replace('/\{(.*?)\}/', $chado_schema_name.'.$1', $sql);
+    $sql = preg_replace('/\[(\w+)\]/', $drupal_schema_name.'.$1', $sql);
 
 
     // The featureloc table has some indexes that use function that call other
     // The featureloc table has some indexes that use function that call other
     // functions and those calls do not reference a schema, therefore, any
     // functions and those calls do not reference a schema, therefore, any
     // tables with featureloc must automaticaly have the chado schema set as
     // tables with featureloc must automaticaly have the chado schema set as
     // active to find.
     // active to find.
-    if (preg_match('/chado.featureloc/i', $sql) or preg_match('/chado.feature/i', $sql)) {
+    if (preg_match('/'.$chado_schema_name.'.featureloc/i', $sql) or preg_match('/'.$chado_schema_name.'.feature/i', $sql)) {
       $previous_db = chado_set_active('chado') ;
       $previous_db = chado_set_active('chado') ;
       $results = db_query($sql, $args);
       $results = db_query($sql, $args);
       chado_set_active($previous_db);
       chado_set_active($previous_db);
@@ -1609,6 +1609,7 @@ function chado_pager_query($query, $args, $limit, $element, $count_query = '') {
   $results = chado_query($query, $args);
   $results = chado_query($query, $args);
   return $results;
   return $results;
 }
 }
+
 /**
 /**
  * A function to retrieve the total number of records for a pager that
  * A function to retrieve the total number of records for a pager that
  * was generated using the chado_pager_query() function
  * was generated using the chado_pager_query() function
@@ -1749,3 +1750,66 @@ function chado_schema_get_foreign_key($table_desc, $field, $values, $options = N
 
 
   return array();
   return array();
 }
 }
+
+/**
+ * Retrieve the name of the PostgreSQL schema housing Chado or Drupal.
+ *
+ * @param $schema
+ *   Wehter you want the schema name for 'chado' or 'drupal'. Chado is the default.
+ * @return
+ *   The name of the PostgreSQL schema housing the $schema specified.
+ */
+function tripal_get_schema_name($schema = 'chado') {
+
+  // First we will set our default. This is what will be returned in most cases.
+  if ($schema == 'chado') {
+    $schema_name = 'chado';
+  }
+  else {
+    $schema_name = 'public';
+  }
+
+  // There are cases where modules or admin might need to change the default
+  // names for the schema. Thus we provide an alter hook here to allow
+  // the names to be changed and ensure that schema names are never hardcoded
+  // directly into queries.
+  $context = array('schema' => $schema);
+  drupal_alter('tripal_get_schema_name', $schema_name, $context);
+
+  return $schema_name;
+}
+
+/**
+ * Alter the name of the schema housing Chado and/or Drupal.
+ *
+ * This example implementation shows a solution for the case where your chado database
+ * was well established in the "public" schema and you added Drupal later in a
+ * "drupal" schema. Please note that this has not been tested and while we can ensure
+ * that Tripal will work as expected, we have no control over whether Drupal is
+ * compatible with not being in the public schema. That's why we recommened the
+ * organization we have (ie: Chado in a "chado" schema and Drupal in the "public schema).
+ *
+ * @param $schema_name
+ *   The current name of the schema as known by Tripal. This is likely the default
+ *   set in tripal_get_schema_name() but in the case of multiple alter hooks, it might
+ *   be different.
+ * @param $context
+ *   This is an array of items to provide context.
+ *     - schema: this is the schema that was passed to tripal_get_schema_name() and will
+ *       be either "chado" or "drupal". This should be used to determine you are changing
+ *       the name of the correct schema.
+ */
+function hook_tripal_get_schema_name_alter($schema_name, $context) {
+
+  // First we check which schema was passed to chado_get_schema().
+  // Notice that we do not use $schema_name since it may already have
+  // been altered by another module.
+  if ($context['schema'] == 'chado') {
+    $schema_name = 'public';
+  }
+  // Notice that we use elseif to capture the second case rather than else. This
+  // avoids the assumption that there is only one chado and one drupal schema.
+  elseif ($context['schema'] == 'drupal') {
+    $schema_name = 'drupal';
+  }
+}

+ 13 - 10
tripal_core/api/tripal_core.chado_schema.api.inc

@@ -30,8 +30,10 @@
  * is necessary because Drupa's db_table_exists will not
  * is necessary because Drupa's db_table_exists will not
  * look in any other schema but the one were Drupal is installed
  * look in any other schema but the one were Drupal is installed
  *
  *
+ * @param $table
+ *   The name of the chado table whose existence should be checked.
  * @return
  * @return
- *   TRUE/FALSE depending upon whether it exists
+ *   TRUE if the table exists in the chado schema and FALSE if it does not.
  *
  *
  * @ingroup tripal_chado_schema_api
  * @ingroup tripal_chado_schema_api
  */
  */
@@ -45,10 +47,10 @@ function chado_table_exists($table) {
     FROM information_schema.tables
     FROM information_schema.tables
     WHERE
     WHERE
       table_name = :table_name AND
       table_name = :table_name AND
-      table_schema = 'chado' AND
-      table_catalog = '$default_db'
+      table_schema = :chado AND
+      table_catalog = :default_db
   ";
   ";
-  $results = db_query($sql, array(':table_name' => $table));
+  $results = db_query($sql, array(':table_name' => $table, ':chado' => tripal_get_schema_name('chado'), ':default_db' => $default_db));
   $exists = $results->fetchObject();
   $exists = $results->fetchObject();
   if (!$exists) {
   if (!$exists) {
     return FALSE;
     return FALSE;
@@ -152,9 +154,9 @@ function chado_is_local() {
     FROM pg_namespace
     FROM pg_namespace
     WHERE
     WHERE
       has_schema_privilege(nspname, 'USAGE') AND
       has_schema_privilege(nspname, 'USAGE') AND
-      nspname = 'chado'
+      nspname = :chado
   ";
   ";
-  $results = db_query($sql);
+  $results = db_query($sql, array(':chado' => tripal_get_schema_name('chado')));
   $name = $results->fetchObject();
   $name = $results->fetchObject();
   if ($name) {
   if ($name) {
     variable_set('chado_schema_exists', FALSE);
     variable_set('chado_schema_exists', FALSE);
@@ -178,7 +180,7 @@ function chado_is_installed() {
   global $databases;
   global $databases;
 
 
   // first check if chado is in the $databases variable of the settings.php file
   // first check if chado is in the $databases variable of the settings.php file
-  if (array_key_exists('chado', $databases)) {
+  if (array_key_exists(tripal_get_schema_name('chado'), $databases)) {
     return TRUE;
     return TRUE;
   }
   }
 
 
@@ -220,7 +222,7 @@ function chado_get_version($exact = FALSE, $warn_if_unsupported = FALSE) {
   if (!$chado_exists) {
   if (!$chado_exists) {
     // if it's not in the drupal database check to see if it's specified in the $db_url
     // if it's not in the drupal database check to see if it's specified in the $db_url
     // in the settings.php
     // in the settings.php
-    if (!array_key_exists('chado', $databases)) {
+    if (!array_key_exists(tripal_get_schema_name('chado'), $databases)) {
       // if it's not in the drupal database or specified in the $db_url then
       // if it's not in the drupal database or specified in the $db_url then
       // return uninstalled as the version
       // return uninstalled as the version
       return 'not installed';
       return 'not installed';
@@ -232,7 +234,8 @@ function chado_get_version($exact = FALSE, $warn_if_unsupported = FALSE) {
   }
   }
   else {
   else {
     $is_local = 1;
     $is_local = 1;
-    $prop_exists = db_table_exists('chado.chadoprop');
+    // @todo we need a chado aware db_table_exists.
+    $prop_exists = db_table_exists(tripal_get_schema_name('chado').'.chadoprop');
   }
   }
 
 
   // if the table doesn't exist then we don't know what version but we know
   // if the table doesn't exist then we don't know what version but we know
@@ -418,4 +421,4 @@ function chado_get_custom_table_schema($table) {
   else {
   else {
     return unserialize($custom->schema);
     return unserialize($custom->schema);
   }
   }
-}
+}

+ 4 - 2
tripal_core/api/tripal_core.custom_tables.api.inc

@@ -122,6 +122,8 @@ function chado_create_custom_table($table, $schema, $skip_if_exists = 1, $mview_
   global $databases;
   global $databases;
   $created = 0;
   $created = 0;
   $recreated = 0;
   $recreated = 0;
+  $chado_schema = tripal_get_schema_name('chado');
+  $chado_dot = $chado_schema . '.';
 
 
   $transaction = db_transaction();
   $transaction = db_transaction();
   try {
   try {
@@ -135,7 +137,7 @@ function chado_create_custom_table($table, $schema, $skip_if_exists = 1, $mview_
 
 
     // if the table does not exist then create it
     // if the table does not exist then create it
     if (!$exists) {
     if (!$exists) {
-      $ret = db_create_table('chado.' . $table, $schema);
+      $ret = db_create_table($chado_dot . $table, $schema);
       $created = 1;
       $created = 1;
     }
     }
 
 
@@ -150,7 +152,7 @@ function chado_create_custom_table($table, $schema, $skip_if_exists = 1, $mview_
       if (array_key_exists('referring_tables', $new_schema)) {
       if (array_key_exists('referring_tables', $new_schema)) {
         unset($new_schema['referring_tables']);
         unset($new_schema['referring_tables']);
       }
       }
-      db_create_table('chado.' . $table, $new_schema);
+      db_create_table($chado_dot . $table, $new_schema);
       $recreated = 1;
       $recreated = 1;
     }
     }
 
 

+ 1 - 1
tripal_core/api/tripal_core.mviews.api.inc

@@ -400,7 +400,7 @@ function tripal_delete_mview($mview_id) {
   db_query($sql);
   db_query($sql);
 
 
   // does the table already exist?
   // does the table already exist?
-  $mview_exists = db_table_exists('chado.' . $mview->mv_table);
+  $mview_exists = chado_table_exists($mview->mv_table);
 
 
   // drop the table from chado if it exists
   // drop the table from chado if it exists
   if ($mview_exists) {
   if ($mview_exists) {

+ 21 - 12
tripal_core/includes/tripal_core.chado_install.inc

@@ -322,6 +322,10 @@ function tripal_core_upgrade_chado_1_11_to_1_2() {
  */
  */
 function tripal_core_reset_chado_schema() {
 function tripal_core_reset_chado_schema() {
 
 
+  // determine the schema name.
+  $chado_schema = tripal_get_schema_name('chado');
+  $chado_dot = $schado_schema . '.';
+
   // drop current chado and chado-related schema
   // drop current chado and chado-related schema
   if (chado_dbschema_exists('genetic_code')) {
   if (chado_dbschema_exists('genetic_code')) {
     print "Dropping existing 'genetic_code' schema\n";
     print "Dropping existing 'genetic_code' schema\n";
@@ -337,12 +341,12 @@ function tripal_core_reset_chado_schema() {
   }
   }
   if (chado_dbschema_exists('chado')) {
   if (chado_dbschema_exists('chado')) {
     print "Dropping existing 'chado' schema\n";
     print "Dropping existing 'chado' schema\n";
-    db_query("drop schema chado cascade");
+    db_query("drop schema $chado_schema cascade");
   }
   }
 
 
   // create the new chado schema
   // create the new chado schema
   print "Creating 'chado' schema\n";
   print "Creating 'chado' schema\n";
-  db_query("create schema chado");
+  db_query("create schema $chado_schema");
   if (chado_dbschema_exists('chado')) {
   if (chado_dbschema_exists('chado')) {
     // before creating the plpgsql language let's check to make sure
     // before creating the plpgsql language let's check to make sure
     // it doesn't already exists
     // it doesn't already exists
@@ -370,8 +374,12 @@ function tripal_core_install_sql($sql_file) {
 
 
   $chado_local = chado_dbschema_exists('chado');
   $chado_local = chado_dbschema_exists('chado');
 
 
+  // determine the schema name.
+  $chado_schema = tripal_get_schema_name('chado');
+  $chado_dot = $schado_schema . '.';
+
   if ($chado_local) {
   if ($chado_local) {
-    db_query("set search_path to chado");
+    db_query("set search_path to $chado_schema");
   }
   }
   print "Loading $sql_file...\n";
   print "Loading $sql_file...\n";
   $lines = file($sql_file, FILE_SKIP_EMPTY_LINES);
   $lines = file($sql_file, FILE_SKIP_EMPTY_LINES);
@@ -403,11 +411,11 @@ function tripal_core_install_sql($sql_file) {
     // Find SQL for new objects
     // Find SQL for new objects
     if (preg_match('/^\s*CREATE\s+TABLE/i', $line) and !$in_string and !$in_function) {
     if (preg_match('/^\s*CREATE\s+TABLE/i', $line) and !$in_string and !$in_function) {
       $stack[] = 'table';
       $stack[] = 'table';
-      $line = preg_replace("/public\./", "chado.", $line);
+      $line = preg_replace("/public\./", $chado_dot, $line);
     }
     }
     if (preg_match('/^\s*ALTER\s+TABLE\s+/i', $line) and !$in_string and !$in_function) {
     if (preg_match('/^\s*ALTER\s+TABLE\s+/i', $line) and !$in_string and !$in_function) {
       $stack[] = 'alter_table';
       $stack[] = 'alter_table';
-      $line = preg_replace("/public\./", "chado.", $line);
+      $line = preg_replace("/public\./", $chado_dot, $line);
     }
     }
     if (preg_match('/^\s*SET/i', $line) and !$in_string and !$in_function) {
     if (preg_match('/^\s*SET/i', $line) and !$in_string and !$in_function) {
       $stack[] = 'set';
       $stack[] = 'set';
@@ -417,27 +425,27 @@ function tripal_core_install_sql($sql_file) {
     }
     }
     if (preg_match('/^\s*CREATE\s+SEQUENCE/i', $line) and !$in_string and !$in_function) {
     if (preg_match('/^\s*CREATE\s+SEQUENCE/i', $line) and !$in_string and !$in_function) {
       $stack[] = 'sequence';
       $stack[] = 'sequence';
-      $line = preg_replace("/public\./", "chado.", $line);
+      $line = preg_replace("/public\./", $chado_dot, $line);
     }
     }
     if (preg_match('/^\s*CREATE\s+(?:OR\s+REPLACE\s+)*VIEW/i', $line) and !$in_string and !$in_function) {
     if (preg_match('/^\s*CREATE\s+(?:OR\s+REPLACE\s+)*VIEW/i', $line) and !$in_string and !$in_function) {
       $stack[] = 'view';
       $stack[] = 'view';
-      $line = preg_replace("/public\./", "chado.", $line);
+      $line = preg_replace("/public\./", $chado_dot, $line);
     }
     }
     if (preg_match('/^\s*COMMENT/i', $line) and !$in_string and sizeof($stack)==0 and !$in_function) {
     if (preg_match('/^\s*COMMENT/i', $line) and !$in_string and sizeof($stack)==0 and !$in_function) {
       $stack[] = 'comment';
       $stack[] = 'comment';
-      $line = preg_replace("/public\./", "chado.", $line);
+      $line = preg_replace("/public\./", $chado_dot, $line);
     }
     }
     if (preg_match('/^\s*CREATE\s+(?:OR\s+REPLACE\s+)*FUNCTION/i', $line) and !$in_string and !$in_function) {
     if (preg_match('/^\s*CREATE\s+(?:OR\s+REPLACE\s+)*FUNCTION/i', $line) and !$in_string and !$in_function) {
       $in_function = TRUE;
       $in_function = TRUE;
       $stack[] = 'function';
       $stack[] = 'function';
-      $line = preg_replace("/public\./", "chado.", $line);
+      $line = preg_replace("/public\./", $chado_dot, $line);
     }
     }
     if (preg_match('/^\s*CREATE\s+INDEX/i', $line) and !$in_string and !$in_function) {
     if (preg_match('/^\s*CREATE\s+INDEX/i', $line) and !$in_string and !$in_function) {
       $stack[] = 'index';
       $stack[] = 'index';
     }
     }
     if (preg_match('/^\s*INSERT\s+INTO/i', $line) and !$in_string and !$in_function) {
     if (preg_match('/^\s*INSERT\s+INTO/i', $line) and !$in_string and !$in_function) {
       $stack[] = 'insert';
       $stack[] = 'insert';
-      $line = preg_replace("/public\./", "chado.", $line);
+      $line = preg_replace("/public\./", $chado_dot, $line);
     }
     }
     if (preg_match('/^\s*CREATE\s+TYPE/i', $line) and !$in_string and !$in_function) {
     if (preg_match('/^\s*CREATE\s+TYPE/i', $line) and !$in_string and !$in_function) {
       $stack[] = 'type';
       $stack[] = 'type';
@@ -563,7 +571,7 @@ function tripal_core_install_sql($sql_file) {
       // rewrite the set search_path to make 'public' be 'chado', but only if the
       // rewrite the set search_path to make 'public' be 'chado', but only if the
       // chado schema exists
       // chado schema exists
       if (strcmp($type, 'set') == 0 and $chado_local) {
       if (strcmp($type, 'set') == 0 and $chado_local) {
-        $query = preg_replace("/public/m", "chado", $query);
+        $query = preg_replace("/public/m", $chado_schema, $query);
       }
       }
 
 
       // execute the statement
       // execute the statement
@@ -593,5 +601,6 @@ function tripal_core_install_sql($sql_file) {
  */
  */
 function tripal_core_chado_install_done() {
 function tripal_core_chado_install_done() {
 
 
-  db_query("set search_path to default");
+  $drupal_schema = tripal_get_schema_name('drupal');
+  db_query("set search_path to $drupal_schema");
 }
 }

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

@@ -328,7 +328,7 @@ function tripal_custom_tables_form_validate($form, &$form_state) {
         $results = db_query($sql, array(':table_id' => $table_id));
         $results = db_query($sql, array(':table_id' => $table_id));
         $ct = $results->fetchObject();
         $ct = $results->fetchObject();
         if ($ct->table_name != $schema_array['table']) {
         if ($ct->table_name != $schema_array['table']) {
-          $exists = db_table_exists('chado.' . $schema_array['table']);
+          $exists = chado_table_exists($schema_array['table']);
           if ($exists) {
           if ($exists) {
             form_set_error($form_state['values']['schema'],
             form_set_error($form_state['values']['schema'],
               t("The table name already exists, please choose a different name."));
               t("The table name already exists, please choose a different name."));

+ 1 - 5
tripal_cv/includes/tripal_cv.cvterm_form.inc

@@ -37,11 +37,7 @@ function tripal_cv_cvterm_edit_form($form, &$form_state) {
     $cv_id = $form_state['build_info']['args'][0];
     $cv_id = $form_state['build_info']['args'][0];
     $cvterm_id = $form_state['build_info']['args'][1];
     $cvterm_id = $form_state['build_info']['args'][1];
     if ($form_state['build_info']['args'][1]) {
     if ($form_state['build_info']['args'][1]) {
-      $result = db_select('chado.cvterm','c')
-        ->fields('c', array('name'))
-        ->condition('c.cvterm_id',$cvterm_id)
-        ->execute();
-      $cvterm_name = $result->fetchObject()->name;
+      $cvterm_name = chado_query('SELECT name FROM {cvterm} WHERE cvterm_id=:id', array(':id' => $cvterm_id))->fetchField();
       $step = 1;
       $step = 1;
     }
     }
   }
   }

+ 2 - 4
tripal_cv/tripal_cv.install

@@ -73,8 +73,7 @@ function tripal_cv_install() {
 function tripal_cv_uninstall() {
 function tripal_cv_uninstall() {
 
 
   // drop the tripal_obo_temp table
   // drop the tripal_obo_temp table
-  // @todo: Remove hardcoding of chado schema name.
-  if (db_table_exists('chado.tripal_obo_temp')) {
+  if (chado_table_exists('tripal_obo_temp')) {
     $sql = "DROP TABLE {tripal_obo_temp}";
     $sql = "DROP TABLE {tripal_obo_temp}";
     chado_query($sql);
     chado_query($sql);
   }
   }
@@ -91,8 +90,7 @@ function tripal_cv_create_tripal_obo_temp() {
   // do not want to use the Tripal Custom Table API because we don't want it to appear in the
   // do not want to use the Tripal Custom Table API because we don't want it to appear in the
   // list of custom tables.  It needs to be available for the Tripal Chado API so we create it
   // list of custom tables.  It needs to be available for the Tripal Chado API so we create it
   // here and then define it in the tripal_cv/api/tripal_cv.schema.api.inc
   // here and then define it in the tripal_cv/api/tripal_cv.schema.api.inc
-  // @todo: Remove hardcoding of chado schema name.
-  if (!db_table_exists('chado.tripal_obo_temp')) {
+  if (!chado_table_exists('tripal_obo_temp')) {
     $sql = "
     $sql = "
       CREATE TABLE {tripal_obo_temp} (
       CREATE TABLE {tripal_obo_temp} (
         id character varying(255) NOT NULL,
         id character varying(255) NOT NULL,

+ 1 - 1
tripal_library/tripal_library.install

@@ -335,7 +335,7 @@ function tripal_library_update_7200() {
   // reset the CV ID for that term and rename the term to 'Library Description'
   // reset the CV ID for that term and rename the term to 'Library Description'
   try {
   try {
     $sql = "
     $sql = "
-      UPDATE chado.cvterm
+      UPDATE {cvterm}
       SET
       SET
         name = 'Library Description',
         name = 'Library Description',
         cv_id = (SELECT cv_id FROM {cv} WHERE name = 'library_property')
         cv_id = (SELECT cv_id FROM {cv} WHERE name = 'library_property')

+ 4 - 10
tripal_pub/tripal_pub.install

@@ -318,16 +318,10 @@ function tripal_pub_update_7200() {
 
 
   // add the pub_property CV
   // add the pub_property CV
   try {
   try {
-    $cv_id = db_query("SELECT cv_id FROM chado.cv WHERE name = 'pub_property'")->fetchField();
-    if (!$cv_id) {
-      // add the vocabulary
-      $cv_id = db_insert('chado.cv')
-        ->fields(array(
-          'name' => 'pub_property',
-          'definition' => 'Contains properties for publications. This can be used if the tripal_pub vocabulary (which is default for publications in Tripal) is not desired.'
-        ))
-        ->execute();
-    }
+    tripal_insert_cv(
+      'pub_property',
+      'Contains properties for publications. This can be used if the tripal_pub vocabulary (which is default for publications in Tripal) is not desired.'
+    );
   }
   }
   catch (\PDOException $e) {
   catch (\PDOException $e) {
     $error = $e->getMessage();
     $error = $e->getMessage();

+ 6 - 3
tripal_views/tripal_views.views.inc

@@ -117,6 +117,9 @@ function tripal_views_views_data() {
   // Manually integrate the drupal.tripal_views* tables
   // Manually integrate the drupal.tripal_views* tables
   $data = tripal_views_views_data_tripal_views_tables($data);
   $data = tripal_views_views_data_tripal_views_tables($data);
 
 
+  // Determine the name of the chado schema
+  $chado_schema = tripal_get_schema_name('chado');
+
   // MAKE SURE ALL CHADO TABLES ARE INTEGRATED
   // MAKE SURE ALL CHADO TABLES ARE INTEGRATED
   tripal_views_integrate_all_chado_tables();
   tripal_views_integrate_all_chado_tables();
 
 
@@ -239,7 +242,7 @@ function tripal_views_views_data() {
         'group' => "$tvi_row->name",
         'group' => "$tvi_row->name",
         'title' => "$tvi_row->name",
         'title' => "$tvi_row->name",
         'help'  => $tvi_row->comment,
         'help'  => $tvi_row->comment,
-        'search_path' => 'chado'
+        'search_path' => $chado_schema
       );
       );
     }
     }
     else {
     else {
@@ -247,7 +250,7 @@ function tripal_views_views_data() {
         'group' => "$tvi_row->name",
         'group' => "$tvi_row->name",
         'title' => "$tvi_row->name",
         'title' => "$tvi_row->name",
         'help'  => $tvi_row->comment,
         'help'  => $tvi_row->comment,
-        'search_path' => 'chado'
+        'search_path' => $chado_schema
       );
       );
     }
     }
 
 
@@ -663,4 +666,4 @@ function tripal_views_views_data_alter(&$data) {
  */
  */
 function tripal_views_views_pre_view(&$view, &$display_id, &$args) {
 function tripal_views_views_pre_view(&$view, &$display_id, &$args) {
   $_GET = array_merge($_GET, $_POST);
   $_GET = array_merge($_GET, $_POST);
-}
+}