From aaccd52084e73d8c4a73f1f34a72298d13e65f4e Mon Sep 17 00:00:00 2001 From: Ray Tri Date: Sat, 9 Nov 2019 12:38:57 -0500 Subject: [PATCH 1/3] Moved breaking changes from #30545 to 7.x, updating #30545 to be not breaking. --- .../Schema/Grammars/PostgresGrammar.php | 70 ++++++++++++++----- 1 file changed, 52 insertions(+), 18 deletions(-) diff --git a/src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php b/src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php index c844cd1fcf54..3808197f2c89 100755 --- a/src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php +++ b/src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php @@ -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 { @@ -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. @@ -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) @@ -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) @@ -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'; } /** @@ -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'; } /** @@ -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; } @@ -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; } @@ -788,7 +788,7 @@ protected function typeMacAddress(Fluent $column) */ protected function typeGeometry(Fluent $column) { - return $this->formatPostGisType('geometry'); + return $this->formatPostGisType('geometry', $column); } /** @@ -799,7 +799,7 @@ protected function typeGeometry(Fluent $column) */ protected function typePoint(Fluent $column) { - return $this->formatPostGisType('point'); + return $this->formatPostGisType('point', $column); } /** @@ -810,7 +810,7 @@ protected function typePoint(Fluent $column) */ protected function typeLineString(Fluent $column) { - return $this->formatPostGisType('linestring'); + return $this->formatPostGisType('linestring', $column); } /** @@ -821,7 +821,7 @@ protected function typeLineString(Fluent $column) */ protected function typePolygon(Fluent $column) { - return $this->formatPostGisType('polygon'); + return $this->formatPostGisType('polygon', $column); } /** @@ -832,7 +832,7 @@ protected function typePolygon(Fluent $column) */ protected function typeGeometryCollection(Fluent $column) { - return $this->formatPostGisType('geometrycollection'); + return $this->formatPostGisType('geometrycollection', $column); } /** @@ -843,7 +843,7 @@ protected function typeGeometryCollection(Fluent $column) */ protected function typeMultiPoint(Fluent $column) { - return $this->formatPostGisType('multipoint'); + return $this->formatPostGisType('multipoint', $column); } /** @@ -854,7 +854,7 @@ protected function typeMultiPoint(Fluent $column) */ public function typeMultiLineString(Fluent $column) { - return $this->formatPostGisType('multilinestring'); + return $this->formatPostGisType('multilinestring', $column); } /** @@ -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); + } } /** From 9da69ba0520ae51deeba6546cc20a7c35750f7b1 Mon Sep 17 00:00:00 2001 From: Ray Tri Date: Sat, 9 Nov 2019 12:50:21 -0500 Subject: [PATCH 2/3] Fixed typo --- src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php b/src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php index 9168f78bf209..12328a0221d7 100755 --- a/src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php +++ b/src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php @@ -907,7 +907,7 @@ private function formatPostGisType(string $type, Fluent $column) return "geometry($type)"; } - return "geometry($type, $projection)"; + return "geometry($type, $column->projection)"; } /** From 98fc5cea4ed321bf1999329ef67e06532e49ef73 Mon Sep 17 00:00:00 2001 From: Ray Tri Date: Sat, 9 Nov 2019 13:02:36 -0500 Subject: [PATCH 3/3] Refactored with null coalescer and simplified logic more --- .../Database/Schema/Grammars/PostgresGrammar.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php b/src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php index 12328a0221d7..4915cbde4c3a 100755 --- a/src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php +++ b/src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php @@ -900,14 +900,10 @@ protected function typeMultiPolygonZ(Fluent $column) private function formatPostGisType(string $type, Fluent $column) { if ($column->geography !== null) { - return "geography($type, ".($column->projection === null ? '4326' : $column->projection).')'; + return "geography($type, ".($column->projection ?? '4326').')'; } - if ($column->projection === null) { - return "geometry($type)"; - } - - return "geometry($type, $column->projection)"; + return "geometry($type".($column->projection === null ? '' : ", $column->projection").')'; } /**