Browse Source

Issue #2333797: BUG FIX -IF EXISTS postgreSQL syntax is incompatible vith version 8.4

laceysanderson 10 years ago
parent
commit
fae6a16541

+ 12 - 9
tripal_contact/tripal_contact.install

@@ -368,14 +368,17 @@ function tripal_contact_update_7201() {
   // to keep from error messages appear, we will drop the FK if it already
   // to keep from error messages appear, we will drop the FK if it already
   // exists and then re-add it.
   // exists and then re-add it.
   try {
   try {
-    db_query('
+    $fkey_exists = db_query('SELECT TRUE FROM pg_constraint WHERE conname = :constraint', array(':constraint' => 'contactprop_type_id_fkey'))->fetchField();
-      ALTER TABLE chado.contactprop
+    if ($fkey_exists) {
-      DROP CONSTRAINT IF EXISTS contactprop_type_id_fkey CASCADE
+      db_query('
-    ');
+        ALTER TABLE chado.contactprop
-    db_query('
+        DROP CONSTRAINT contactprop_type_id_fkey CASCADE
-      ALTER TABLE chado.contactprop
+      ');
-      DROP CONSTRAINT IF EXISTS contactprop_contact_id_fkey CASCADE
+      db_query('
-    ');
+        ALTER TABLE chado.contactprop
+        DROP CONSTRAINT contactprop_contact_id_fkey CASCADE
+      ');
+    }
     db_query('
     db_query('
       ALTER TABLE chado.contactprop
       ALTER TABLE chado.contactprop
       ADD CONSTRAINT contactprop_type_id_fkey
       ADD CONSTRAINT contactprop_type_id_fkey
@@ -412,4 +415,4 @@ function tripal_contact_update_7202() {
     $error = $e->getMessage();
     $error = $e->getMessage();
     throw new DrupalUpdateException('Failed to update tripal_contact OBO path: '. $error);
     throw new DrupalUpdateException('Failed to update tripal_contact OBO path: '. $error);
   }
   }
-}
+}

+ 1 - 1
tripal_core/tripal_core.install

@@ -68,7 +68,7 @@ function tripal_core_uninstall() {
   // so that Drupal can then drop the tables
   // so that Drupal can then drop the tables
   db_query('
   db_query('
     ALTER TABLE {tripal_custom_tables}
     ALTER TABLE {tripal_custom_tables}
-    DROP CONSTRAINT IF EXISTS tripal_custom_tables_fk1 CASCADE
+    DROP CONSTRAINT tripal_custom_tables_fk1 CASCADE
   ');
   ');
 }
 }
 
 

+ 32 - 25
tripal_featuremap/tripal_featuremap.install

@@ -571,15 +571,18 @@ function tripal_featuremap_update_7201() {
   // to keep from error messages appear, we will drop the FK if it already
   // to keep from error messages appear, we will drop the FK if it already
   // exists and then re-add it.
   // exists and then re-add it.
   try {
   try {
-    // featuremapprop table
+    $fkey_exists = db_query('SELECT TRUE FROM pg_constraint WHERE conname = :constraint', array(':constraint' => 'featuremapprop_type_id_fkey'))->fetchField();
-    db_query('
+    if ($fkey_exists) {
-      ALTER TABLE chado.featuremapprop
+      // featuremapprop table
-      DROP CONSTRAINT IF EXISTS featuremapprop_type_id_fkey CASCADE
+      db_query('
-    ');
+        ALTER TABLE chado.featuremapprop
-    db_query('
+        DROP CONSTRAINT featuremapprop_type_id_fkey CASCADE
-      ALTER TABLE chado.featuremapprop
+      ');
-      DROP CONSTRAINT IF EXISTS featuremapprop_featuremap_id_fkey CASCADE
+      db_query('
-    ');
+        ALTER TABLE chado.featuremapprop
+        DROP CONSTRAINT featuremapprop_featuremap_id_fkey CASCADE
+      ');
+    }
     db_query('
     db_query('
       ALTER TABLE chado.featuremapprop
       ALTER TABLE chado.featuremapprop
       ADD CONSTRAINT featuremapprop_type_id_fkey
       ADD CONSTRAINT featuremapprop_type_id_fkey
@@ -594,14 +597,16 @@ function tripal_featuremap_update_7201() {
     ');
     ');
 
 
     // featuremap_dbref table
     // featuremap_dbref table
-    db_query('
+    if ($fkey_exists) {
-      ALTER TABLE chado.featuremap_dbxref
+      db_query('
-      DROP CONSTRAINT IF EXISTS featuremap_dbxref_dbxref_id_fkey CASCADE
+        ALTER TABLE chado.featuremap_dbxref
-    ');
+        DROP CONSTRAINT featuremap_dbxref_dbxref_id_fkey CASCADE
-    db_query('
+      ');
-      ALTER TABLE chado.featuremap_dbxref
+      db_query('
-      DROP CONSTRAINT IF EXISTS featuremap_dbxref_featuremap_id_fkey CASCADE
+        ALTER TABLE chado.featuremap_dbxref
-    ');
+        DROP CONSTRAINT featuremap_dbxref_featuremap_id_fkey CASCADE
+      ');
+    }
     db_query('
     db_query('
       ALTER TABLE chado.featuremap_dbxref
       ALTER TABLE chado.featuremap_dbxref
       ADD CONSTRAINT featuremap_dbxref_dbxref_id_fkey
       ADD CONSTRAINT featuremap_dbxref_dbxref_id_fkey
@@ -616,14 +621,16 @@ function tripal_featuremap_update_7201() {
     ');
     ');
 
 
     // featureposprop
     // featureposprop
-    db_query('
+    if ($fkey_exists) {
-      ALTER TABLE chado.featureposprop
+      db_query('
-      DROP CONSTRAINT IF EXISTS featureposprop_type_id_fkey CASCADE
+        ALTER TABLE chado.featureposprop
-    ');
+        DROP CONSTRAINT featureposprop_type_id_fkey CASCADE
-    db_query('
+      ');
-      ALTER TABLE chado.featureposprop
+      db_query('
-      DROP CONSTRAINT IF EXISTS featureposprop_featurepos_id_fkey CASCADE
+        ALTER TABLE chado.featureposprop
-    ');
+        DROP CONSTRAINT featureposprop_featurepos_id_fkey CASCADE
+      ');
+    }
     db_query('
     db_query('
       ALTER TABLE chado.featureposprop
       ALTER TABLE chado.featureposprop
       ADD CONSTRAINT featureposprop_type_id_fkey
       ADD CONSTRAINT featureposprop_type_id_fkey

+ 12 - 9
tripal_pub/tripal_pub.install

@@ -408,14 +408,17 @@ function tripal_pub_update_7201() {
   // to keep from error messages appear, we will drop the FK if it already
   // to keep from error messages appear, we will drop the FK if it already
   // exists and then re-add it.
   // exists and then re-add it.
   try {
   try {
-    db_query('
+    $fkey_exists = db_query('SELECT TRUE FROM pg_constraint WHERE conname = :constraint', array(':constraint' => 'pubauthor_contact_pubauthor_id_fkey'))->fetchField();
-      ALTER TABLE chado.pubauthor_contact
+    if ($fkey_exists) {
-      DROP CONSTRAINT IF EXISTS pubauthor_contact_pubauthor_id_fkey CASCADE
+      db_query('
-    ');
+        ALTER TABLE chado.pubauthor_contact
-    db_query('
+        DROP CONSTRAINT pubauthor_contact_pubauthor_id_fkey CASCADE
-      ALTER TABLE chado.pubauthor_contact
+      ');
-      DROP CONSTRAINT IF EXISTS pubauthor_contact_contact_id_fkey CASCADE
+      db_query('
-    ');
+        ALTER TABLE chado.pubauthor_contact
+        DROP CONSTRAINT pubauthor_contact_contact_id_fkey CASCADE
+      ');
+    }
     db_query('
     db_query('
       ALTER TABLE chado.pubauthor_contact
       ALTER TABLE chado.pubauthor_contact
       ADD CONSTRAINT pubauthor_contact_pubauthor_id_fkey
       ADD CONSTRAINT pubauthor_contact_pubauthor_id_fkey
@@ -452,4 +455,4 @@ function tripal_pub_update_7202() {
     $error = $e->getMessage();
     $error = $e->getMessage();
     throw new DrupalUpdateException('Failed to update tripal_pub OBO path: '. $error);
     throw new DrupalUpdateException('Failed to update tripal_pub OBO path: '. $error);
   }
   }
-}
+}