WordPress.org

Make WordPress Core

Changeset 37574


Ignore:
Timestamp:
05/26/2016 04:58:13 AM (2 years ago)
Author:
pento
Message:

Database: Add support for SPATIAL keys to dbDelta().

dbDelta() already supported spatial fields (by virtue of not checking field types), so it's nice to round that out with spatial key support, too.

Fixes #36948.

Location:
trunk
Files:
2 edited

Legend:

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

    r37538 r37574  
    22012201                case 'unique':
    22022202                case 'key':
     2203                case 'spatial':
    22032204                    $validfield = false;
    22042205                    $indices[] = trim(trim($fld), ", \n");
     
    23012302                if ( 'FULLTEXT' === strtoupper( $index_data['index_type'] ) ) {
    23022303                    $index_string .= 'FULLTEXT ';
     2304                }
     2305                if ( 'SPATIAL' === strtoupper( $index_data['index_type'] ) ) {
     2306                    $index_string .= 'SPATIAL ';
    23032307                }
    23042308                $index_string .= 'KEY ';
  • trunk/tests/phpunit/tests/dbdelta.php

    r37538 r37574  
    489489        $this->assertEmpty( $updates );
    490490    }
     491
     492    /**
     493     * @ticket 36948
     494     */
     495    function test_spatial_indices() {
     496        global $wpdb;
     497
     498        if ( version_compare( $wpdb->db_version(), '5.4', '<' ) ) {
     499            $this->markTestSkipped( 'Spatial indices require MySQL 5.4 and above.' );
     500        }
     501
     502        $schema =
     503            "
     504            CREATE TABLE {$wpdb->prefix}spatial_index_test (
     505                non_spatial bigint(20) unsigned NOT NULL,
     506                spatial_value geometrycollection NOT NULL,
     507                KEY non_spatial (non_spatial),
     508                SPATIAL KEY spatial_key (spatial_value)
     509            ) ENGINE=MyISAM;
     510            ";
     511
     512        $wpdb->query( $schema );
     513
     514        $updates = dbDelta( $schema, false );
     515
     516        $this->assertEmpty( $updates );
     517
     518        $schema =
     519            "
     520            CREATE TABLE {$wpdb->prefix}spatial_index_test (
     521                non_spatial bigint(20) unsigned NOT NULL,
     522                spatial_value geometrycollection NOT NULL,
     523                spatial_value2 geometrycollection NOT NULL,
     524                KEY non_spatial (non_spatial),
     525                SPATIAL KEY spatial_key (spatial_value)
     526                SPATIAL KEY spatial_key2 (spatial_value2)
     527            ) ENGINE=MyISAM;
     528            ";
     529
     530        $updates = dbDelta( $schema, false );
     531
     532        $this->assertSame( array(
     533            "{$wpdb->prefix}spatial_index_test.spatial_value2" => "Added column {$wpdb->prefix}spatial_index_test.spatial_value2",
     534            "Added index {$wpdb->prefix}spatial_index_test SPATIAL KEY spatial_key2 (spatial_value2)"
     535            ), $updates );
     536
     537        $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}spatial_index_test" );
     538    }
    491539}
Note: See TracChangeset for help on using the changeset viewer.