Prechádzať zdrojové kódy

Renamed tripal tables so tripal and tripal_chado modules can be enabled when upgrading from v2

Chun-Huai Cheng 9 rokov pred
rodič
commit
c4763de866
2 zmenil súbory, kde vykonal 139 pridanie a 3 odobranie
  1. 9 2
      tripal/tripal.install
  2. 130 1
      tripal_chado/tripal_chado.install

+ 9 - 2
tripal/tripal.install

@@ -86,7 +86,9 @@ function tripal_enable() {
     db_query($sql);
     $sql = "ALTER INDEX tripal_jobs_pkey2 RENAME TO tripal_jobs_pkey";
     db_query($sql);
+  }
 
+  if (db_table_exists('tripal_token_formats2')) {
     $sql = "DROP TABLE tripal_token_formats";
     db_query($sql);
     $sql = "ALTER TABLE tripal_token_formats2 RENAME TO tripal_token_formats";
@@ -95,7 +97,9 @@ function tripal_enable() {
     db_query($sql);
     $sql = "ALTER INDEX tripal_token_formats_type_application_key2 RENAME TO tripal_token_formats_type_application_key";
     db_query($sql);
-
+  }
+  
+  if (db_table_exists('tripal_variables2')) {
     $sql = "DROP TABLE tripal_variables";
     db_query($sql);
     $sql = "ALTER TABLE tripal_variables2 RENAME TO tripal_variables";
@@ -131,7 +135,9 @@ function tripal_schema() {
     db_query($sql);
     $sql = "ALTER INDEX tripal_jobs_pkey RENAME TO tripal_jobs_pkey2";
     db_query($sql);
+  }
 
+  if (db_table_exists('tripal_token_formats')) {
     // Move the tripal_token_formats table out of the way.
     $sql = "ALTER TABLE tripal_token_formats RENAME TO tripal_token_formats2";
     db_query($sql);
@@ -139,7 +145,9 @@ function tripal_schema() {
     db_query($sql);
     $sql = "ALTER INDEX tripal_token_formats_type_application_key RENAME TO tripal_token_formats_type_application_key2";
     db_query($sql);
+  }
 
+  if (db_table_exists('tripal_variables')) {
     // Move the tripal_variables table out of the way.
     $sql = "ALTER TABLE tripal_variables RENAME TO tripal_variables2";
     db_query($sql);
@@ -149,7 +157,6 @@ function tripal_schema() {
     db_query($sql);
     $sql = "ALTER INDEX tripal_variables_tripal_variables_c1_key RENAME TO tripal_variables_tripal_variables_c1_key2";
     db_query($sql);
-
   }
 
   $schema = array();

+ 130 - 1
tripal_chado/tripal_chado.install

@@ -11,7 +11,6 @@ function tripal_chado_install() {
 //   ');
 }
 
-
 /**
  * Implementation of hook_uninstall().
  *
@@ -92,11 +91,141 @@ function tripal_chado_tripal_cv_defaults_schema() {
   );
 }
 
+/**
+ *
+ */
+function tripal_chado_enable() {
+  // If Tripal v2 is already installed, the installation of this module
+  // will try and recreate some of the tables created with tripal_core and the
+  // installation will fail.  Therefore, in the install we renamed it. Now
+  // we want to move it back.
+  if (db_table_exists('tripal_mviews2')) {
+    // tripal_mviews
+    $sql = "DROP TABLE tripal_mviews";
+    db_query($sql);
+    $sql = "ALTER TABLE tripal_mviews2 RENAME to tripal_mviews";
+    db_query($sql);
+    $sql = "ALTER INDEX tripal_mviews_mv_name_key2 RENAME TO tripal_mviews_mv_name_key";
+    db_query($sql);
+    $sql = "ALTER INDEX tripal_mviews_mv_table_key2 RENAME TO tripal_mviews_mv_table_key";
+    db_query($sql);
+    $sql = "ALTER INDEX tripal_mviews_mview_id_idx2 RENAME TO tripal_mviews_mview_id_idx";
+    db_query($sql);
+    $sql = "ALTER INDEX tripal_mviews_pkey2 RENAME TO tripal_mviews_pkey";
+    db_query($sql);
+  }
+    
+    // tripal_custom_tables
+  if (db_table_exists('tripal_custom_tables2')) {
+    $sql = "DROP TABLE tripal_custom_tables";
+    db_query($sql);
+    $sql = "ALTER TABLE tripal_custom_tables2 RENAME to tripal_custom_tables";
+    db_query($sql);
+    $sql = "ALTER INDEX tripal_custom_tables_pkey2 RENAME TO tripal_custom_tables_pkey";
+    db_query($sql);
+    $sql = "ALTER INDEX tripal_custom_tables_table_id_idx2 RENAME TO tripal_custom_tables_table_id_idx";
+    db_query($sql);
+  }
+    
+    // tripal_cv_obo
+  if (db_table_exists('tripal_cv_obo2')) {
+    $sql = "DROP TABLE tripal_cv_obo";
+    db_query($sql);
+    $sql = "ALTER TABLE tripal_cv_obo2 RENAME to tripal_cv_obo";
+    db_query($sql);
+    $sql = "ALTER INDEX tripal_cv_obo_obo_id_idx2 RENAME TO tripal_cv_obo_obo_id_idx";
+    db_query($sql);
+    $sql = "ALTER INDEX tripal_cv_obo_pkey2 RENAME TO tripal_cv_obo_pkey";
+    db_query($sql);
+  }
+    
+    // tripal_cv_defaults
+  if (db_table_exists('tripal_cv_defaults2')) {
+    $sql = "DROP TABLE tripal_cv_defaults";
+    db_query($sql);
+    $sql = "ALTER TABLE tripal_cv_defaults2 RENAME to tripal_cv_defaults";
+    db_query($sql);
+    $sql = "ALTER INDEX tripal_cv_defaults_pkey2 RENAME TO tripal_cv_defaults_pkey";
+    db_query($sql);
+    $sql = "ALTER INDEX tripal_cv_defaults_tripal_cv_defaults_idx1_idx2 RENAME TO tripal_cv_defaults_tripal_cv_defaults_idx1_idx";
+    db_query($sql);
+    $sql = "ALTER INDEX tripal_cv_defaults_tripal_cv_defaults_unq1_key2 RENAME TO tripal_cv_defaults_tripal_cv_defaults_unq1_key";
+    db_query($sql);
+  }
+    
+    // tripal_pub_import
+  if (db_table_exists('tripal_pub_import2')) {
+    $sql = "DROP TABLE tripal_pub_import";
+    db_query($sql);
+    $sql = "ALTER TABLE tripal_pub_import2 RENAME to tripal_pub_import";
+    db_query($sql);
+    $sql = "ALTER INDEX tripal_pub_import_name_idx2 RENAME TO tripal_pub_import_name_idx";
+    db_query($sql);
+    $sql = "ALTER INDEX tripal_pub_import_pkey2 RENAME TO tripal_pub_import_pkey";
+    db_query($sql);
+  }
+}
 
 /**
  * Implements hook_schema().
  */
 function tripal_chado_schema() {
+  
+  if (db_table_exists('tripal_mviews')) {
+    // Move the tripal_mviews table out of the way.
+    $sql = "ALTER TABLE tripal_mviews RENAME TO tripal_mviews2";
+    db_query($sql);
+    $sql = "ALTER INDEX tripal_mviews_mv_name_key RENAME TO tripal_mviews_mv_name_key2";
+    db_query($sql);
+    $sql = "ALTER INDEX tripal_mviews_mv_table_key RENAME TO tripal_mviews_mv_table_key2";
+    db_query($sql);
+    $sql = "ALTER INDEX tripal_mviews_mview_id_idx RENAME TO tripal_mviews_mview_id_idx2";
+    db_query($sql);
+    $sql = "ALTER INDEX tripal_mviews_pkey RENAME TO tripal_mviews_pkey2";
+    db_query($sql);
+  }
+   
+  if (db_table_exists('tripal_custom_tables')) {
+    // Move the tripal_custom_tables table out of the way.
+    $sql = "ALTER TABLE tripal_custom_tables RENAME TO tripal_custom_tables2";
+    db_query($sql);
+    $sql = "ALTER INDEX tripal_custom_tables_pkey RENAME TO tripal_custom_tables_pkey2";
+    db_query($sql);
+    $sql = "ALTER INDEX tripal_custom_tables_table_id_idx RENAME TO tripal_custom_tables_table_id_idx2";
+    db_query($sql);
+  }
+  
+  if (db_table_exists('tripal_cv_obo')) {
+    // Move the tripal_cv_obo table out of the way.
+    $sql = "ALTER TABLE tripal_cv_obo RENAME TO tripal_cv_obo2";
+    db_query($sql);
+    $sql = "ALTER INDEX tripal_cv_obo_obo_id_idx RENAME TO tripal_cv_obo_obo_id_idx2";
+    db_query($sql);
+    $sql = "ALTER INDEX tripal_cv_obo_pkey RENAME TO tripal_cv_obo_pkey2";
+    db_query($sql);
+  }
+    
+  if (db_table_exists('tripal_cv_defaults')) {
+    // Move the tripal_cv_defaults table out of the way.
+    $sql = "ALTER TABLE tripal_cv_defaults RENAME TO tripal_cv_defaults2";
+    db_query($sql);
+    $sql = "ALTER INDEX tripal_cv_defaults_pkey RENAME TO tripal_cv_defaults_pkey2";
+    db_query($sql);
+    $sql = "ALTER INDEX tripal_cv_defaults_tripal_cv_defaults_idx1_idx RENAME TO tripal_cv_defaults_tripal_cv_defaults_idx1_idx2";
+    db_query($sql);
+    $sql = "ALTER INDEX tripal_cv_defaults_tripal_cv_defaults_unq1_key RENAME TO tripal_cv_defaults_tripal_cv_defaults_unq1_key2";
+    db_query($sql);
+  }
+    
+  if (db_table_exists('tripal_pub_import')) {
+    // Move the tripal_pub_import table out of the way.
+    $sql = "ALTER TABLE tripal_pub_import RENAME TO tripal_pub_import2";
+    db_query($sql);
+    $sql = "ALTER INDEX tripal_pub_import_name_idx RENAME TO tripal_pub_import_name_idx2";
+    db_query($sql);
+    $sql = "ALTER INDEX tripal_pub_import_pkey RENAME TO tripal_pub_import_pkey2";
+    db_query($sql);
+  }
 
   // Links TripalEntity entities to the chado record.
   $schema['chado_entity'] = tripal_chado_chado_entity_schema();