Skip to content

Commit f5947e2

Browse files
[11.x] Make spatial types consistent (#9266)
* fix spatial types * add upgrade guid * formatting * formatting * formatting * formatting --------- Co-authored-by: Taylor Otwell <taylor@laravel.com>
1 parent 944c218 commit f5947e2

File tree

2 files changed

+39
-57
lines changed

2 files changed

+39
-57
lines changed

migrations.md

Lines changed: 14 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -410,30 +410,24 @@ The schema builder blueprint offers a variety of methods that correspond to the
410410
[foreignIdFor](#column-method-foreignIdFor)
411411
[foreignUlid](#column-method-foreignUlid)
412412
[foreignUuid](#column-method-foreignUuid)
413-
[geometryCollection](#column-method-geometryCollection)
413+
[geography](#column-method-geography)
414414
[geometry](#column-method-geometry)
415415
[id](#column-method-id)
416416
[increments](#column-method-increments)
417417
[integer](#column-method-integer)
418418
[ipAddress](#column-method-ipAddress)
419419
[json](#column-method-json)
420420
[jsonb](#column-method-jsonb)
421-
[lineString](#column-method-lineString)
422421
[longText](#column-method-longText)
423422
[macAddress](#column-method-macAddress)
424423
[mediumIncrements](#column-method-mediumIncrements)
425424
[mediumInteger](#column-method-mediumInteger)
426425
[mediumText](#column-method-mediumText)
427426
[morphs](#column-method-morphs)
428-
[multiLineString](#column-method-multiLineString)
429-
[multiPoint](#column-method-multiPoint)
430-
[multiPolygon](#column-method-multiPolygon)
431427
[nullableMorphs](#column-method-nullableMorphs)
432428
[nullableTimestamps](#column-method-nullableTimestamps)
433429
[nullableUlidMorphs](#column-method-nullableUlidMorphs)
434430
[nullableUuidMorphs](#column-method-nullableUuidMorphs)
435-
[point](#column-method-point)
436-
[polygon](#column-method-polygon)
437431
[rememberToken](#column-method-rememberToken)
438432
[set](#column-method-set)
439433
[smallIncrements](#column-method-smallIncrements)
@@ -546,7 +540,7 @@ The `enum` method creates a `ENUM` equivalent column with the given valid values
546540

547541
The `float` method creates a `FLOAT` equivalent column with the given precision:
548542

549-
$table->float('amount', 53);
543+
$table->float('amount', $precision = 53);
550544

551545
<a name="column-method-foreignId"></a>
552546
#### `foreignId()` {.collection-method}
@@ -576,19 +570,25 @@ The `foreignUuid` method creates a `UUID` equivalent column:
576570

577571
$table->foreignUuid('user_id');
578572

579-
<a name="column-method-geometryCollection"></a>
580-
#### `geometryCollection()` {.collection-method}
573+
<a name="column-method-geography"></a>
574+
#### `geography()` {.collection-method}
581575

582-
The `geometryCollection` method creates a `GEOMETRYCOLLECTION` equivalent column:
576+
The `geography` method creates a `GEOGRAPHY` equivalent column with the given spatial type and SRID (Spatial Reference System Identifier):
583577

584-
$table->geometryCollection('positions');
578+
$table->geography('coordinates', subtype: 'point', srid: 4326);
579+
580+
> [!NOTE]
581+
> Support for spatial types depends on your database driver. Please refer to your database's documentation. If your application is utilizing a PostgreSQL database, you must install the [PostGIS](https://postgis.net) extension before the `geography` method may be used.
585582
586583
<a name="column-method-geometry"></a>
587584
#### `geometry()` {.collection-method}
588585

589-
The `geometry` method creates a `GEOMETRY` equivalent column:
586+
The `geometry` method creates a `GEOMETRY` equivalent column with the given spatial type and SRID (Spatial Reference System Identifier):
587+
588+
$table->geometry('positions', subtype: 'point', srid: 0);
590589

591-
$table->geometry('positions');
590+
> [!NOTE]
591+
> Support for spatial types depends on your database driver. Please refer to your database's documentation. If your application is utilizing a PostgreSQL database, you must install the [PostGIS](https://postgis.net) extension before the `geometry` method may be used.
592592
593593
<a name="column-method-id"></a>
594594
#### `id()` {.collection-method}
@@ -634,13 +634,6 @@ The `jsonb` method creates a `JSONB` equivalent column:
634634

635635
$table->jsonb('options');
636636

637-
<a name="column-method-lineString"></a>
638-
#### `lineString()` {.collection-method}
639-
640-
The `lineString` method creates a `LINESTRING` equivalent column:
641-
642-
$table->lineString('positions');
643-
644637
<a name="column-method-longText"></a>
645638
#### `longText()` {.collection-method}
646639

@@ -685,27 +678,6 @@ This method is intended to be used when defining the columns necessary for a pol
685678

686679
$table->morphs('taggable');
687680

688-
<a name="column-method-multiLineString"></a>
689-
#### `multiLineString()` {.collection-method}
690-
691-
The `multiLineString` method creates a `MULTILINESTRING` equivalent column:
692-
693-
$table->multiLineString('positions');
694-
695-
<a name="column-method-multiPoint"></a>
696-
#### `multiPoint()` {.collection-method}
697-
698-
The `multiPoint` method creates a `MULTIPOINT` equivalent column:
699-
700-
$table->multiPoint('positions');
701-
702-
<a name="column-method-multiPolygon"></a>
703-
#### `multiPolygon()` {.collection-method}
704-
705-
The `multiPolygon` method creates a `MULTIPOLYGON` equivalent column:
706-
707-
$table->multiPolygon('positions');
708-
709681
<a name="column-method-nullableTimestamps"></a>
710682
#### `nullableTimestamps()` {.collection-method}
711683

@@ -734,20 +706,6 @@ The method is similar to the [uuidMorphs](#column-method-uuidMorphs) method; how
734706

735707
$table->nullableUuidMorphs('taggable');
736708

737-
<a name="column-method-point"></a>
738-
#### `point()` {.collection-method}
739-
740-
The `point` method creates a `POINT` equivalent column:
741-
742-
$table->point('position');
743-
744-
<a name="column-method-polygon"></a>
745-
#### `polygon()` {.collection-method}
746-
747-
The `polygon` method creates a `POLYGON` equivalent column:
748-
749-
$table->polygon('position');
750-
751709
<a name="column-method-rememberToken"></a>
752710
#### `rememberToken()` {.collection-method}
753711

@@ -974,7 +932,6 @@ Modifier | Description
974932
`->virtualAs($expression)` | Create a virtual generated column (MySQL / PostgreSQL / SQLite).
975933
`->generatedAs($expression)` | Create an identity column with specified sequence options (PostgreSQL).
976934
`->always()` | Defines the precedence of sequence values over input for an identity column (PostgreSQL).
977-
`->isGeometry()` | Set spatial column type to `geometry` - the default type is `geography` (PostgreSQL).
978935

979936
<a name="default-expressions"></a>
980937
#### Default Expressions

upgrade.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<div class="content-list" markdown="1">
1919

2020
- [The `Enumerable` Contract](#the-enumerable-contract)
21+
- [Spatial Types](#spatial-types)
2122

2223
</div>
2324

@@ -62,3 +63,27 @@ The `dump` method of the `Illuminate\Support\Enumerable` contract has been updat
6263
```php
6364
public function dump(...$args);
6465
```
66+
67+
<a name="database"></a>
68+
### Database
69+
70+
<a name="spatial-types"></a>
71+
#### Spatial Types
72+
73+
**Likelihood Of Impact: Low**
74+
75+
The spatial column types of database migrations have been rewritten to be consistent across all databases. Therefore, you may remove `point`, `lineString`, `polygon`, `geometryCollection`, `multiPoint`, `multiLineString`, `multiPolygon`, and `multiPolygonZ` methods from your migrations and use `geometry` or `geography` methods instead:
76+
77+
```php
78+
$table->geometry('shapes');
79+
$table->geography('coordinates');
80+
```
81+
82+
To explicitly restrict the type or the spatial reference system identifier for values stored in the column on MySQL and PostgreSQL, you may pass the `subtype` and `srid` to the method:
83+
84+
```php
85+
$table->geometry('dimension', subtype: 'polygon', srid: 0);
86+
$table->geography('latitude', subtype: 'point', srid: 4326);
87+
```
88+
89+
The `isGeometry` and `projection` column modifiers of the PostgreSQL grammar have been removed accordingly.

0 commit comments

Comments
 (0)