Make WordPress Core

Changeset 60789

Timestamp:
09/21/2025 03:50:56 PM (3 weeks ago)
Author:
SergeyBiryukov
Message:

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.

Location:
trunk
Files:
2 edited

Legend:

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

    r60784 r60789  
    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 ) ) {
  • trunk/tests/phpunit/tests/db/dbDelta.php

    r60782 r60789  
    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}
Note: See TracChangeset for help on using the changeset viewer.