pre_schema_upgrade

Runs before the schema is upgraded.

Description

pre_schema_upgrade(); 

Usage

  1. if ( !function_exists( 'pre_schema_upgrade' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/upgrade.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = pre_schema_upgrade(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/upgrade.php  
  1. function pre_schema_upgrade() { 
  2. global $wp_current_db_version, $wpdb; 
  3.  
  4. // Upgrade versions prior to 2.9 
  5. if ( $wp_current_db_version < 11557 ) { 
  6. // Delete duplicate options. Keep the option with the highest option_id. 
  7. $wpdb->query("DELETE o1 FROM $wpdb->options AS o1 JOIN $wpdb->options AS o2 USING (`option_name`) WHERE o2.option_id > o1.option_id"); 
  8.  
  9. // Drop the old primary key and add the new. 
  10. $wpdb->query("ALTER TABLE $wpdb->options DROP PRIMARY KEY, ADD PRIMARY KEY(option_id)"); 
  11.  
  12. // Drop the old option_name index. dbDelta() doesn't do the drop. 
  13. $wpdb->query("ALTER TABLE $wpdb->options DROP INDEX option_name"); 
  14.  
  15. // Multisite schema upgrades. 
  16. if ( $wp_current_db_version < 25448 && is_multisite() && wp_should_upgrade_global_tables() ) { 
  17.  
  18. // Upgrade versions prior to 3.7 
  19. if ( $wp_current_db_version < 25179 ) { 
  20. // New primary key for signups. 
  21. $wpdb->query( "ALTER TABLE $wpdb->signups ADD signup_id BIGINT(20) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST" ); 
  22. $wpdb->query( "ALTER TABLE $wpdb->signups DROP INDEX domain" ); 
  23.  
  24. if ( $wp_current_db_version < 25448 ) { 
  25. // Convert archived from enum to tinyint. 
  26. $wpdb->query( "ALTER TABLE $wpdb->blogs CHANGE COLUMN archived archived varchar(1) NOT NULL default '0'" ); 
  27. $wpdb->query( "ALTER TABLE $wpdb->blogs CHANGE COLUMN archived archived tinyint(2) NOT NULL default 0" ); 
  28.  
  29. // Upgrade versions prior to 4.2. 
  30. if ( $wp_current_db_version < 31351 ) { 
  31. $wpdb->query( "ALTER TABLE $wpdb->usermeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" ); 
  32. $wpdb->query( "ALTER TABLE $wpdb->terms DROP INDEX slug, ADD INDEX slug(slug(191))" ); 
  33. $wpdb->query( "ALTER TABLE $wpdb->terms DROP INDEX name, ADD INDEX name(name(191))" ); 
  34. $wpdb->query( "ALTER TABLE $wpdb->commentmeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" ); 
  35. $wpdb->query( "ALTER TABLE $wpdb->postmeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" ); 
  36. $wpdb->query( "ALTER TABLE $wpdb->posts DROP INDEX post_name, ADD INDEX post_name(post_name(191))" ); 
  37.  
  38. // Upgrade versions prior to 4.4. 
  39. if ( $wp_current_db_version < 34978 ) { 
  40. // If compatible termmeta table is found, use it, but enforce a proper index and update collation. 
  41. if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->termmeta}'" ) && $wpdb->get_results( "SHOW INDEX FROM {$wpdb->termmeta} WHERE Column_name = 'meta_key'" ) ) { 
  42. $wpdb->query( "ALTER TABLE $wpdb->termmeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" ); 
  43. maybe_convert_table_to_utf8mb4( $wpdb->termmeta );