Skip to content

Commit ebd415b

Browse files
Database: Do not unnecessarily alter table in dbDelta() for field type case differences.
This aims to avoid extra changes to database structure when type case is the only difference: {{{ Changed type of wp_table.field from varchar(255) to VARCHAR(255) }}} Follow-up to [1575], [37532]. Props leewillis77, tristanleboss, lordspace, johnbillion, SergeyBiryukov. Fixes #59481. git-svn-id: https://develop.svn.wordpress.org/trunk@60789 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 06ef70d commit ebd415b

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/wp-admin/includes/upgrade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3203,7 +3203,7 @@ function dbDelta( $queries = '', $execute = true ) { // phpcs:ignore WordPress.N
32033203
$fieldtype_base = strtok( $fieldtype_without_parentheses, ' ' );
32043204

32053205
// Is actual field type different from the field type in query?
3206-
if ( $tablefield->Type !== $fieldtype ) {
3206+
if ( $tablefield->Type !== $fieldtype_lowercased ) {
32073207
$do_change = true;
32083208
if ( in_array( $fieldtype_lowercased, $text_fields, true ) && in_array( $tablefield_type_lowercased, $text_fields, true ) ) {
32093209
if ( array_search( $fieldtype_lowercased, $text_fields, true ) < array_search( $tablefield_type_lowercased, $text_fields, true ) ) {

tests/phpunit/tests/db/dbDelta.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,4 +1116,29 @@ public function test_column_type_change_with_hyphens_in_name() {
11161116
$updates
11171117
);
11181118
}
1119+
1120+
/**
1121+
* @ticket 59481
1122+
*/
1123+
public function test_column_types_are_not_case_sensitive() {
1124+
global $wpdb;
1125+
1126+
$updates = dbDelta(
1127+
"
1128+
CREATE TABLE {$wpdb->prefix}dbdelta_test (
1129+
id bigint(20) NOT NULL AUTO_INCREMENT,
1130+
column_1 varCHAr(255) NOT NULL,
1131+
column_2 TEXT,
1132+
column_3 blOB,
1133+
PRIMARY KEY (id),
1134+
KEY key_1 (column_1($this->max_index_length)),
1135+
KEY compound_key (id,column_1($this->max_index_length)),
1136+
FULLTEXT KEY fulltext_key (column_1)
1137+
) {$this->db_engine}
1138+
",
1139+
false
1140+
);
1141+
1142+
$this->assertEmpty( $updates );
1143+
}
11191144
}

0 commit comments

Comments
 (0)