Skip to content

Commit

Permalink
Moved breaking changes from laravel#30545 to 7.x, updating laravel#30545
Browse files Browse the repository at this point in the history
 to be not breaking.
  • Loading branch information
raymondtri committed Nov 9, 2019
1 parent 009d4e9 commit aaccd52
Showing 1 changed file with 52 additions and 18 deletions.
70 changes: 52 additions & 18 deletions src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Illuminate\Database\Schema\Grammars;

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

class PostgresGrammar extends Grammar
{
Expand All @@ -19,7 +19,7 @@ class PostgresGrammar extends Grammar
*
* @var array
*/
protected $modifiers = ['Increment', 'Nullable', 'Default'];
protected $modifiers = ['Collate', 'Increment', 'Nullable', 'Default'];

/**
* The columns available as serials.
Expand Down Expand Up @@ -200,7 +200,7 @@ public function compileDropIfExists(Blueprint $blueprint, Fluent $command)
/**
* Compile the SQL needed to drop all tables.
*
* @param string $tables
* @param array $tables
* @return string
*/
public function compileDropAllTables($tables)
Expand All @@ -211,7 +211,7 @@ public function compileDropAllTables($tables)
/**
* Compile the SQL needed to drop all views.
*
* @param string $views
* @param array $views
* @return string
*/
public function compileDropAllViews($views)
Expand Down Expand Up @@ -685,7 +685,7 @@ protected function typeDateTimeTz(Fluent $column)
*/
protected function typeTime(Fluent $column)
{
return "time($column->precision) without time zone";
return 'time'.(is_null($column->precision) ? '' : "($column->precision)").' without time zone';
}

/**
Expand All @@ -696,7 +696,7 @@ protected function typeTime(Fluent $column)
*/
protected function typeTimeTz(Fluent $column)
{
return "time($column->precision) with time zone";
return 'time'.(is_null($column->precision) ? '' : "($column->precision)").' with time zone';
}

/**
Expand All @@ -707,7 +707,7 @@ protected function typeTimeTz(Fluent $column)
*/
protected function typeTimestamp(Fluent $column)
{
$columnType = "timestamp($column->precision) without time zone";
$columnType = 'timestamp'.(is_null($column->precision) ? '' : "($column->precision)").' without time zone';

return $column->useCurrent ? "$columnType default CURRENT_TIMESTAMP" : $columnType;
}
Expand All @@ -720,7 +720,7 @@ protected function typeTimestamp(Fluent $column)
*/
protected function typeTimestampTz(Fluent $column)
{
$columnType = "timestamp($column->precision) with time zone";
$columnType = 'timestamp'.(is_null($column->precision) ? '' : "($column->precision)").' with time zone';

return $column->useCurrent ? "$columnType default CURRENT_TIMESTAMP" : $columnType;
}
Expand Down 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,18 +865,52 @@ 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);
}

/**
* 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 === null ? '4326' : $column->projection).')';
}

if ($column->projection === null) {
return "geometry($type)";
}

return "geometry($type, $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

0 comments on commit aaccd52

Please sign in to comment.