Skip to content
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
11 changes: 11 additions & 0 deletions src/Illuminate/Database/Schema/Blueprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,17 @@ public function dropIndex($index)
return $this->dropIndexCommand('dropIndex', 'index', $index);
}

/**
* Indicate that the given spatial index should be dropped.
*
* @param string|array $index
* @return \Illuminate\Support\Fluent
*/
public function dropSpatialIndex($index)
{
return $this->dropIndexCommand('dropSpatialIndex', 'spatialIndex', $index);
}

/**
* Indicate that the given foreign key should be dropped.
*
Expand Down
38 changes: 25 additions & 13 deletions src/Illuminate/Database/Schema/Grammars/MySqlGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,18 @@ public function compileDropIndex(Blueprint $blueprint, Fluent $command)
return "alter table {$this->wrapTable($blueprint)} drop index {$index}";
}

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

/**
* Compile a drop foreign key command.
*
Expand Down Expand Up @@ -690,7 +702,7 @@ protected function typeMacAddress(Fluent $column)
}

/**
* Create the column definition for a geometry type.
* Create the column definition for a spatial Geometry type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
Expand All @@ -701,7 +713,7 @@ public function typeGeometry(Fluent $column)
}

/**
* Create the column definition for a point type.
* Create the column definition for a spatial Point type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
Expand All @@ -712,18 +724,18 @@ public function typePoint(Fluent $column)
}

/**
* Create the column definition for a linestring type.
* Create the column definition for a spatial LineString type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
public function typeLinestring(Fluent $column)
public function typeLineString(Fluent $column)
{
return 'linestring';
}

/**
* Create the column definition for a polygon type.
* Create the column definition for a spatial Polygon type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
Expand All @@ -734,45 +746,45 @@ public function typePolygon(Fluent $column)
}

/**
* Create the column definition for a geometrycollection type.
* Create the column definition for a spatial GeometryCollection type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
public function typeGeometrycollection(Fluent $column)
public function typeGeometryCollection(Fluent $column)
{
return 'geometrycollection';
}

/**
* Create the column definition for a multipoint type.
* Create the column definition for a spatial MultiPoint type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
public function typeMultipoint(Fluent $column)
public function typeMultiPoint(Fluent $column)
{
return 'multipoint';
}

/**
* Create the column definition for a multilinestring type.
* Create the column definition for a spatial MultiLineString type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
public function typeMultilinestring(Fluent $column)
public function typeMultiLineString(Fluent $column)
{
return 'multilinestring';
}

/**
* Create the column definition for a multipolygon type.
* Create the column definition for a spatial MultiPolygon type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
public function typeMultipolygon(Fluent $column)
public function typeMultiPolygon(Fluent $column)
{
return 'multipolygon';
}
Expand Down
62 changes: 45 additions & 17 deletions src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Illuminate\Database\Schema\Grammars;

use Exception;
use RuntimeException;
use Illuminate\Support\Fluent;
use Illuminate\Database\Schema\Blueprint;

Expand Down Expand Up @@ -127,6 +127,20 @@ public function compileIndex(Blueprint $blueprint, Fluent $command)
);
}

/**
* 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)
{
$command->algorithm = 'gist';

return $this->compileIndex($blueprint, $command);
}

/**
* Compile a foreign key command.
*
Expand Down Expand Up @@ -249,6 +263,18 @@ public function compileDropIndex(Blueprint $blueprint, Fluent $command)
return "drop index {$this->wrap($command->index)}";
}

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

/**
* Compile a drop foreign key command.
*
Expand Down Expand Up @@ -629,18 +655,18 @@ protected function typeMacAddress(Fluent $column)
}

/**
* Create the column definition for a geometry type.
* Create the column definition for a spatial Geometry type.
*
* @param \Illuminate\Support\Fluent $column
* @throws \Exception
* @throws \RuntimeException
*/
protected function typeGeometry(Fluent $column)
{
throw new Exception('Geometry data type not supported for current database engine.');
throw new RuntimeException('The database driver in use does not support the Geometry spatial column type.');
}

/**
* Create the column definition for a point type.
* Create the column definition for a spatial Point type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
Expand All @@ -651,18 +677,18 @@ protected function typePoint(Fluent $column)
}

/**
* Create the column definition for a linestring type.
* Create the column definition for a spatial LineString type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeLinestring(Fluent $column)
protected function typeLineString(Fluent $column)
{
return $this->formatPostGisType('linestring');
}

/**
* Create the column definition for a polygon type.
* Create the column definition for a spatial Polygon type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
Expand All @@ -673,56 +699,58 @@ protected function typePolygon(Fluent $column)
}

/**
* Create the column definition for a geometrycollection type.
* Create the column definition for a spatial GeometryCollection type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeGeometrycollection(Fluent $column)
protected function typeGeometryCollection(Fluent $column)
{
return $this->formatPostGisType('geometrycollection');
}

/**
* Create the column definition for a multipoint type.
* Create the column definition for a spatial MultiPoint type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeMultipoint(Fluent $column)
protected function typeMultiPoint(Fluent $column)
{
return $this->formatPostGisType('multipoint');
}

/**
* Create the column definition for a multilinestring type.
* Create the column definition for a spatial MultiLineString type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
public function typeMultilinestring(Fluent $column)
public function typeMultiLineString(Fluent $column)
{
return $this->formatPostGisType('multilinestring');
}

/**
* Create the column definition for a multipolygon type.
* Create the column definition for a spatial MultiPolygon type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeMultipolygon(Fluent $column)
protected function typeMultiPolygon(Fluent $column)
{
return $this->formatPostGisType('multipolygon');
}

/**
* Format the column definition for a PostGIS spatial type.
*
* @param string $type
* @return string
*/
private function formatPostGisType(string $type)
{
return "geography({$type}, 4326)";
return "geography($type, 4326)";
}

/**
Expand Down
Loading