Skip to content

[5.5] Blueprint Geo Spatial index #21070

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/Illuminate/Database/Schema/Blueprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ protected function addImpliedCommands()
protected function addFluentIndexes()
{
foreach ($this->columns as $column) {
foreach (['primary', 'unique', 'index'] as $index) {
foreach (['primary', 'unique', 'index', 'spatialIndex'] as $index) {
// If the index has been specified on the given column, but is simply equal
// to "true" (boolean), no name has been specified for this index so the
// index method can be called without a name and it will generate one.
Expand Down Expand Up @@ -385,6 +385,18 @@ public function index($columns, $name = null, $algorithm = null)
return $this->indexCommand('index', $columns, $name, $algorithm);
}

/**
* Specify a spatial index for the table.
*
* @param string|array $columns
* @param string $name
* @return \Illuminate\Support\Fluent
*/
public function spatialIndex($columns, $name = null)
{
return $this->indexCommand('spatialIndex', $columns, $name);
}

/**
* Specify a foreign key for the table.
*
Expand Down
12 changes: 12 additions & 0 deletions src/Illuminate/Database/Schema/Grammars/MySqlGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,18 @@ public function compileIndex(Blueprint $blueprint, Fluent $command)
return $this->compileKey($blueprint, $command, 'index');
}

/**
* Compile a spatial index key command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @return string
*/
public function compileSpatialIndex(Blueprint $blueprint, Fluent $command)
{
return $this->compileKey($blueprint, $command, 'spatial index');
}

/**
* Compile an index creation command.
*
Expand Down
20 changes: 20 additions & 0 deletions tests/Database/DatabaseMySqlSchemaGrammarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,26 @@ public function testAddingIndexWithAlgorithm()
$this->assertEquals('alter table `users` add index `baz` using hash(`foo`, `bar`)', $statements[0]);
}

public function testAddingSpatialIndex()
{
$blueprint = new Blueprint('users');
$blueprint->spatialIndex('foo', 'baz');
$statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());

$this->assertCount(1, $statements);
$this->assertEquals('alter table `users` add spatial index `baz`(`foo`)', $statements[0]);
}

public function testAddingFluentSpatialIndex()
{
$blueprint = new Blueprint('users');
$blueprint->point('foo')->spatialIndex('baz');
$statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());

$this->assertCount(2, $statements);
$this->assertEquals('alter table `users` add spatial index `baz`(`foo`)', $statements[1]);
}

public function testAddingForeignKey()
{
$blueprint = new Blueprint('users');
Expand Down