Skip to content

Commit d97caae

Browse files
feat(martin-georgiev#305): add support for PostGIS's types of GEOGRAPHY, GEOMETRY and their array variations (martin-georgiev#421)
1 parent 41f6727 commit d97caae

40 files changed

+3340
-27
lines changed

.github/workflows/integration-tests.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,23 @@ jobs:
3434
needs: should-run
3535
if: needs.should-run.outputs.run == 'true'
3636
runs-on: ubuntu-latest
37-
name: "PostgreSQL ${{ matrix.postgres }} + PHP ${{ matrix.php }}"
37+
name: "PostgreSQL ${{ matrix.postgres }} + PostGIS ${{ matrix.postgis }} + PHP ${{ matrix.php }}"
3838

3939
strategy:
4040
fail-fast: false
4141
matrix:
4242
php: ['8.1', '8.2', '8.3', '8.4']
43+
postgis: ['3.4', '3.5']
4344
postgres: ['16', '17']
4445
include:
4546
- php: '8.4'
47+
postgis: '3.5'
4648
postgres: '17'
4749
calculate-code-coverage: true
4850

4951
services:
5052
postgres:
51-
image: postgres:${{ matrix.postgres }}
53+
image: postgis/postgis:${{ matrix.postgres }}-${{ matrix.postgis }}
5254
env:
5355
POSTGRES_PASSWORD: postgres
5456
POSTGRES_USER: postgres
@@ -110,6 +112,9 @@ jobs:
110112
echo "\nListing available PostgreSQL extensions:"
111113
PGPASSWORD=postgres psql -h localhost -U postgres -d postgres_doctrine_test -c "SELECT * FROM pg_available_extensions;"
112114
115+
echo "\nVerifying PostGIS installation:"
116+
PGPASSWORD=postgres psql -h localhost -U postgres -d postgres_doctrine_test -c "SELECT PostGIS_Version();"
117+
113118
- name: Run integration test suite
114119
run: composer run-integration-tests
115120
env:

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ This package provides comprehensive Doctrine support for PostgreSQL features:
5555
- MAC addresses (`macaddr`, `macaddr[]`)
5656
- **Geometric Types**
5757
- Point (`point`, `point[]`)
58+
- PostGIS Geometry (`geometry`, `geometry[]`)
59+
- PostGIS Geography (`geography`, `geography[]`)
5860
- **Range Types**
5961
- Date and time ranges (`daterange`, `tsrange`, `tstzrange`)
6062
- Numeric ranges (`numrange`, `int4range`, `int8range`)
@@ -98,6 +100,8 @@ Full documentation:
98100
- [Value Objects for Range Types](docs/RANGE-TYPES.md)
99101
- [Available Functions and Operators](docs/AVAILABLE-FUNCTIONS-AND-OPERATORS.md)
100102
- [Common Use Cases and Examples](docs/USE-CASES-AND-EXAMPLES.md)
103+
- [Spatial Types](docs/SPATIAL-TYPES.md)
104+
- [Geometry Arrays](docs/GEOMETRY-ARRAYS.md)
101105

102106
## 📦 Installation
103107

@@ -122,10 +126,10 @@ composer run-unit-tests
122126
```
123127

124128
### PostgreSQL Integration Tests
125-
We also provide integration tests that run against a real PostgreSQL database to ensure compatibility:
129+
We also provide integration tests that run against a real PostgreSQL database with PostGIS to ensure compatibility:
126130

127131
```bash
128-
# Start PostgreSQL using Docker Compose
132+
# Start PostgreSQL with PostGIS using Docker Compose
129133
docker-compose up -d
130134

131135
# Run integration tests
@@ -135,7 +139,7 @@ composer run-integration-tests
135139
docker-compose down -v
136140
```
137141

138-
See [tests-integration/README.md](tests-integration/README.md) for more details.
142+
See [tests/Integration/README.md](tests/Integration/README.md) for more details.
139143

140144
## ⭐ Support the Project
141145

ci/php-cs-fixer/config.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
'php_unit_internal_class' => false,
4444
'php_unit_method_casing' => ['case' => 'snake_case'],
4545
'php_unit_test_class_requires_covers' => false,
46+
'phpdoc_align' => ['align' => 'left'],
4647
'phpdoc_types_order' => ['null_adjustment' => 'always_last'],
4748
'simplified_null_return' => false,
4849
'single_line_comment_style' => false,

devenv.nix

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,37 @@ in
6060
services.postgres = {
6161
enable = true;
6262

63+
# Use PostgreSQL 17 to match Docker Compose and CI
64+
package = pkgs.postgresql_17;
65+
6366
listen_addresses = "127.0.0.1";
6467
port = config.env.POSTGRES_PORT;
6568

6669
initialDatabases = [ { name = config.env.POSTGRES_DB; } ];
6770

71+
# Enable PostGIS extension
72+
extensions = extensions: [
73+
extensions.postgis
74+
];
75+
6876
initialScript = ''
69-
CREATE ROLE "${config.env.POSTGRES_USER}"
70-
WITH SUPERUSER LOGIN PASSWORD '${config.env.POSTGRES_PASSWORD}';
77+
-- Create role if it doesn't exist, or update password if it does
78+
DO $$
79+
BEGIN
80+
IF NOT EXISTS (SELECT FROM pg_catalog.pg_roles WHERE rolname = '${config.env.POSTGRES_USER}') THEN
81+
CREATE ROLE "${config.env.POSTGRES_USER}" WITH SUPERUSER LOGIN PASSWORD '${config.env.POSTGRES_PASSWORD}';
82+
ELSE
83+
ALTER ROLE "${config.env.POSTGRES_USER}" WITH SUPERUSER LOGIN PASSWORD '${config.env.POSTGRES_PASSWORD}';
84+
END IF;
85+
END
86+
$$;
87+
88+
-- Set database owner
89+
ALTER DATABASE "${config.env.POSTGRES_DB}" OWNER TO "${config.env.POSTGRES_USER}";
90+
91+
-- Enable PostGIS extension in the database
92+
\c ${config.env.POSTGRES_DB}
93+
CREATE EXTENSION IF NOT EXISTS postgis;
7194
'';
7295
};
7396

docker-compose.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
services:
22
postgres:
3-
image: postgres:${POSTGRES_VERSION:-17}
3+
image: postgis/postgis:${POSTGRES_VERSION:-17}-3.4
44
environment:
55
POSTGRES_USER: ${POSTGRES_USER:-postgres}
66
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-postgres}
77
POSTGRES_DB: ${POSTGRES_DB:-postgres_doctrine_test}
8+
TZ: UTC
89
ports:
910
- "${POSTGRES_PORT:-5432}:5432"
1011
volumes:

docs/AVAILABLE-TYPES.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,28 @@
88
| bigint[] | _int8 | `MartinGeorgiev\Doctrine\DBAL\Types\BigIntArray` |
99
| real[] | _float4 | `MartinGeorgiev\Doctrine\DBAL\Types\RealArray` |
1010
| double precision[] | _float8 | `MartinGeorgiev\Doctrine\DBAL\Types\DoublePrecisionArray` |
11-
| text[] | _text | `MartinGeorgiev\Doctrine\DBAL\Types\TextArray` |
12-
| jsonb[] | _jsonb | `MartinGeorgiev\Doctrine\DBAL\Types\JsonbArray` |
11+
|---|---|---|
1312
| jsonb | jsonb | `MartinGeorgiev\Doctrine\DBAL\Types\Jsonb` |
14-
| inet | inet | `MartinGeorgiev\Doctrine\DBAL\Types\Inet` |
15-
| inet[] | _inet | `MartinGeorgiev\Doctrine\DBAL\Types\InetArray` |
13+
| jsonb[] | _jsonb | `MartinGeorgiev\Doctrine\DBAL\Types\JsonbArray` |
14+
| text[] | _text | `MartinGeorgiev\Doctrine\DBAL\Types\TextArray` |
15+
|---|---|---|
1616
| cidr | cidr | `MartinGeorgiev\Doctrine\DBAL\Types\Cidr` |
1717
| cidr[] | _cidr | `MartinGeorgiev\Doctrine\DBAL\Types\CidrArray` |
18+
| inet | inet | `MartinGeorgiev\Doctrine\DBAL\Types\Inet` |
19+
| inet[] | _inet | `MartinGeorgiev\Doctrine\DBAL\Types\InetArray` |
1820
| macaddr | macaddr | `MartinGeorgiev\Doctrine\DBAL\Types\Macaddr` |
1921
| macaddr[] | _macaddr | `MartinGeorgiev\Doctrine\DBAL\Types\MacaddrArray` |
20-
| point | point | `MartinGeorgiev\Doctrine\DBAL\Types\Point` |
21-
| point[] | _point | `MartinGeorgiev\Doctrine\DBAL\Types\PointArray` |
22+
|---|---|---|
2223
| daterange | daterange | `MartinGeorgiev\Doctrine\DBAL\Types\DateRange` |
2324
| int4range | int4range | `MartinGeorgiev\Doctrine\DBAL\Types\Int4Range` |
2425
| int8range | int8range | `MartinGeorgiev\Doctrine\DBAL\Types\Int8Range` |
2526
| numrange | numrange | `MartinGeorgiev\Doctrine\DBAL\Types\NumRange` |
2627
| tsrange | tsrange | `MartinGeorgiev\Doctrine\DBAL\Types\TsRange` |
2728
| tstzrange | tstzrange | `MartinGeorgiev\Doctrine\DBAL\Types\TstzRange` |
29+
|---|---|---|
30+
| geography | geography | `MartinGeorgiev\Doctrine\DBAL\Types\Geography` |
31+
| geography[] | _geography | `MartinGeorgiev\Doctrine\DBAL\Types\GeographyArray` |
32+
| geometry | geometry | `MartinGeorgiev\Doctrine\DBAL\Types\Geometry` |
33+
| geometry[] | _geometry | `MartinGeorgiev\Doctrine\DBAL\Types\GeometryArray` |
34+
| point | point | `MartinGeorgiev\Doctrine\DBAL\Types\Point` |
35+
| point[] | _point | `MartinGeorgiev\Doctrine\DBAL\Types\PointArray` |

docs/CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ The provided environment includes:
117117
118118
- PHP 8.1, which is the oldest PHP version supported by this project.
119119
- Composer
120-
- PostgreSQL 17, started by `devenv up`.
120+
- PostgreSQL 17 with PostGIS 3.4, started by `devenv up`.
121121
- Pre-commit hooks (PHP-CS-Fixer, PHPStan, Rector, deptrac, ...).
122122
123123
### Local development

0 commit comments

Comments
 (0)