From 6189a6fce21e3dc553c860a09bf79d3597b3a8af Mon Sep 17 00:00:00 2001 From: ryan Date: Thu, 19 Nov 2009 16:42:07 +0000 Subject: [PATCH] Make option_id primary. Add uniques for option_name and autoload. see #2699 git-svn-id: http://svn.automattic.com/wordpress/trunk@12217 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/schema.php | 5 +++-- wp-admin/includes/upgrade.php | 36 +++++++++++++++++++++-------------- wp-includes/version.php | 2 +- 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/wp-admin/includes/schema.php b/wp-admin/includes/schema.php index 4e64deeca8..18cf8068e7 100644 --- a/wp-admin/includes/schema.php +++ b/wp-admin/includes/schema.php @@ -108,8 +108,9 @@ CREATE TABLE $wpdb->options ( option_name varchar(64) NOT NULL default '', option_value longtext NOT NULL, autoload varchar(20) NOT NULL default 'yes', - PRIMARY KEY (option_name), - KEY option_id (option_id) + PRIMARY KEY (option_id), + UNIQUE option_name (option_name), + UNIQUE autoloaded_options (autoload, option_name) ) $charset_collate; CREATE TABLE $wpdb->postmeta ( meta_id bigint(20) unsigned NOT NULL auto_increment, diff --git a/wp-admin/includes/upgrade.php b/wp-admin/includes/upgrade.php index 7b018a961a..768dcad800 100644 --- a/wp-admin/includes/upgrade.php +++ b/wp-admin/includes/upgrade.php @@ -1708,25 +1708,33 @@ function maybe_disable_automattic_widgets() { function pre_schema_upgrade() { global $wp_current_db_version, $wp_db_version, $wpdb; - // Only run if less than 2.9 - if ( $wp_current_db_version >= 11557 ) - return; + // Upgrade 2.9 development versions + if ( ( $wp_current_db_version > 11557 ) && ( $wp_current_db_version < 12204 ) ) { + // Drop the option_id index. dbDelta() doesn't do the drop. + $wpdb->query("ALTER TABLE $wpdb->options DROP INDEX option_id"); - // Delete duplicate options. Keep the option with the highest option_id. - $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"); - if ( !empty($delete_options) ) { - $delete_options = implode(',', $delete_options); - $wpdb->query("DELETE FROM $wpdb->options WHERE option_id IN ($delete_options)"); + // Drop the old primary key and add the new. + $wpdb->query("ALTER TABLE $wpdb->options DROP PRIMARY KEY, ADD PRIMARY KEY(option_id)"); + + return; } - // Add an index on option_id to satisfy the auto_increment requirement - $wpdb->query("ALTER TABLE $wpdb->options ADD INDEX option_id (option_id)"); + // Upgrade versions prior to 2.9 + if ( $wp_current_db_version < 11557 ) { + // Delete duplicate options. Keep the option with the highest option_id. + $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"); + if ( !empty($delete_options) ) { + $delete_options = implode(',', $delete_options); + $wpdb->query("DELETE FROM $wpdb->options WHERE option_id IN ($delete_options)"); + } - // Drop the old primary key. The new primary will be created by dbDelta() - $wpdb->query("ALTER TABLE $wpdb->options DROP PRIMARY KEY"); + // Drop the old primary key and add the new. + $wpdb->query("ALTER TABLE $wpdb->options DROP PRIMARY KEY, ADD PRIMARY KEY(option_id)"); + + // Drop the old option_name index. dbDelta() doesn't do the drop. + $wpdb->query("ALTER TABLE $wpdb->options DROP INDEX option_name"); + } - // Drop the old option_name index. dbDelta() doesn't do the drop. - $wpdb->query("ALTER TABLE $wpdb->options DROP INDEX option_name"); } ?> diff --git a/wp-includes/version.php b/wp-includes/version.php index b2a7519d60..9c0eaa24e9 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -15,7 +15,7 @@ $wp_version = '2.9-beta-1'; * * @global int $wp_db_version */ -$wp_db_version = 12208; +$wp_db_version = 12217; /** * Holds the TinyMCE version