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.



git-svn-id: https://develop.svn.wordpress.org/trunk@37574 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Gary Pendergast 2016-05-26 04:58:13 +00:00
parent 96b71d7d89
commit a51a68fb75
2 changed files with 52 additions and 0 deletions

View File

@ -2200,6 +2200,7 @@ function dbDelta( $queries = '', $execute = true ) {
case 'fulltext':
case 'unique':
case 'key':
case 'spatial':
$validfield = false;
$indices[] = trim(trim($fld), ", \n");
break;
@ -2301,6 +2302,9 @@ function dbDelta( $queries = '', $execute = true ) {
if ( 'FULLTEXT' === strtoupper( $index_data['index_type'] ) ) {
$index_string .= 'FULLTEXT ';
}
if ( 'SPATIAL' === strtoupper( $index_data['index_type'] ) ) {
$index_string .= 'SPATIAL ';
}
$index_string .= 'KEY ';
if ($index_name != 'PRIMARY') {
$index_string .= $index_name;

View File

@ -488,4 +488,52 @@ class Tests_dbDelta extends WP_UnitTestCase {
$this->assertEmpty( $updates );
}
/**
* @ticket 36948
*/
function test_spatial_indices() {
global $wpdb;
if ( version_compare( $wpdb->db_version(), '5.4', '<' ) ) {
$this->markTestSkipped( 'Spatial indices require MySQL 5.4 and above.' );
}
$schema =
"
CREATE TABLE {$wpdb->prefix}spatial_index_test (
non_spatial bigint(20) unsigned NOT NULL,
spatial_value geometrycollection NOT NULL,
KEY non_spatial (non_spatial),
SPATIAL KEY spatial_key (spatial_value)
) ENGINE=MyISAM;
";
$wpdb->query( $schema );
$updates = dbDelta( $schema, false );
$this->assertEmpty( $updates );
$schema =
"
CREATE TABLE {$wpdb->prefix}spatial_index_test (
non_spatial bigint(20) unsigned NOT NULL,
spatial_value geometrycollection NOT NULL,
spatial_value2 geometrycollection NOT NULL,
KEY non_spatial (non_spatial),
SPATIAL KEY spatial_key (spatial_value)
SPATIAL KEY spatial_key2 (spatial_value2)
) ENGINE=MyISAM;
";
$updates = dbDelta( $schema, false );
$this->assertSame( array(
"{$wpdb->prefix}spatial_index_test.spatial_value2" => "Added column {$wpdb->prefix}spatial_index_test.spatial_value2",
"Added index {$wpdb->prefix}spatial_index_test SPATIAL KEY spatial_key2 (spatial_value2)"
), $updates );
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}spatial_index_test" );
}
}