postgis.Geometry can't declare a subtype like geometry(Polygon, 4326)

Open
#30,772 2 comments 1 reaction 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
postgresql, typescript
Domain
backend, databases

Research direction

Start by tracing postgis.Geometry through contract inference, schema verification, and the DDL planner; the issue does not name implementation files or tests. Reproduce with a PostGIS column declared as geometry(Polygon, 4326) and follow the reported prisma contract infer → prisma db sign flow. Done when subtype declarations are inferred and accepted by verification and the planner renders the matching DDL.

Written by the indexing model from the issue text.

Description

bug/1-unconfirmed kind/bug
Package and version

[email protected]

What happened?

Package and version

@prisma/[email protected], @prisma/[email protected], [email protected]

Problem

postgis.Geometry(srid?) can only describe geometry or geometry(Geometry, <srid>). There is no way to declare a geometry subtype (Polygon, Point, LineString, MultiPolygon, ...), which is the common way PostGIS columns are typed.

As a result, an existing database with a typed geometry column can't be adopted:

  • prisma contract infer produces postgis.Geometry(...) for the column, losing the subtype.
  • prisma db sign then fails schema verification on that column, so the app space can't be signed and migrations can't be chained from it:
✘ app: not signed, the schema does not satisfy its contract
└─ ✘ mismatch: database/public/table_a/column:shape
✘ [CONTRACT.SCHEMA_VERIFICATION_FAILED] Database schema does not satisfy contract (1 failure)

Live column vs. contract:

Live database Contract
table_a.shape geometry(Polygon) postgis.Geometry() → geometry
table_b.shape geometry(Polygon, 4326) postgis.Geometry(4326) → geometry(Geometry, 4326)
What did you expect to happen?

Accept an optional geometry subtype, mirroring PostGIS's geometry(<subtype>, <srid>) modifier:

types {
  AreaPolygon  = postgis.Geometry("Polygon", 4326)   // geometry(Polygon, 4326)
  PlainPolygon = postgis.Geometry("Polygon")         // geometry(Polygon)
  Position     = postgis.Geometry("Point", 4326)     // geometry(Point, 4326)
}

with contract infer emitting the subtype from the live column, db verify / db sign comparing it, and the planner rendering it in DDL. Ideally the TypeScript result type narrows by subtype too (e.g. a Polygon GeoJSON type rather than any Geometry), but the DDL/verification part alone would unblock adoption.

Minimal reproduction
  1. In a Postgres database with PostGIS: CREATE TABLE areas (id serial PRIMARY KEY, shape geometry(Polygon, 4326));
  2. prisma contract infer, then prisma contract emit with extensions: [postgis] in prisma.config.ts.
  3. prisma db sign → CONTRACT.SCHEMA_VERIFICATION_FAILED on areas.shape.
types {
  AreaPolygon = postgis.Geometry(4326)
}

model Area {
  id    Int          @id @default(autoincrement())
  shape AreaPolygon?

  @@map("areas")
}
Environment
  • Node: v22.23.2
  • OS: Linux 6.18
  • Package manager: npm 10.9.8
  • Database: PostgreSQL with PostGIS
Additional context

No response

Dominant language
TypeScript
Stars
47.8k
Forks
2.6k
Avg merge
1d 21h
Merged PRs (30d)
227

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from prisma/orm

All issues in prisma/orm

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.