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

[5.5] Geo Spatial blueprint methods #21056

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
88 changes: 88 additions & 0 deletions src/Illuminate/Database/Schema/Blueprint.php
Expand Up @@ -924,6 +924,94 @@ public function macAddress($column)
return $this->addColumn('macAddress', $column);
}

/**
* Create a new geometry column on the table.
*
* @param string $column
* @return \Illuminate\Support\Fluent
*/
public function geometry($column)
{
return $this->addColumn('geometry', $column);
}

/**
* Create a new point column on the table.
*
* @param string $column
* @return \Illuminate\Support\Fluent
*/
public function point($column)
{
return $this->addColumn('point', $column);
}

/**
* Create a new linestring column on the table.
*
* @param string $column
* @return \Illuminate\Support\Fluent
*/
public function lineString($column)
{
return $this->addColumn('linestring', $column);
}

/**
* Create a new polygon column on the table.
*
* @param string $column
* @return \Illuminate\Support\Fluent
*/
public function polygon($column)
{
return $this->addColumn('polygon', $column);
}

/**
* Create a new geometrycollection column on the table.
*
* @param string $column
* @return \Illuminate\Support\Fluent
*/
public function geometryCollection($column)
{
return $this->addColumn('geometrycollection', $column);
}

/**
* Create a new multipoint column on the table.
*
* @param string $column
* @return \Illuminate\Support\Fluent
*/
public function multiPoint($column)
{
return $this->addColumn('multipoint', $column);
}

/**
* Create a new multilinestring column on the table.
*
* @param string $column
* @return \Illuminate\Support\Fluent
*/
public function multiLineString($column)
{
return $this->addColumn('multilinestring', $column);
}

/**
* Create a new multipolygon column on the table.
*
* @param string $column
* @return \Illuminate\Support\Fluent
*/
public function multiPolygon($column)
{
return $this->addColumn('multipolygon', $column);
}

/**
* Add the proper columns for a polymorphic table.
*
Expand Down
88 changes: 88 additions & 0 deletions src/Illuminate/Database/Schema/Grammars/MySqlGrammar.php
Expand Up @@ -677,6 +677,94 @@ protected function typeMacAddress(Fluent $column)
return 'varchar(17)';
}

/**
* Create the column definition for a geometry type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
public function typeGeometry(Fluent $column)
{
return 'geometry';
}

/**
* Create the column definition for a point type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
public function typePoint(Fluent $column)
{
return 'point';
}

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

/**
* Create the column definition for a polygon type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
public function typePolygon(Fluent $column)
{
return 'polygon';
}

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

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

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

/**
* Create the column definition for a multipolygon type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
public function typeMultipolygon(Fluent $column)
{
return 'multipolygon';
}

/**
* Get the SQL for a generated virtual column modifier.
*
Expand Down
97 changes: 97 additions & 0 deletions src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php
Expand Up @@ -605,6 +605,103 @@ protected function typeMacAddress(Fluent $column)
return 'macaddr';
}

/**
* Create the column definition for a geometry type.
*
* @param \Illuminate\Support\Fluent $column
* @throws \Exception
*/
protected function typeGeometry(Fluent $column)
{
throw new \Exception('Geometry data type not supported for current database engine.');
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Didn't know what type of exception would be better to throw here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've thought about RuntimeException too.

}

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

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

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

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

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

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

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

/**
* @param string $type
* @return string
*/
private function formatPostGisType(string $type)
{
return "geography({$type}, 4326)";
}

/**
* Get the SQL for a nullable column modifier.
*
Expand Down
88 changes: 88 additions & 0 deletions src/Illuminate/Database/Schema/Grammars/SQLiteGrammar.php
Expand Up @@ -641,6 +641,94 @@ protected function typeMacAddress(Fluent $column)
return 'varchar';
}

/**
* Create the column definition for a geometry type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
public function typeGeometry(Fluent $column)
{
return 'geometry';
}

/**
* Create the column definition for a point type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
public function typePoint(Fluent $column)
{
return 'point';
}

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

/**
* Create the column definition for a polygon type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
public function typePolygon(Fluent $column)
{
return 'polygon';
}

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

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

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

/**
* Create the column definition for a multipolygon type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
public function typeMultipolygon(Fluent $column)
{
return 'multipolygon';
}

/**
* Get the SQL for a nullable column modifier.
*
Expand Down