Skip to content

Conversation

@abnegate
Copy link
Member

@abnegate abnegate commented Sep 12, 2025

Summary by CodeRabbit

  • New Features
    • Added adapter capability to handle spatial axis order; enabled on MySQL.
    • Standardized spatial column definitions and geometry construction across databases for more consistent queries.
  • Bug Fixes
    • Improved spatial validation with stricter coordinate checks and clearer error messages (including point/ring indices).
    • More reliable distance calculations by using a consistent earth radius.
  • Refactor
    • Centralized spatial helpers for geometry creation and type rendering to ensure consistent behavior across adapters.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 12, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Introduces axis-order capability queries and centralized spatial geometry construction across adapters. Adds Database::EARTH_RADIUS. Refactors spatial SQL generation (distance, predicates, projections, and type definitions) to use getSpatialGeomFromText and new getSpatialSQLType. Enhances Spatial validator with coordinate-range checks and expands tests, including invalid coordinates and polygon nesting.

Changes

Cohort / File(s) Summary
Adapter capability surface
src/Database/Adapter.php, src/Database/Adapter/Pool.php
Adds abstract and delegated method getSupportForSpatialAxisOrder(): bool to query axis-order support.
Core SQL helper and axis-order handling
src/Database/Adapter/SQL.php
Introduces getSpatialGeomFromText(...) and getSpatialAxisOrderSpec(); switches create/update/projection to use helper; adds getSupportForSpatialAxisOrder() (default false) and axis-order-aware ST_AsText.
MySQL adapter spatial refactor
src/Database/Adapter/MySQL.php
Uses getSpatialGeomFromText in distance logic; normalizes non-meter distances via SRID 0; adds getSpatialSQLType(...) and getSupportForSpatialAxisOrder()=true; introduces protected getSpatialAxisOrderSpec().
MariaDB adapter spatial refactor
src/Database/Adapter/MariaDB.php
Replaces inline ST_GeomFromText with getSpatialGeomFromText across CRUD and predicates; adds getSpatialSQLType(...); adds getSupportForSpatialAxisOrder()=false; removes explicit axis-order usage in queries; uses Database::EARTH_RADIUS.
Postgres adapter spatial refactor
src/Database/Adapter/Postgres.php
Centralizes geometry construction via getSpatialGeomFromText for distance/predicates; meters path casts to geography; adds getSupportForSpatialAxisOrder()=false.
SQLite adapter capability
src/Database/Adapter/SQLite.php
Adds getSupportForSpatialAxisOrder()=false.
Database constants
src/Database/Database.php
Adds public constant EARTH_RADIUS=6371000.
Spatial validator enhancements
src/Database/Validator/Spatial.php
Adds isValidCoordinate and integrates into POINT/LINESTRING/POLYGON validation; improves error messages with indices; retains public API.
E2E spatial tests update
tests/e2e/Adapter/Scopes/SpatialTests.php
Switches polygon test data to multi-ring nesting; adds tests for attribute order and invalid coordinates; adjusts queries/expectations; ensures cleanup.
Unit tests for validator
tests/unit/Validator/SpatialTest.php
Adds testInvalidCoordinate covering out-of-range longitude/latitude and line/polygon coordinate errors.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Client
  participant Adapter as SQL Adapter
  participant Impl as Concrete Adapter (MySQL/MariaDB/Postgres/SQLite)
  participant DB as Database

  Client->>Adapter: Create/Query with spatial attributes (WKT)
  Adapter->>Impl: getSupportForSpatialAxisOrder()
  Impl-->>Adapter: true/false
  note over Adapter: Build SQL using getSpatialGeomFromText(<wkt>, <srid>)<br/>Append axis-order spec only if supported

  alt Distance in meters
    Adapter->>DB: ST_Distance(..., getSpatialGeomFromText(...), 'metre') / geography cast
  else Distance non-meters
    Adapter->>DB: ST_Distance(..., getSpatialGeomFromText(...))
  end

  Adapter-->>Client: Results (spatial projections via ST_AsText[+axis-order?])
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Suggested reviewers

Poem

A rabbit hopped through WKT fields so wide,
Stirred axis orders, set SRIDs with pride.
With gentle paws, it typed away—
Distances measured, in metres today.
Polygons nested, tests all green,
EARTH_RADIUS steady, spatial serene. 🐇🌍

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 44af82d and dbecdf8.

📒 Files selected for processing (11)
  • src/Database/Adapter.php (1 hunks)
  • src/Database/Adapter/MariaDB.php (7 hunks)
  • src/Database/Adapter/MySQL.php (2 hunks)
  • src/Database/Adapter/Pool.php (1 hunks)
  • src/Database/Adapter/Postgres.php (5 hunks)
  • src/Database/Adapter/SQL.php (6 hunks)
  • src/Database/Adapter/SQLite.php (1 hunks)
  • src/Database/Database.php (1 hunks)
  • src/Database/Validator/Spatial.php (6 hunks)
  • tests/e2e/Adapter/Scopes/SpatialTests.php (6 hunks)
  • tests/unit/Validator/SpatialTest.php (1 hunks)
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch 1.x

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@abnegate abnegate marked this pull request as ready for review September 12, 2025 12:29
@abnegate abnegate merged commit e68f2e3 into main Sep 12, 2025
14 of 15 checks passed
@abnegate abnegate deleted the 1.x branch September 12, 2025 12:29
@abnegate abnegate restored the 1.x branch September 12, 2025 12:29
This was referenced Sep 29, 2025
@coderabbitai coderabbitai bot mentioned this pull request Oct 7, 2025
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.

3 participants