Make WordPress Core


Ignore:
Timestamp:
02/05/2020 04:28:13 AM (7 years ago)
Author:
SergeyBiryukov
Message:

Tests: Allow dbDelta() tests to (mostly) run on MySQL 8.0.11+.

  • MySQL 8.0.11 changed the GeometryCollection data type name to GeomCollection, with the latter being the preferred name.
  • MySQL 8.0.17 removed support for the display width attribute for integer data types. Previously, default display width of 20 digits was used: BIGINT(20).

The affected tests now check the MySQL server version and use the appropriate data types.

This leaves one unresolved failure on MySQL 8.0.17+ to be addressed in the future, caused by the same BIGINT display width discrepancy coming from wp_get_db_schema().

Props kaggdesign, ottok, jeremyfelt, SergeyBiryukov.
Fixes #44384, #49344. See #49364.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/dbdelta.php

    r47122 r47184  
    1616
    1717        /**
     18         * Display width for BIGINT data type.
     19         *
     20         * Prior to MySQL 8.0.17, default width of 20 digits was used: BIGINT(20).
     21         * Since MySQL 8.0.17, display width for integer data types is no longer supported.
     22         */
     23        protected $bigint_display_width = '';
     24
     25        /**
    1826         * Make sure the upgrade code is loaded before the tests are run.
    1927         */
     
    3139
    3240                global $wpdb;
     41
     42                $db_version = $wpdb->db_version();
     43
     44                if ( version_compare( $db_version, '8.0.17', '<' ) ) {
     45                        // Prior to MySQL 8.0.17, default width of 20 digits was used: BIGINT(20).
     46                        $this->bigint_display_width = '(20)';
     47                }
    3348
    3449                // Forcing MyISAM, because InnoDB only started supporting FULLTEXT indexes in MySQL 5.7.
     
    3752                                "
    3853                                CREATE TABLE {$wpdb->prefix}dbdelta_test (
    39                                         id bigint(20) NOT NULL AUTO_INCREMENT,
     54                                        id bigint{$this->bigint_display_width} NOT NULL AUTO_INCREMENT,
    4055                                        column_1 varchar(255) NOT NULL,
    4156                                        column_2 text,
     
    7994                $updates = dbDelta(
    8095                        "CREATE TABLE {$wpdb->prefix}dbdelta_create_test (
    81                                 id bigint(20) NOT NULL AUTO_INCREMENT,
     96                                id bigint{$this->bigint_display_width} NOT NULL AUTO_INCREMENT,
    8297                                column_1 varchar(255) NOT NULL,
    8398                                PRIMARY KEY  (id)
     
    114129                        "
    115130                        CREATE TABLE {$wpdb->prefix}dbdelta_test (
    116                                 id bigint(20) NOT NULL AUTO_INCREMENT,
     131                                id bigint{$this->bigint_display_width} NOT NULL AUTO_INCREMENT,
    117132                                column_1 varchar(255) NOT NULL,
    118133                                PRIMARY KEY  (id),
     
    133148                global $wpdb;
    134149
    135                 // id: bigint(20) => int(11)
     150                // id: bigint => int(11)
    136151                $updates = dbDelta(
    137152                        "
     
    149164                        array(
    150165                                "{$wpdb->prefix}dbdelta_test.id"
    151                                         => "Changed type of {$wpdb->prefix}dbdelta_test.id from bigint(20) to int(11)",
     166                                        => "Changed type of {$wpdb->prefix}dbdelta_test.id from bigint{$this->bigint_display_width} to int(11)",
    152167                        ),
    153168                        $updates
     
    165180                        "
    166181                        CREATE TABLE {$wpdb->prefix}dbdelta_test (
    167                                 id bigint(20) NOT NULL AUTO_INCREMENT,
     182                                id bigint{$this->bigint_display_width} NOT NULL AUTO_INCREMENT,
    168183                                column_1 varchar(255) NOT NULL,
    169184                                extra_col longtext,
     
    200215                        "
    201216                        CREATE TABLE {$wpdb->prefix}dbdelta_test (
    202                                 id bigint(20) NOT NULL AUTO_INCREMENT,
     217                                id bigint{$this->bigint_display_width} NOT NULL AUTO_INCREMENT,
    203218                                PRIMARY KEY  (id),
    204219                                KEY key_1 (column_1($this->max_index_length)),
     
    224239                        "
    225240                        CREATE TABLE {$wpdb->prefix}dbdelta_test (
    226                                 id bigint(20) NOT NULL AUTO_INCREMENT,
     241                                id bigint{$this->bigint_display_width} NOT NULL AUTO_INCREMENT,
    227242                                column_1 varchar(255) NOT NULL,
    228243                                extra_col longtext,
     
    276291                        "
    277292                        CREATE TABLE {$wpdb->prefix}dbdelta_test (
    278                                 id bigint(20) NOT NULL AUTO_INCREMENT,
     293                                id bigint{$this->bigint_display_width} NOT NULL AUTO_INCREMENT,
    279294                                column_1 varchar(255) NOT NULL,
    280295                                PRIMARY KEY  (id),
     
    421436                        "
    422437                        CREATE TABLE {$wpdb->prefix}dbdelta_test (
    423                                 id bigint(20) NOT NULL AUTO_INCREMENT,
     438                                id bigint{$this->bigint_display_width} NOT NULL AUTO_INCREMENT,
    424439                                column_1 varchar(255) NOT NULL,
    425440                                column_2 tinytext,
     
    446461                        "
    447462                        CREATE TABLE {$wpdb->prefix}dbdelta_test (
    448                                 id bigint(20) NOT NULL AUTO_INCREMENT,
     463                                id bigint{$this->bigint_display_width} NOT NULL AUTO_INCREMENT,
    449464                                column_1 varchar(255) NOT NULL,
    450465                                column_2 text,
     
    471486                        "
    472487                        CREATE TABLE {$wpdb->prefix}dbdelta_test (
    473                                 id bigint(20) NOT NULL AUTO_INCREMENT,
     488                                id bigint{$this->bigint_display_width} NOT NULL AUTO_INCREMENT,
    474489                                column_1 varchar(255) NOT NULL,
    475490                                column_2 bigtext,
     
    502517                        "
    503518                        CREATE TABLE {$wpdb->prefix}dbdelta_test (
    504                                 id bigint(20) NOT NULL AUTO_INCREMENT,
     519                                id bigint{$this->bigint_display_width} NOT NULL AUTO_INCREMENT,
    505520                                column_1 varchar(255) NOT NULL,
    506521                                column_2 text,
     
    532547                $schema = "
    533548                        CREATE TABLE {$wpdb->prefix}dbdelta_test2 (
    534                                 `id` bigint(20) NOT NULL AUTO_INCREMENT,
     549                                `id` bigint{$this->bigint_display_width} NOT NULL AUTO_INCREMENT,
    535550                                `column_1` varchar(255) NOT NULL,
    536551                                PRIMARY KEY  (id),
     
    555570                global $wpdb;
    556571
    557                 if ( version_compare( $wpdb->db_version(), '5.4', '<' ) ) {
     572                $db_version = $wpdb->db_version();
     573
     574                if ( version_compare( $db_version, '5.4', '<' ) ) {
    558575                        $this->markTestSkipped( 'Spatial indices require MySQL 5.4 and above.' );
    559576                }
    560577
     578                $geomcollection_name = 'geomcollection';
     579
     580                if ( version_compare( $db_version, '8.0.11', '<' ) ) {
     581                        // Prior to MySQL 8.0.11, GeometryCollection data type name was used.
     582                        $geomcollection_name = 'geometrycollection';
     583                }
     584
    561585                $schema =
    562586                        "
    563587                        CREATE TABLE {$wpdb->prefix}spatial_index_test (
    564                                 non_spatial bigint(20) unsigned NOT NULL,
    565                                 spatial_value geometrycollection NOT NULL,
     588                                non_spatial bigint{$this->bigint_display_width} unsigned NOT NULL,
     589                                spatial_value {$geomcollection_name} NOT NULL,
    566590                                KEY non_spatial (non_spatial),
    567591                                SPATIAL KEY spatial_key (spatial_value)
     
    579603                        "
    580604                        CREATE TABLE {$wpdb->prefix}spatial_index_test (
    581                                 non_spatial bigint(20) unsigned NOT NULL,
    582                                 spatial_value geometrycollection NOT NULL,
    583                                 spatial_value2 geometrycollection NOT NULL,
     605                                non_spatial bigint{$this->bigint_display_width} unsigned NOT NULL,
     606                                spatial_value {$geomcollection_name} NOT NULL,
     607                                spatial_value2 {$geomcollection_name} NOT NULL,
    584608                                KEY non_spatial (non_spatial),
    585609                                SPATIAL KEY spatial_key (spatial_value)
     
    609633                $schema = "
    610634                        CREATE TABLE {$wpdb->prefix}dbdelta_test2 (
    611                                 `id` bigint(20) NOT NULL AUTO_INCREMENT,
     635                                `id` bigint{$this->bigint_display_width} NOT NULL AUTO_INCREMENT,
    612636                                `references` varchar(255) NOT NULL,
    613637                                PRIMARY KEY  (`id`),
     
    639663                        "
    640664                        CREATE TABLE {$wpdb->prefix}dbdelta_test (
    641                                 id bigint(20) NOT NULL AUTO_INCREMENT,
     665                                id bigint{$this->bigint_display_width} NOT NULL AUTO_INCREMENT,
    642666                                column_1 varchar(255) NOT NULL,
    643667                                column_2 text,
     
    683707                $schema = "
    684708                        CREATE TABLE {$wpdb->prefix}dbdelta_test (
    685                                 id bigint(20) NOT NULL AUTO_INCREMENT,
     709                                id bigint{$this->bigint_display_width} NOT NULL AUTO_INCREMENT,
    686710                                column_1 varchar(255) NOT NULL,
    687711                                column_2 text,
     
    722746                        "
    723747                        CREATE TABLE {$wpdb->prefix}dbdelta_test (
    724                                 id bigint(20) NOT NULL AUTO_INCREMENT,
     748                                id bigint{$this->bigint_display_width} NOT NULL AUTO_INCREMENT,
    725749                                column_1 varchar(255) NOT NULL,
    726750                                column_2 text,
     
    745769                $schema = "
    746770                        CREATE TABLE {$wpdb->prefix}dbdelta_test (
    747                                 id bigint(20) NOT NULL AUTO_INCREMENT,
     771                                id bigint{$this->bigint_display_width} NOT NULL AUTO_INCREMENT,
    748772                                column_1 varchar(255) NOT NULL,
    749773                                column_2 text,
     
    780804                        "
    781805                        CREATE TABLE {$wpdb->prefix}dbdelta_test (
    782                                 id bigint(20) NOT NULL AUTO_INCREMENT,
     806                                id bigint{$this->bigint_display_width} NOT NULL AUTO_INCREMENT,
    783807                                column_1 varchar(255) NOT NULL,
    784808                                column_2 text,
     
    804828                        "
    805829                        CREATE TABLE {$wpdb->prefix}dbdelta_test (
    806                                 id bigint(20) NOT NULL AUTO_INCREMENT,
     830                                id bigint{$this->bigint_display_width} NOT NULL AUTO_INCREMENT,
    807831                                column_1 varchar(255) NOT NULL,
    808832                                column_2 text,
     
    828852                        "
    829853                        CREATE TABLE {$wpdb->prefix}dbdelta_test (
    830                                 id bigint(20) NOT NULL AUTO_INCREMENT,
     854                                id bigint{$this->bigint_display_width} NOT NULL AUTO_INCREMENT,
    831855                                column_1 varchar(255) NOT NULL,
    832856                                column_2 text,
     
    852876                        "
    853877                        CREATE TABLE {$wpdb->prefix}dbdelta_test (
    854                                 id bigint(20) NOT NULL AUTO_INCREMENT,
     878                                id bigint{$this->bigint_display_width} NOT NULL AUTO_INCREMENT,
    855879                                column_1 varchar(255) NOT NULL,
    856880                                column_2 text,
     
    876900                        "
    877901                        CREATE TABLE {$wpdb->prefix}dbdelta_test (
    878                                 id bigint(20) NOT NULL AUTO_INCREMENT,
     902                                id bigint{$this->bigint_display_width} NOT NULL AUTO_INCREMENT,
    879903                                column_1 varchar(255) NOT NULL,
    880904                                column_2 text,
     
    901925                        "
    902926                        CREATE TABLE {$wpdb->prefix}dbdelta_test (
    903                                 id bigint(20) NOT NULL AUTO_INCREMENT,
     927                                id bigint{$this->bigint_display_width} NOT NULL AUTO_INCREMENT,
    904928                                column_1 varchar(255) NOT NULL,
    905929                                column_2 text,
     
    926950                        "
    927951                        CREATE TABLE {$wpdb->prefix}dbdelta_test (
    928                                 id bigint(20) NOT NULL AUTO_INCREMENT,
     952                                id bigint{$this->bigint_display_width} NOT NULL AUTO_INCREMENT,
    929953                                column_1 varchar(255) NOT NULL,
    930954                                column_2 text,
     
    949973                        "
    950974                        CREATE TABLE {$wpdb->prefix}dbdelta_test (
    951                                 id bigint(20) NOT NULL AUTO_INCREMENT,
     975                                id bigint{$this->bigint_display_width} NOT NULL AUTO_INCREMENT,
    952976                                column_1 varchar(255) NOT NULL,
    953977                                column_2 text,
     
    967991                        "
    968992                        CREATE TABLE {$wpdb->prefix}dbdelta_test (
    969                                 id bigint(20) NOT NULL AUTO_INCREMENT,
     993                                id bigint{$this->bigint_display_width} NOT NULL AUTO_INCREMENT,
    970994                                column_1 varchar(255) NOT NULL,
    971995                                column_2 text,
     
    9851009                        "
    9861010                        CREATE TABLE {$wpdb->prefix}dbdelta_test (
    987                                 id bigint(20) NOT NULL AUTO_INCREMENT,
     1011                                id bigint{$this->bigint_display_width} NOT NULL AUTO_INCREMENT,
    9881012                                column_1 varchar(255) NOT NULL,
    9891013                                column_2 text,
Note: See TracChangeset for help on using the changeset viewer.