Skip to content
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

[7.x] Added support for separation between geometry and geography types #30552

Closed
wants to merge 4 commits into from
Closed
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
50 changes: 40 additions & 10 deletions src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ protected function typeMacAddress(Fluent $column)
*/
protected function typeGeometry(Fluent $column)
{
return $this->formatPostGisType('geometry');
return $this->formatPostGisType('geometry', $column);
}

/**
Expand All @@ -799,7 +799,7 @@ protected function typeGeometry(Fluent $column)
*/
protected function typePoint(Fluent $column)
{
return $this->formatPostGisType('point');
return $this->formatPostGisType('point', $column);
}

/**
Expand All @@ -810,7 +810,7 @@ protected function typePoint(Fluent $column)
*/
protected function typeLineString(Fluent $column)
{
return $this->formatPostGisType('linestring');
return $this->formatPostGisType('linestring', $column);
}

/**
Expand All @@ -821,7 +821,7 @@ protected function typeLineString(Fluent $column)
*/
protected function typePolygon(Fluent $column)
{
return $this->formatPostGisType('polygon');
return $this->formatPostGisType('polygon', $column);
}

/**
Expand All @@ -832,7 +832,7 @@ protected function typePolygon(Fluent $column)
*/
protected function typeGeometryCollection(Fluent $column)
{
return $this->formatPostGisType('geometrycollection');
return $this->formatPostGisType('geometrycollection', $column);
}

/**
Expand All @@ -843,7 +843,7 @@ protected function typeGeometryCollection(Fluent $column)
*/
protected function typeMultiPoint(Fluent $column)
{
return $this->formatPostGisType('multipoint');
return $this->formatPostGisType('multipoint', $column);
}

/**
Expand All @@ -854,7 +854,7 @@ protected function typeMultiPoint(Fluent $column)
*/
public function typeMultiLineString(Fluent $column)
{
return $this->formatPostGisType('multilinestring');
return $this->formatPostGisType('multilinestring', $column);
}

/**
Expand All @@ -865,7 +865,18 @@ public function typeMultiLineString(Fluent $column)
*/
protected function typeMultiPolygon(Fluent $column)
{
return $this->formatPostGisType('multipolygon');
return $this->formatPostGisType('multipolygon', $column);
}

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

/**
Expand All @@ -883,11 +894,30 @@ protected function typeMultiPolygonZ(Fluent $column)
* Format the column definition for a PostGIS spatial type.
*
* @param string $type
* @param Fluent $column
* @return string
*/
private function formatPostGisType(string $type)
private function formatPostGisType(string $type, Fluent $column)
{
if ($column->geography !== null) {
return "geography($type, ".($column->projection ?? '4326').')';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return sprintf('geography(%s, %s)', $type, $column->projection ?? '4326');

}

return "geometry($type".($column->projection === null ? '' : ", $column->projection").')';
}

/**
* Get the SQL for a collation column modifier.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $column
* @return string|null
*/
protected function modifyCollate(Blueprint $blueprint, Fluent $column)
{
return "geography($type, 4326)";
if (! is_null($column->collation)) {
return ' collate '.$this->wrapValue($column->collation);
}
}

/**
Expand Down