Make option_id primary. Add uniques for option_name and autoload. see #2699
git-svn-id: https://develop.svn.wordpress.org/trunk@12217 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
e6be89ee0a
commit
d1190b5bd6
|
@ -108,8 +108,9 @@ CREATE TABLE $wpdb->options (
|
||||||
option_name varchar(64) NOT NULL default '',
|
option_name varchar(64) NOT NULL default '',
|
||||||
option_value longtext NOT NULL,
|
option_value longtext NOT NULL,
|
||||||
autoload varchar(20) NOT NULL default 'yes',
|
autoload varchar(20) NOT NULL default 'yes',
|
||||||
PRIMARY KEY (option_name),
|
PRIMARY KEY (option_id),
|
||||||
KEY option_id (option_id)
|
UNIQUE option_name (option_name),
|
||||||
|
UNIQUE autoloaded_options (autoload, option_name)
|
||||||
) $charset_collate;
|
) $charset_collate;
|
||||||
CREATE TABLE $wpdb->postmeta (
|
CREATE TABLE $wpdb->postmeta (
|
||||||
meta_id bigint(20) unsigned NOT NULL auto_increment,
|
meta_id bigint(20) unsigned NOT NULL auto_increment,
|
||||||
|
|
|
@ -1708,25 +1708,33 @@ function maybe_disable_automattic_widgets() {
|
||||||
function pre_schema_upgrade() {
|
function pre_schema_upgrade() {
|
||||||
global $wp_current_db_version, $wp_db_version, $wpdb;
|
global $wp_current_db_version, $wp_db_version, $wpdb;
|
||||||
|
|
||||||
// Only run if less than 2.9
|
// Upgrade 2.9 development versions
|
||||||
if ( $wp_current_db_version >= 11557 )
|
if ( ( $wp_current_db_version > 11557 ) && ( $wp_current_db_version < 12204 ) ) {
|
||||||
return;
|
// 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.
|
// Drop the old primary key and add the new.
|
||||||
$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");
|
$wpdb->query("ALTER TABLE $wpdb->options DROP PRIMARY KEY, ADD PRIMARY KEY(option_id)");
|
||||||
if ( !empty($delete_options) ) {
|
|
||||||
$delete_options = implode(',', $delete_options);
|
return;
|
||||||
$wpdb->query("DELETE FROM $wpdb->options WHERE option_id IN ($delete_options)");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add an index on option_id to satisfy the auto_increment requirement
|
// Upgrade versions prior to 2.9
|
||||||
$wpdb->query("ALTER TABLE $wpdb->options ADD INDEX option_id (option_id)");
|
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()
|
// Drop the old primary key and add the new.
|
||||||
$wpdb->query("ALTER TABLE $wpdb->options DROP PRIMARY KEY");
|
$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");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -15,7 +15,7 @@ $wp_version = '2.9-beta-1';
|
||||||
*
|
*
|
||||||
* @global int $wp_db_version
|
* @global int $wp_db_version
|
||||||
*/
|
*/
|
||||||
$wp_db_version = 12208;
|
$wp_db_version = 12217;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the TinyMCE version
|
* Holds the TinyMCE version
|
||||||
|
|
Loading…
Reference in New Issue