Procházet zdrojové kódy

Made sure the rename of tripal tables is only performed once when the site is upgraded from v2 to v3.
Also, tripal v3 added a new column to the tripal_jobs table. The schema for this table is updated accordingly when doing the upgrade.

Chun-Huai Cheng před 9 roky
rodič
revize
68e1fadfa9
2 změnil soubory, kde provedl 100 přidání a 87 odebrání
  1. 39 34
      tripal/tripal.install
  2. 61 53
      tripal_chado/includes/tripal_chado.setup.inc

+ 39 - 34
tripal/tripal.install

@@ -86,6 +86,9 @@ function tripal_enable() {
     db_query($sql);
     $sql = "ALTER INDEX tripal_jobs_pkey2 RENAME TO tripal_jobs_pkey";
     db_query($sql);
+    // schema change
+    $sql = "ALTER TABLE tripal_jobs ADD COLUMN includes text";
+    db_query($sql);
   }
 
   if (db_table_exists('tripal_token_formats2')) {
@@ -120,45 +123,47 @@ function tripal_enable() {
  */
 function tripal_schema() {
 
-
   // 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, we need to temporarily move those
   // tables out of the way, let the module install and then move them back.
-  if (db_table_exists('tripal_jobs')) {
-    // Move the tripal_jobs table out of the way.
-    $sql = "ALTER TABLE tripal_jobs RENAME TO tripal_jobs2";
-    db_query($sql);
-    $sql = "ALTER INDEX tripal_jobs_job_id_idx RENAME TO tripal_jobs_job_id_idx2";
-    db_query($sql);
-    $sql = "ALTER INDEX tripal_jobs_job_name_idx RENAME TO tripal_jobs_job_name_idx2";
-    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);
-    $sql = "ALTER INDEX tripal_token_formats_pkey RENAME TO tripal_token_formats_pkey2";
-    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);
-    $sql = "ALTER INDEX tripal_variables_pkey RENAME TO tripal_variables_pkey2";
-    db_query($sql);
-    $sql = "ALTER INDEX tripal_variables_tripal_variable_names_idx1_idx RENAME TO tripal_variables_tripal_variable_names_idx1_idx2";
-    db_query($sql);
-    $sql = "ALTER INDEX tripal_variables_tripal_variables_c1_key RENAME TO tripal_variables_tripal_variables_c1_key2";
-    db_query($sql);
+  $migrated = variable_get ('tripal_v2_schema_migrated', FALSE);
+  if (!$migrated) {
+    if (db_table_exists('tripal_jobs')) {
+      // Move the tripal_jobs table out of the way.
+      $sql = "ALTER TABLE tripal_jobs RENAME TO tripal_jobs2";
+      db_query($sql);
+      $sql = "ALTER INDEX tripal_jobs_job_id_idx RENAME TO tripal_jobs_job_id_idx2";
+      db_query($sql);
+      $sql = "ALTER INDEX tripal_jobs_job_name_idx RENAME TO tripal_jobs_job_name_idx2";
+      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);
+      $sql = "ALTER INDEX tripal_token_formats_pkey RENAME TO tripal_token_formats_pkey2";
+      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);
+      $sql = "ALTER INDEX tripal_variables_pkey RENAME TO tripal_variables_pkey2";
+      db_query($sql);
+      $sql = "ALTER INDEX tripal_variables_tripal_variable_names_idx1_idx RENAME TO tripal_variables_tripal_variable_names_idx1_idx2";
+      db_query($sql);
+      $sql = "ALTER INDEX tripal_variables_tripal_variables_c1_key RENAME TO tripal_variables_tripal_variables_c1_key2";
+      db_query($sql);
+    }
+    variable_set ('tripal_v2_schema_migrated', TRUE);
   }
-
   $schema = array();
 
   $schema['tripal_jobs'] = tripal_tripal_jobs_schema();

+ 61 - 53
tripal_chado/includes/tripal_chado.setup.inc

@@ -171,62 +171,70 @@ function tripal_chado_enable() {
  */
 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 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, we need to temporarily move those
+  // tables out of the way, let the module install and then move them back.
+  $migrated = variable_get ('tripal_chado_v2_schema_migrated', FALSE);
+  if (!$migrated) {
+    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_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_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);
+    }
     
-  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);
+    variable_set ('tripal_chado_v2_schema_migrated', TRUE);
   }
-
   // Links TripalEntity entities to the chado record.
   $schema['chado_entity'] = tripal_chado_chado_entity_schema();
   $schema['tripal_mviews'] = tripal_chado_tripal_mviews_schema();