Browse Source

Added new API functions for indexes. Fixed default values in chado tables

Ficklin 10 years ago
parent
commit
0e8d642881

+ 51 - 0
tripal_core/api/tripal_core.chado_schema.api.inc

@@ -56,6 +56,57 @@ function chado_table_exists($table) {
   return TRUE;
 }
 
+/**
+ * A Chado-aware replacement for the db_index_exists() function.
+ *
+ * @param $table
+ *   The table to be altered.
+ * @param $name
+ *   The name of the index.
+ */
+function chado_index_exists($table, $name) {
+  global $databases;
+
+  $indexname = $table . '_' . $name . '_idx';
+
+  $default_db = $databases['default']['default']['database'];
+
+  $sql = "SELECT 1 as exists FROM pg_indexes WHERE indexname = :indexname";
+
+  $result = db_query($sql, array(':indexname' => $indexname));
+  $exists = $result->fetchObject();
+  return $exists->exists;
+}
+
+/**
+ * A Chado-aware wrapper for the db_add_index() function.
+ *
+ * @param $table
+ *   The table to be altered.
+ * @param $name
+ *   The name of the index.
+ * @param $fields
+ *   An array of field names.
+ */
+function chado_add_index($table, $name, $fields) {
+  $indexname = $table . '_' . $name . '_idx';
+
+  $query = 'CREATE INDEX "' . $indexname . '" ON {' . $table . '} ';
+  $query .= '(';
+  $temp = array();
+  foreach ($fields as $field) {
+    if (is_array($field)) {
+      $temp[] = 'substr(' . $field[0] . ', 1, ' . $field[1] . ')';
+    }
+    else {
+      $temp[] = '"' . $field . '"';
+    }
+  }
+  $query .= implode(', ', $temp);
+  $query .= ')';
+  return chado_query($query);
+}
+
 /**
  * Check that any given schema exists
  *

+ 11 - 11
tripal_core/api/tripal_core.schema_v1.2.api.inc

@@ -73,7 +73,7 @@ function tripal_core_chado_schema_v1_2_acquisition() {
         'description' => '',
         'type' => 'datetime',
         'not null' => FALSE,
-        'default' => 'ow(',
+        'default' => 'now()',
       ),
       'name' => array(
         'description' => '',
@@ -384,7 +384,7 @@ function tripal_core_chado_schema_v1_2_analysis() {
         'description' => '',
         'type' => 'datetime',
         'not null' => TRUE,
-        'default' => 'ow(',
+        'default' => 'now()',
       ),
     ),
     'primary key' => array(
@@ -937,7 +937,7 @@ function tripal_core_chado_schema_v1_2_assay() {
         'description' => '',
         'type' => 'datetime',
         'not null' => FALSE,
-        'default' => 'ow(',
+        'default' => 'now()',
       ),
       'arrayidentifier' => array(
         'description' => '',
@@ -1738,13 +1738,13 @@ function tripal_core_chado_schema_v1_2_cell_line() {
         'description' => '',
         'type' => 'datetime',
         'not null' => TRUE,
-        'default' => 'ow(',
+        'default' => 'now()',
       ),
       'timelastmodified' => array(
         'description' => '',
         'type' => 'datetime',
         'not null' => TRUE,
-        'default' => 'ow(',
+        'default' => 'now()',
       ),
     ),
     'primary key' => array(
@@ -4889,13 +4889,13 @@ function tripal_core_chado_schema_v1_2_feature() {
         'description' => '',
         'type' => 'datetime',
         'not null' => TRUE,
-        'default' => 'ow(',
+        'default' => 'now()',
       ),
       'timelastmodified' => array(
         'description' => '',
         'type' => 'datetime',
         'not null' => TRUE,
-        'default' => 'ow(',
+        'default' => 'now()',
       ),
     ),
     'primary key' => array(
@@ -7136,13 +7136,13 @@ function tripal_core_chado_schema_v1_2_library() {
         'description' => '',
         'type' => 'datetime',
         'not null' => TRUE,
-        'default' => 'ow(',
+        'default' => 'now()',
       ),
       'timelastmodified' => array(
         'description' => '',
         'type' => 'datetime',
         'not null' => TRUE,
-        'default' => 'ow(',
+        'default' => 'now()',
       ),
     ),
     'primary key' => array(
@@ -11682,7 +11682,7 @@ function tripal_core_chado_schema_v1_2_quantification() {
         'description' => '',
         'type' => 'datetime',
         'not null' => FALSE,
-        'default' => 'ow(',
+        'default' => 'now()',
       ),
       'name' => array(
         'description' => '',
@@ -13881,7 +13881,7 @@ function tripal_core_chado_schema_v1_2_tableinfo() {
         'description' => '',
         'type' => 'date',
         'not null' => TRUE,
-        'default' => 'ow(',
+        'default' => 'now()',
       ),
     ),
     'primary key' => array(