WordPress.org

Make WordPress Core

Changeset 12217


Ignore:
Timestamp:
11/19/09 16:42:07 (6 years ago)
Author:
ryan
Message:

Make option_id primary. Add uniques for option_name and autoload. see #2699

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/schema.php

    r12210 r12217  
    109109  option_value longtext NOT NULL, 
    110110  autoload varchar(20) NOT NULL default 'yes', 
    111   PRIMARY KEY  (option_name), 
    112   KEY option_id (option_id) 
     111  PRIMARY KEY  (option_id), 
     112  UNIQUE option_name (option_name), 
     113  UNIQUE autoloaded_options (autoload, option_name) 
    113114) $charset_collate; 
    114115CREATE TABLE $wpdb->postmeta ( 
  • trunk/wp-admin/includes/upgrade.php

    r12212 r12217  
    17091709    global $wp_current_db_version, $wp_db_version, $wpdb; 
    17101710 
    1711     // Only run if less than 2.9 
    1712     if ( $wp_current_db_version >= 11557 ) 
     1711    // Upgrade 2.9 development versions 
     1712    if ( ( $wp_current_db_version > 11557 ) && ( $wp_current_db_version < 12204 ) ) { 
     1713        // Drop the option_id index. dbDelta() doesn't do the drop. 
     1714        $wpdb->query("ALTER TABLE $wpdb->options DROP INDEX option_id"); 
     1715 
     1716        // Drop the old primary key and add the new. 
     1717        $wpdb->query("ALTER TABLE $wpdb->options DROP PRIMARY KEY, ADD PRIMARY KEY(option_id)"); 
     1718 
    17131719        return; 
    1714  
    1715     // Delete duplicate options.  Keep the option with the highest option_id. 
    1716     $delete_options = $wpdb->get_col("SELECT o1.option_id FROM $wpdb->options AS o1 JOIN $wpdb->options AS o2 ON o2.option_name = o1.option_name AND o2.option_id > o1.option_id"); 
    1717     if ( !empty($delete_options) ) { 
    1718         $delete_options = implode(',', $delete_options); 
    1719         $wpdb->query("DELETE FROM $wpdb->options WHERE option_id IN ($delete_options)"); 
    1720     } 
    1721  
    1722     // Add an index on option_id to satisfy the auto_increment requirement 
    1723     $wpdb->query("ALTER TABLE $wpdb->options ADD INDEX option_id (option_id)"); 
    1724  
    1725     // Drop the old primary key. The new primary will be created by dbDelta() 
    1726     $wpdb->query("ALTER TABLE $wpdb->options DROP PRIMARY KEY"); 
    1727  
    1728     // Drop the old option_name index. dbDelta() doesn't do the drop. 
    1729     $wpdb->query("ALTER TABLE $wpdb->options DROP INDEX option_name"); 
     1720    } 
     1721 
     1722    // Upgrade versions prior to 2.9 
     1723    if ( $wp_current_db_version < 11557 ) { 
     1724        // Delete duplicate options.  Keep the option with the highest option_id. 
     1725        $delete_options = $wpdb->get_col("SELECT o1.option_id FROM $wpdb->options AS o1 JOIN $wpdb->options AS o2 ON o2.option_name = o1.option_name AND o2.option_id > o1.option_id"); 
     1726        if ( !empty($delete_options) ) { 
     1727            $delete_options = implode(',', $delete_options); 
     1728            $wpdb->query("DELETE FROM $wpdb->options WHERE option_id IN ($delete_options)"); 
     1729        } 
     1730 
     1731        // Drop the old primary key and add the new. 
     1732        $wpdb->query("ALTER TABLE $wpdb->options DROP PRIMARY KEY, ADD PRIMARY KEY(option_id)"); 
     1733 
     1734        // Drop the old option_name index. dbDelta() doesn't do the drop. 
     1735        $wpdb->query("ALTER TABLE $wpdb->options DROP INDEX option_name"); 
     1736    } 
     1737 
    17301738} 
    17311739 
  • trunk/wp-includes/version.php

    r12210 r12217  
    1616 * @global int $wp_db_version 
    1717 */ 
    18 $wp_db_version = 12208; 
     18$wp_db_version = 12217; 
    1919 
    2020/** 
Note: See TracChangeset for help on using the changeset viewer.