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

[11.x] Make spatial types consistent #49634

Merged
merged 1 commit into from
Jan 18, 2024

Conversation

hafezdivandari
Copy link
Contributor

@hafezdivandari hafezdivandari commented Jan 10, 2024

Spatial Data types was added on Laravel 5.5 via #21056 and had minor chnages on 5.7 and 6.0 (#25323 and #30545). During these years, MySQL, PostgreSQL (via PostGIS), SQLServer and SQLite (via SpatiaLite) databases have better and more stable support for spatial types. This PR make the support for these types consistent across all supported databases, you may also consider this as a behavioral fix in some way!

Notes

Why?

  • The usage of these types are currently inconsistent across DBs and the result is hard to predict.
  • The geometry defaults to geography which is confusing.
  • PostgreSQL has native geometrics types (point, line, lseg, box, path, polygon, and circle), that has conflict with implemented PostGIS types (the point and polygon types). This PR fixes this.
  • Using PostGIS, there are almost 48 subtypes available for geometry and 21 subtypes for geography that was impossible to be used on Laravel. The new implementation on this PR fixes this.
  • All spatial types on SQL Server was mapped to geography although SQL Server has geometry type too. This PR fixes that.

Changes

  • Changes geometry type to accept subtype (default null) and srid (default 0) :
    $table->geometry('column_name', subtype: 'point', srid: 0);`
    • MySQL subtypes: null (i.e. geometry), point, lineString, polygon, geometryCollection, multiPoint, multiLineString, multiPolygon
    • PostGis subtypes: null, point, lineString, polygon, geometryCollection, multiPoint, multiLineString, multiPolygon, linearRing, polyhedralSurface, triangle, tin, circularString, compoundCurve, curvePolygon, multiCurve, multiSurface with added suffixes Z, M and ZM.
  • Adds geography type that accepts subtype (default null) and srid (default 4326):
    $table->geography('column_name', subtype: 'point', srid: 4326);`
    • MySQL subtypes: null (i.e. geometry), point, lineString, polygon, geometryCollection, multiPoint, multiLineString, multiPolygon
    • PostGIS subtypes: null, point, lineString, polygon, geometryCollection, multiPoint, multiLineString, multiPolygon with added suffixes Z, M and ZM.
  • Removes point, lineString, polygon, geometryCollection, multiPoint, multiLineString, multiPolygon, and multiPolygonZ explicit types.
  • Removes ->isGeometry() and ->projection() modifiers from PostgreSQL.

Upgrade guide

Likelihood Of Impact: Low

The geometry and geography column types of database migrations have been rewritten to make these types consistent across all databases, Therefore, you may remove point, lineString, polygon, geometryCollection, multiPoint, multiLineString, multiPolygon, and multiPolygonZ types from your migrations and use geometry / geography types instead:

- $table->point('geo');
// `geography(POINT,4326)` on PostgreSQL, `POINT` on MySQL and `geography` on SQL Server
+ $table->geography('geo', 'point');
// `geography(POINT,4326)` on PostgreSQL, `POINT SRID 4326` on MySQL and `geography` on SQL Server
+ $table->geometry('geo', 'point');
// `geometry(POINT)` on PostgreSQL, `POINT` on MySQL and `geometry` on SQL Server

@hafezdivandari hafezdivandari marked this pull request as ready for review January 10, 2024 14:02
@taylorotwell taylorotwell merged commit 8317461 into laravel:master Jan 18, 2024
21 checks passed
@taylorotwell
Copy link
Member

@hafezdivandari could you send a PR to migration docs and upgrade docs master branch to document this?

@hafezdivandari hafezdivandari deleted the master-fix-geometrics branch January 18, 2024 17:29
@hafezdivandari
Copy link
Contributor Author

@taylorotwell sure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants