diff --git a/src/Illuminate/Database/Schema/Blueprint.php b/src/Illuminate/Database/Schema/Blueprint.php index 98590946a93f..a5ef15078a4f 100755 --- a/src/Illuminate/Database/Schema/Blueprint.php +++ b/src/Illuminate/Database/Schema/Blueprint.php @@ -1348,100 +1348,26 @@ public function macAddress($column = 'mac_address') * Create a new geometry column on the table. * * @param string $column + * @param string|null $subtype + * @param int $srid * @return \Illuminate\Database\Schema\ColumnDefinition */ - public function geometry($column) + public function geometry($column, $subtype = null, $srid = 0) { - return $this->addColumn('geometry', $column); + return $this->addColumn('geometry', $column, compact('subtype', 'srid')); } /** - * Create a new point column on the table. + * Create a new geography column on the table. * * @param string $column - * @param int|null $srid + * @param string|null $subtype + * @param int $srid * @return \Illuminate\Database\Schema\ColumnDefinition */ - public function point($column, $srid = null) + public function geography($column, $subtype = null, $srid = 4326) { - return $this->addColumn('point', $column, compact('srid')); - } - - /** - * Create a new linestring column on the table. - * - * @param string $column - * @return \Illuminate\Database\Schema\ColumnDefinition - */ - public function lineString($column) - { - return $this->addColumn('linestring', $column); - } - - /** - * Create a new polygon column on the table. - * - * @param string $column - * @return \Illuminate\Database\Schema\ColumnDefinition - */ - public function polygon($column) - { - return $this->addColumn('polygon', $column); - } - - /** - * Create a new geometrycollection column on the table. - * - * @param string $column - * @return \Illuminate\Database\Schema\ColumnDefinition - */ - public function geometryCollection($column) - { - return $this->addColumn('geometrycollection', $column); - } - - /** - * Create a new multipoint column on the table. - * - * @param string $column - * @return \Illuminate\Database\Schema\ColumnDefinition - */ - public function multiPoint($column) - { - return $this->addColumn('multipoint', $column); - } - - /** - * Create a new multilinestring column on the table. - * - * @param string $column - * @return \Illuminate\Database\Schema\ColumnDefinition - */ - public function multiLineString($column) - { - return $this->addColumn('multilinestring', $column); - } - - /** - * Create a new multipolygon column on the table. - * - * @param string $column - * @return \Illuminate\Database\Schema\ColumnDefinition - */ - public function multiPolygon($column) - { - return $this->addColumn('multipolygon', $column); - } - - /** - * Create a new multipolygon column on the table. - * - * @param string $column - * @return \Illuminate\Database\Schema\ColumnDefinition - */ - public function multiPolygonZ($column) - { - return $this->addColumn('multipolygonz', $column); + return $this->addColumn('geography', $column, compact('subtype', 'srid')); } /** diff --git a/src/Illuminate/Database/Schema/Grammars/MySqlGrammar.php b/src/Illuminate/Database/Schema/Grammars/MySqlGrammar.php index 07bd41291414..a0d9dab6d191 100755 --- a/src/Illuminate/Database/Schema/Grammars/MySqlGrammar.php +++ b/src/Illuminate/Database/Schema/Grammars/MySqlGrammar.php @@ -18,7 +18,7 @@ class MySqlGrammar extends Grammar */ protected $modifiers = [ 'Unsigned', 'Charset', 'Collate', 'VirtualAs', 'StoredAs', 'Nullable', - 'Srid', 'Default', 'OnUpdate', 'Invisible', 'Increment', 'Comment', 'After', 'First', + 'Default', 'OnUpdate', 'Invisible', 'Increment', 'Comment', 'After', 'First', ]; /** @@ -1077,86 +1077,29 @@ protected function typeMacAddress(Fluent $column) * @param \Illuminate\Support\Fluent $column * @return string */ - public function typeGeometry(Fluent $column) + protected function typeGeometry(Fluent $column) { - return 'geometry'; - } - - /** - * Create the column definition for a spatial Point type. - * - * @param \Illuminate\Support\Fluent $column - * @return string - */ - public function typePoint(Fluent $column) - { - return 'point'; - } - - /** - * Create the column definition for a spatial LineString type. - * - * @param \Illuminate\Support\Fluent $column - * @return string - */ - public function typeLineString(Fluent $column) - { - return 'linestring'; - } - - /** - * Create the column definition for a spatial Polygon type. - * - * @param \Illuminate\Support\Fluent $column - * @return string - */ - public function typePolygon(Fluent $column) - { - return 'polygon'; - } - - /** - * Create the column definition for a spatial GeometryCollection type. - * - * @param \Illuminate\Support\Fluent $column - * @return string - */ - public function typeGeometryCollection(Fluent $column) - { - return 'geometrycollection'; - } + $subtype = $column->subtype ? strtolower($column->subtype) : null; - /** - * Create the column definition for a spatial MultiPoint type. - * - * @param \Illuminate\Support\Fluent $column - * @return string - */ - public function typeMultiPoint(Fluent $column) - { - return 'multipoint'; - } + if (! in_array($subtype, ['point', 'linestring', 'polygon', 'geometrycollection', 'multipoint', 'multilinestring', 'multipolygon'])) { + $subtype = null; + } - /** - * Create the column definition for a spatial MultiLineString type. - * - * @param \Illuminate\Support\Fluent $column - * @return string - */ - public function typeMultiLineString(Fluent $column) - { - return 'multilinestring'; + return sprintf('%s%s', + $subtype ?? 'geometry', + $column->srid ? ' srid '.$column->srid : '' + ); } /** - * Create the column definition for a spatial MultiPolygon type. + * Create the column definition for a spatial Geography type. * * @param \Illuminate\Support\Fluent $column * @return string */ - public function typeMultiPolygon(Fluent $column) + protected function typeGeography(Fluent $column) { - return 'multipolygon'; + return $this->typeGeometry($column); } /** @@ -1377,20 +1320,6 @@ protected function modifyComment(Blueprint $blueprint, Fluent $column) } } - /** - * Get the SQL for a SRID column modifier. - * - * @param \Illuminate\Database\Schema\Blueprint $blueprint - * @param \Illuminate\Support\Fluent $column - * @return string|null - */ - protected function modifySrid(Blueprint $blueprint, Fluent $column) - { - if (is_int($column->srid) && $column->srid > 0) { - return ' srid '.$column->srid; - } - } - /** * Wrap a single string in keyword identifiers. * diff --git a/src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php b/src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php index e6b66bc0d01d..d5d4902465eb 100755 --- a/src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php +++ b/src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php @@ -1084,115 +1084,32 @@ protected function typeMacAddress(Fluent $column) */ protected function typeGeometry(Fluent $column) { - return $this->formatPostGisType('geometry', $column); - } - - /** - * Create the column definition for a spatial Point type. - * - * @param \Illuminate\Support\Fluent $column - * @return string - */ - protected function typePoint(Fluent $column) - { - return $this->formatPostGisType('point', $column); - } - - /** - * Create the column definition for a spatial LineString type. - * - * @param \Illuminate\Support\Fluent $column - * @return string - */ - protected function typeLineString(Fluent $column) - { - return $this->formatPostGisType('linestring', $column); - } - - /** - * Create the column definition for a spatial Polygon type. - * - * @param \Illuminate\Support\Fluent $column - * @return string - */ - protected function typePolygon(Fluent $column) - { - return $this->formatPostGisType('polygon', $column); - } - - /** - * Create the column definition for a spatial GeometryCollection type. - * - * @param \Illuminate\Support\Fluent $column - * @return string - */ - protected function typeGeometryCollection(Fluent $column) - { - return $this->formatPostGisType('geometrycollection', $column); - } - - /** - * Create the column definition for a spatial MultiPoint type. - * - * @param \Illuminate\Support\Fluent $column - * @return string - */ - protected function typeMultiPoint(Fluent $column) - { - return $this->formatPostGisType('multipoint', $column); - } - - /** - * Create the column definition for a spatial MultiLineString type. - * - * @param \Illuminate\Support\Fluent $column - * @return string - */ - public function typeMultiLineString(Fluent $column) - { - return $this->formatPostGisType('multilinestring', $column); - } - - /** - * Create the column definition for a spatial MultiPolygon type. - * - * @param \Illuminate\Support\Fluent $column - * @return string - */ - protected function typeMultiPolygon(Fluent $column) - { - return $this->formatPostGisType('multipolygon', $column); - } + if ($column->subtype) { + return sprintf('geometry(%s%s)', + strtolower($column->subtype), + $column->srid ? ','.$column->srid : '' + ); + } - /** - * 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); + return 'geometry'; } /** - * Format the column definition for a PostGIS spatial type. + * Create the column definition for a spatial Geography type. * - * @param string $type * @param \Illuminate\Support\Fluent $column * @return string */ - private function formatPostGisType($type, Fluent $column) + protected function typeGeography(Fluent $column) { - if ($column->isGeometry === null) { - return sprintf('geography(%s, %s)', $type, $column->projection ?? '4326'); - } - - if ($column->projection !== null) { - return sprintf('geometry(%s, %s)', $type, $column->projection); + if ($column->subtype) { + return sprintf('geography(%s%s)', + strtolower($column->subtype), + $column->srid ? ','.$column->srid : '' + ); } - return "geometry({$type})"; + return 'geography'; } /** diff --git a/src/Illuminate/Database/Schema/Grammars/SQLiteGrammar.php b/src/Illuminate/Database/Schema/Grammars/SQLiteGrammar.php index fcbaf0798685..e2fc795680d7 100644 --- a/src/Illuminate/Database/Schema/Grammars/SQLiteGrammar.php +++ b/src/Illuminate/Database/Schema/Grammars/SQLiteGrammar.php @@ -980,86 +980,20 @@ protected function typeMacAddress(Fluent $column) * @param \Illuminate\Support\Fluent $column * @return string */ - public function typeGeometry(Fluent $column) + protected function typeGeometry(Fluent $column) { return 'geometry'; } /** - * Create the column definition for a spatial Point type. + * Create the column definition for a spatial Geography type. * * @param \Illuminate\Support\Fluent $column * @return string */ - public function typePoint(Fluent $column) + protected function typeGeography(Fluent $column) { - return 'point'; - } - - /** - * Create the column definition for a spatial LineString type. - * - * @param \Illuminate\Support\Fluent $column - * @return string - */ - public function typeLineString(Fluent $column) - { - return 'linestring'; - } - - /** - * Create the column definition for a spatial Polygon type. - * - * @param \Illuminate\Support\Fluent $column - * @return string - */ - public function typePolygon(Fluent $column) - { - return 'polygon'; - } - - /** - * Create the column definition for a spatial GeometryCollection type. - * - * @param \Illuminate\Support\Fluent $column - * @return string - */ - public function typeGeometryCollection(Fluent $column) - { - return 'geometrycollection'; - } - - /** - * Create the column definition for a spatial MultiPoint type. - * - * @param \Illuminate\Support\Fluent $column - * @return string - */ - public function typeMultiPoint(Fluent $column) - { - return 'multipoint'; - } - - /** - * Create the column definition for a spatial MultiLineString type. - * - * @param \Illuminate\Support\Fluent $column - * @return string - */ - public function typeMultiLineString(Fluent $column) - { - return 'multilinestring'; - } - - /** - * Create the column definition for a spatial MultiPolygon type. - * - * @param \Illuminate\Support\Fluent $column - * @return string - */ - public function typeMultiPolygon(Fluent $column) - { - return 'multipolygon'; + return $this->typeGeometry($column); } /** diff --git a/src/Illuminate/Database/Schema/Grammars/SqlServerGrammar.php b/src/Illuminate/Database/Schema/Grammars/SqlServerGrammar.php index 72cb8c2ef975..7914b9c66368 100755 --- a/src/Illuminate/Database/Schema/Grammars/SqlServerGrammar.php +++ b/src/Illuminate/Database/Schema/Grammars/SqlServerGrammar.php @@ -957,84 +957,18 @@ protected function typeMacAddress(Fluent $column) * @param \Illuminate\Support\Fluent $column * @return string */ - public function typeGeometry(Fluent $column) + protected function typeGeometry(Fluent $column) { - return 'geography'; - } - - /** - * Create the column definition for a spatial Point type. - * - * @param \Illuminate\Support\Fluent $column - * @return string - */ - public function typePoint(Fluent $column) - { - return 'geography'; - } - - /** - * Create the column definition for a spatial LineString type. - * - * @param \Illuminate\Support\Fluent $column - * @return string - */ - public function typeLineString(Fluent $column) - { - return 'geography'; - } - - /** - * Create the column definition for a spatial Polygon type. - * - * @param \Illuminate\Support\Fluent $column - * @return string - */ - public function typePolygon(Fluent $column) - { - return 'geography'; - } - - /** - * Create the column definition for a spatial GeometryCollection type. - * - * @param \Illuminate\Support\Fluent $column - * @return string - */ - public function typeGeometryCollection(Fluent $column) - { - return 'geography'; - } - - /** - * Create the column definition for a spatial MultiPoint type. - * - * @param \Illuminate\Support\Fluent $column - * @return string - */ - public function typeMultiPoint(Fluent $column) - { - return 'geography'; - } - - /** - * Create the column definition for a spatial MultiLineString type. - * - * @param \Illuminate\Support\Fluent $column - * @return string - */ - public function typeMultiLineString(Fluent $column) - { - return 'geography'; + return 'geometry'; } /** - * Create the column definition for a spatial MultiPolygon type. + * Create the column definition for a spatial Geography type. * * @param \Illuminate\Support\Fluent $column * @return string */ - public function typeMultiPolygon(Fluent $column) + protected function typeGeography(Fluent $column) { return 'geography'; } diff --git a/tests/Database/DatabaseMySqlSchemaGrammarTest.php b/tests/Database/DatabaseMySqlSchemaGrammarTest.php index 3c1cea72fd49..e5eb104605ea 100755 --- a/tests/Database/DatabaseMySqlSchemaGrammarTest.php +++ b/tests/Database/DatabaseMySqlSchemaGrammarTest.php @@ -411,7 +411,7 @@ public function testAddingSpatialIndex() public function testAddingFluentSpatialIndex() { $blueprint = new Blueprint('geo'); - $blueprint->point('coordinates')->spatialIndex(); + $blueprint->geometry('coordinates', 'point')->spatialIndex(); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); $this->assertCount(2, $statements); @@ -1174,10 +1174,20 @@ public function testAddingGeometry() $this->assertSame('alter table `geo` add `coordinates` geometry not null', $statements[0]); } + public function testAddingGeography() + { + $blueprint = new Blueprint('geo'); + $blueprint->geography('coordinates'); + $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); + + $this->assertCount(1, $statements); + $this->assertSame('alter table `geo` add `coordinates` geometry srid 4326 not null', $statements[0]); + } + public function testAddingPoint() { $blueprint = new Blueprint('geo'); - $blueprint->point('coordinates'); + $blueprint->geometry('coordinates', 'point'); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); $this->assertCount(1, $statements); @@ -1187,27 +1197,27 @@ public function testAddingPoint() public function testAddingPointWithSrid() { $blueprint = new Blueprint('geo'); - $blueprint->point('coordinates', 4326); + $blueprint->geometry('coordinates', 'point', 4326); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); $this->assertCount(1, $statements); - $this->assertSame('alter table `geo` add `coordinates` point not null srid 4326', $statements[0]); + $this->assertSame('alter table `geo` add `coordinates` point srid 4326 not null', $statements[0]); } public function testAddingPointWithSridColumn() { $blueprint = new Blueprint('geo'); - $blueprint->point('coordinates', 4326)->after('id'); + $blueprint->geometry('coordinates', 'point', 4326)->after('id'); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); $this->assertCount(1, $statements); - $this->assertSame('alter table `geo` add `coordinates` point not null srid 4326 after `id`', $statements[0]); + $this->assertSame('alter table `geo` add `coordinates` point srid 4326 not null after `id`', $statements[0]); } public function testAddingLineString() { $blueprint = new Blueprint('geo'); - $blueprint->linestring('coordinates'); + $blueprint->geometry('coordinates', 'linestring'); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); $this->assertCount(1, $statements); @@ -1217,7 +1227,7 @@ public function testAddingLineString() public function testAddingPolygon() { $blueprint = new Blueprint('geo'); - $blueprint->polygon('coordinates'); + $blueprint->geometry('coordinates', 'polygon'); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); $this->assertCount(1, $statements); @@ -1227,7 +1237,7 @@ public function testAddingPolygon() public function testAddingGeometryCollection() { $blueprint = new Blueprint('geo'); - $blueprint->geometrycollection('coordinates'); + $blueprint->geometry('coordinates', 'geometrycollection'); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); $this->assertCount(1, $statements); @@ -1237,7 +1247,7 @@ public function testAddingGeometryCollection() public function testAddingMultiPoint() { $blueprint = new Blueprint('geo'); - $blueprint->multipoint('coordinates'); + $blueprint->geometry('coordinates', 'multipoint'); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); $this->assertCount(1, $statements); @@ -1247,7 +1257,7 @@ public function testAddingMultiPoint() public function testAddingMultiLineString() { $blueprint = new Blueprint('geo'); - $blueprint->multilinestring('coordinates'); + $blueprint->geometry('coordinates', 'multilinestring'); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); $this->assertCount(1, $statements); @@ -1257,7 +1267,7 @@ public function testAddingMultiLineString() public function testAddingMultiPolygon() { $blueprint = new Blueprint('geo'); - $blueprint->multipolygon('coordinates'); + $blueprint->geometry('coordinates', 'multipolygon'); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); $this->assertCount(1, $statements); diff --git a/tests/Database/DatabasePostgresSchemaGrammarTest.php b/tests/Database/DatabasePostgresSchemaGrammarTest.php index 8f1fc47b6019..38dcd2f1075d 100755 --- a/tests/Database/DatabasePostgresSchemaGrammarTest.php +++ b/tests/Database/DatabasePostgresSchemaGrammarTest.php @@ -332,7 +332,7 @@ public function testAddingSpatialIndex() public function testAddingFluentSpatialIndex() { $blueprint = new Blueprint('geo'); - $blueprint->point('coordinates')->spatialIndex(); + $blueprint->geometry('coordinates', 'point')->spatialIndex(); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); $this->assertCount(2, $statements); @@ -1062,77 +1062,97 @@ public function testAddingGeometry() $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); $this->assertCount(1, $statements); - $this->assertSame('alter table "geo" add column "coordinates" geography(geometry, 4326) not null', $statements[0]); + $this->assertSame('alter table "geo" add column "coordinates" geometry not null', $statements[0]); + } + + public function testAddingGeography() + { + $blueprint = new Blueprint('geo'); + $blueprint->geography('coordinates', 'pointzm', 4269); + $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); + + $this->assertCount(1, $statements); + $this->assertSame('alter table "geo" add column "coordinates" geography(pointzm,4269) not null', $statements[0]); } public function testAddingPoint() { $blueprint = new Blueprint('geo'); - $blueprint->point('coordinates'); + $blueprint->geometry('coordinates', 'point'); + $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); + + $this->assertCount(1, $statements); + $this->assertSame('alter table "geo" add column "coordinates" geometry(point) not null', $statements[0]); + } + + public function testAddingPointWithSrid() + { + $blueprint = new Blueprint('geo'); + $blueprint->geometry('coordinates', 'point', 4269); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); $this->assertCount(1, $statements); - $this->assertSame('alter table "geo" add column "coordinates" geography(point, 4326) not null', $statements[0]); + $this->assertSame('alter table "geo" add column "coordinates" geometry(point,4269) not null', $statements[0]); } public function testAddingLineString() { $blueprint = new Blueprint('geo'); - $blueprint->linestring('coordinates'); + $blueprint->geometry('coordinates', 'linestring'); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); $this->assertCount(1, $statements); - $this->assertSame('alter table "geo" add column "coordinates" geography(linestring, 4326) not null', $statements[0]); + $this->assertSame('alter table "geo" add column "coordinates" geometry(linestring) not null', $statements[0]); } public function testAddingPolygon() { $blueprint = new Blueprint('geo'); - $blueprint->polygon('coordinates'); + $blueprint->geometry('coordinates', 'polygon'); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); $this->assertCount(1, $statements); - $this->assertSame('alter table "geo" add column "coordinates" geography(polygon, 4326) not null', $statements[0]); + $this->assertSame('alter table "geo" add column "coordinates" geometry(polygon) not null', $statements[0]); } public function testAddingGeometryCollection() { $blueprint = new Blueprint('geo'); - $blueprint->geometrycollection('coordinates'); + $blueprint->geometry('coordinates', 'geometrycollection'); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); $this->assertCount(1, $statements); - $this->assertSame('alter table "geo" add column "coordinates" geography(geometrycollection, 4326) not null', $statements[0]); + $this->assertSame('alter table "geo" add column "coordinates" geometry(geometrycollection) not null', $statements[0]); } public function testAddingMultiPoint() { $blueprint = new Blueprint('geo'); - $blueprint->multipoint('coordinates'); + $blueprint->geometry('coordinates', 'multipoint'); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); $this->assertCount(1, $statements); - $this->assertSame('alter table "geo" add column "coordinates" geography(multipoint, 4326) not null', $statements[0]); + $this->assertSame('alter table "geo" add column "coordinates" geometry(multipoint) not null', $statements[0]); } public function testAddingMultiLineString() { $blueprint = new Blueprint('geo'); - $blueprint->multilinestring('coordinates'); + $blueprint->geometry('coordinates', 'multilinestring'); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); $this->assertCount(1, $statements); - $this->assertSame('alter table "geo" add column "coordinates" geography(multilinestring, 4326) not null', $statements[0]); + $this->assertSame('alter table "geo" add column "coordinates" geometry(multilinestring) not null', $statements[0]); } public function testAddingMultiPolygon() { $blueprint = new Blueprint('geo'); - $blueprint->multipolygon('coordinates'); + $blueprint->geometry('coordinates', 'multipolygon'); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); $this->assertCount(1, $statements); - $this->assertSame('alter table "geo" add column "coordinates" geography(multipolygon, 4326) not null', $statements[0]); + $this->assertSame('alter table "geo" add column "coordinates" geometry(multipolygon) not null', $statements[0]); } public function testCreateDatabase() diff --git a/tests/Database/DatabaseSQLiteSchemaGrammarTest.php b/tests/Database/DatabaseSQLiteSchemaGrammarTest.php index b43c30a3d2bb..bc84c378381a 100755 --- a/tests/Database/DatabaseSQLiteSchemaGrammarTest.php +++ b/tests/Database/DatabaseSQLiteSchemaGrammarTest.php @@ -241,7 +241,7 @@ public function testAddingFluentSpatialIndex() $this->expectExceptionMessage('The database driver in use does not support spatial indexes.'); $blueprint = new Blueprint('geo'); - $blueprint->point('coordinates')->spatialIndex(); + $blueprint->geometry('coordinates')->spatialIndex(); $blueprint->toSql($this->getConnection(), $this->getGrammar()); } @@ -794,76 +794,6 @@ public function testAddingGeometry() $this->assertSame('alter table "geo" add column "coordinates" geometry not null', $statements[0]); } - public function testAddingPoint() - { - $blueprint = new Blueprint('geo'); - $blueprint->point('coordinates'); - $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); - - $this->assertCount(1, $statements); - $this->assertSame('alter table "geo" add column "coordinates" point not null', $statements[0]); - } - - public function testAddingLineString() - { - $blueprint = new Blueprint('geo'); - $blueprint->linestring('coordinates'); - $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); - - $this->assertCount(1, $statements); - $this->assertSame('alter table "geo" add column "coordinates" linestring not null', $statements[0]); - } - - public function testAddingPolygon() - { - $blueprint = new Blueprint('geo'); - $blueprint->polygon('coordinates'); - $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); - - $this->assertCount(1, $statements); - $this->assertSame('alter table "geo" add column "coordinates" polygon not null', $statements[0]); - } - - public function testAddingGeometryCollection() - { - $blueprint = new Blueprint('geo'); - $blueprint->geometrycollection('coordinates'); - $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); - - $this->assertCount(1, $statements); - $this->assertSame('alter table "geo" add column "coordinates" geometrycollection not null', $statements[0]); - } - - public function testAddingMultiPoint() - { - $blueprint = new Blueprint('geo'); - $blueprint->multipoint('coordinates'); - $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); - - $this->assertCount(1, $statements); - $this->assertSame('alter table "geo" add column "coordinates" multipoint not null', $statements[0]); - } - - public function testAddingMultiLineString() - { - $blueprint = new Blueprint('geo'); - $blueprint->multilinestring('coordinates'); - $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); - - $this->assertCount(1, $statements); - $this->assertSame('alter table "geo" add column "coordinates" multilinestring not null', $statements[0]); - } - - public function testAddingMultiPolygon() - { - $blueprint = new Blueprint('geo'); - $blueprint->multipolygon('coordinates'); - $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); - - $this->assertCount(1, $statements); - $this->assertSame('alter table "geo" add column "coordinates" multipolygon not null', $statements[0]); - } - public function testAddingGeneratedColumn() { $blueprint = new Blueprint('products'); diff --git a/tests/Database/DatabaseSqlServerSchemaGrammarTest.php b/tests/Database/DatabaseSqlServerSchemaGrammarTest.php index 72e0bc314508..22a6eafa03c8 100755 --- a/tests/Database/DatabaseSqlServerSchemaGrammarTest.php +++ b/tests/Database/DatabaseSqlServerSchemaGrammarTest.php @@ -282,7 +282,7 @@ public function testAddingSpatialIndex() public function testAddingFluentSpatialIndex() { $blueprint = new Blueprint('geo'); - $blueprint->point('coordinates')->spatialIndex(); + $blueprint->geometry('coordinates', 'point')->spatialIndex(); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); $this->assertCount(2, $statements); @@ -830,73 +830,13 @@ public function testAddingGeometry() $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); $this->assertCount(1, $statements); - $this->assertSame('alter table "geo" add "coordinates" geography not null', $statements[0]); - } - - public function testAddingPoint() - { - $blueprint = new Blueprint('geo'); - $blueprint->point('coordinates'); - $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); - - $this->assertCount(1, $statements); - $this->assertSame('alter table "geo" add "coordinates" geography not null', $statements[0]); - } - - public function testAddingLineString() - { - $blueprint = new Blueprint('geo'); - $blueprint->linestring('coordinates'); - $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); - - $this->assertCount(1, $statements); - $this->assertSame('alter table "geo" add "coordinates" geography not null', $statements[0]); - } - - public function testAddingPolygon() - { - $blueprint = new Blueprint('geo'); - $blueprint->polygon('coordinates'); - $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); - - $this->assertCount(1, $statements); - $this->assertSame('alter table "geo" add "coordinates" geography not null', $statements[0]); - } - - public function testAddingGeometryCollection() - { - $blueprint = new Blueprint('geo'); - $blueprint->geometrycollection('coordinates'); - $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); - - $this->assertCount(1, $statements); - $this->assertSame('alter table "geo" add "coordinates" geography not null', $statements[0]); - } - - public function testAddingMultiPoint() - { - $blueprint = new Blueprint('geo'); - $blueprint->multipoint('coordinates'); - $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); - - $this->assertCount(1, $statements); - $this->assertSame('alter table "geo" add "coordinates" geography not null', $statements[0]); - } - - public function testAddingMultiLineString() - { - $blueprint = new Blueprint('geo'); - $blueprint->multilinestring('coordinates'); - $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); - - $this->assertCount(1, $statements); - $this->assertSame('alter table "geo" add "coordinates" geography not null', $statements[0]); + $this->assertSame('alter table "geo" add "coordinates" geometry not null', $statements[0]); } - public function testAddingMultiPolygon() + public function testAddingGeography() { $blueprint = new Blueprint('geo'); - $blueprint->multipolygon('coordinates'); + $blueprint->geography('coordinates'); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); $this->assertCount(1, $statements); diff --git a/tests/Integration/Database/DatabaseSchemaBlueprintTest.php b/tests/Integration/Database/DatabaseSchemaBlueprintTest.php index cc5355063e31..a03218e79673 100644 --- a/tests/Integration/Database/DatabaseSchemaBlueprintTest.php +++ b/tests/Integration/Database/DatabaseSchemaBlueprintTest.php @@ -91,7 +91,7 @@ public function testNativeColumnModifyingOnMySql() $table->double('amount')->nullable()->invisible()->after('name')->change(); $table->timestamp('added_at', 4)->nullable(false)->useCurrent()->useCurrentOnUpdate()->change(); $table->enum('difficulty', ['easy', 'hard'])->default('easy')->charset('utf8mb4')->collation('unicode')->change(); - $table->multiPolygon('positions')->srid(1234)->storedAs('expression')->change(); + $table->geometry('positions', 'multipolygon', 1234)->storedAs('expression')->change(); $table->string('old_name', 50)->renameTo('new_name')->change(); $table->bigIncrements('id')->first()->from(10)->comment('my comment')->change(); }); @@ -101,7 +101,7 @@ public function testNativeColumnModifyingOnMySql() .'modify `amount` double null invisible after `name`, ' .'modify `added_at` timestamp(4) not null default CURRENT_TIMESTAMP(4) on update CURRENT_TIMESTAMP(4), ' ."modify `difficulty` enum('easy', 'hard') character set utf8mb4 collate 'unicode' not null default 'easy', " - .'modify `positions` multipolygon as (expression) stored srid 1234, ' + .'modify `positions` multipolygon srid 1234 as (expression) stored, ' .'change `old_name` `new_name` varchar(50) not null, ' ."modify `id` bigint unsigned not null auto_increment primary key comment 'my comment' first", 'alter table `users` auto_increment = 10', @@ -155,12 +155,12 @@ public function testNativeColumnModifyingOnPostgreSql() ], $blueprint->toSql($connection, new PostgresGrammar)); $blueprint = new Blueprint('users', function ($table) { - $table->point('foo')->isGeometry()->projection(1234)->change(); + $table->geometry('foo', 'point', 1234)->change(); }); $this->assertEquals([ 'alter table "users" ' - .'alter column "foo" type geometry(point, 1234), ' + .'alter column "foo" type geometry(point,1234), ' .'alter column "foo" set not null, ' .'alter column "foo" drop default, ' .'alter column "foo" drop identity if exists',