Replies: 5 comments 2 replies
|
Hello, Can you share the generator block of your schema.prisma file? It should look something like this: generator client {
provider = "prisma-client"
output = "./generated"
previewFeatures = ["postgresqlExtensions"]
}
datasource db {
provider = "postgresql"
extensions = [postgis]
} |
|
The schema line itself is valid on current Prisma versions — the docs now show
So my guess is less "the type is unsupported" and more "the schema is being parsed by an older engine". As a temporary fallback, |
|
To clarify the confusion first: when Prisma's documentation says PostGIS is "natively supported", it refers to the extension being recognized and manageable via the The correct schema setup generator client {
provider = "prisma-client-js"
previewFeatures = ["postgresqlExtensions"]
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
extensions = [postgis]
}
model Recipient {
id String @id @default(uuid())
lastName String @db.VarChar(100)
firstName String @db.VarChar(100)
email String @db.VarChar(255)
phoneNumber String @unique @db.VarChar(20)
streetAddress String @db.VarChar(255)
city String @db.VarChar(100)
stateRegion String? @db.VarChar(100)
postalCode String @db.VarChar(20)
country String @default("France") @db.VarChar(100)
position Unsupported("geometry(Point, 4326)")?
@@index([position], name: "recipient_position_idx", type: Gist)
}Remove the Inserting and querying the position field Because import { Prisma } from '@prisma/client'
// Insert with a point
await prisma.$executeRaw`
UPDATE "Recipient"
SET position = ST_SetSRID(ST_MakePoint(${longitude}, ${latitude}), 4326)
WHERE id = ${id}
`
// Query by proximity (within 5km)
const nearby = await prisma.$queryRaw<Recipient[]>`
SELECT *,
ST_Distance(
position::geography,
ST_SetSRID(ST_MakePoint(${longitude}, ${latitude}), 4326)::geography
) AS distance
FROM "Recipient"
WHERE ST_DWithin(
position::geography,
ST_SetSRID(ST_MakePoint(${longitude}, ${latitude}), 4326)::geography,
5000
)
ORDER BY distance
`If you want to avoid raw queries for inserts, you can use a Prisma Client extension to wrap the geometry fields cleanly: const extendedPrisma = prisma.$extends({
model: {
recipient: {
async createWithPosition(data: RecipientCreateInput, lat: number, lng: number) {
const created = await prisma.recipient.create({ data })
await prisma.$executeRaw`
UPDATE "Recipient"
SET position = ST_SetSRID(ST_MakePoint(${lng}, ${lat}), 4326)
WHERE id = ${created.id}
`
return created
}
}
}
})The |
|
Prisma's PostGIS support means it recognizes the Here's what a working setup looks like: generator client {
provider = "prisma-client-js"
previewFeatures = ["postgresqlExtensions"]
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
extensions = [postgis]
}
model Location {
id Int @id @default(autoincrement())
name String
geom Unsupported("geometry(Point, 4326)")?
}The const nearby = await prisma.$queryRaw`
SELECT id, name, ST_AsGeoJSON(geom) as geojson
FROM "Location"
WHERE ST_DWithin(geom, ST_MakePoint(${lng}, ${lat})::geography, ${radiusMeters})
`;Make sure:
If you're getting errors during migration, check that PostGIS is actually installed on your Postgres instance (not just the extension enabled in the schema). |
|
The error is clear and the fix is straightforward — the What's actually happeningPrisma's native PostGIS support does not mean you can write PSL field definitions must follow the pattern What Prisma's PostGIS "native support" actually meansThe Prisma documentation page you linked describes support for the datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
extensions = [postgis]
}
generator client {
provider = "prisma-client-js"
previewFeatures = ["postgresqlExtensions"]
}This tells Prisma to include The correct schema — use
|
| What you tried | Why it fails |
|---|---|
location Geometry(Point, 4326)? |
Not a valid PSL type — causes P1012 validation error |
position Unsupported("geometry(Point, 4326)")? |
Correct — use this |
extensions = [postgis] in datasource |
Correct — manages the extension in migrations |
previewFeatures = ["postgresqlExtensions"] in generator |
Required for the extensions block to work |
The Unsupported() syntax on your position field is correct. Delete the location Geometry(Point, 4326)? line and the validation error will resolve immediately.
Hope this helps — if it answers your question, would you mind clicking "Mark as answer" so others searching for the same thing can find it quickly?
PostGIS extension answerThe main issue is that If Prisma rejects that line with: then the problem is not PostGIS itself. The problem is that your Prisma schema parser does not recognize What Prisma supports
Unsupported("geometry(Point, 4326)")?Correct schemadatasource db {
provider = "postgresql"
url = env("DATABASE_URL")
extensions = [postgis]
}
model Recipient {
id String @id @default(uuid())
lastName String @db.VarChar(100)
firstName String @db.VarChar(100)
email String @db.VarChar(255)
phoneNumber String @unique @db.VarChar(20)
streetAddress String @db.VarChar(255)
city String @db.VarChar(100)
stateRegion String? @db.VarChar(100)
postalCode String @db.VarChar(20)
country String @default("France") @db.VarChar(100)
position Unsupported("geometry(Point, 4326)")?
}Why your line failsThe field: position Geometry(Point, 4326)?fails during schema validation because Prisma does not treat that syntax as a valid field declaration in the version that produced your error. That is why the CLI stops before migration even starts. What to do nextIf you want the schema to compile right now, remove the native If you want to use the newer native PostGIS geometry support, make sure your Prisma version matches the current documentation and actually includes that feature. Short answer
|
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Question
hello guys,
I've been trying to use the postgis extension without the Unsupported fallback type since according to their https://www.prisma.io/docs/orm/prisma-schema/postgresql-extensions, postgis is natively supported by Prisma but without much success. I always get the same error:
❯ npx prisma migrate deploy --config libs/shared/api/db/data-access/prisma.config.ts
Loaded Prisma config from libs/shared/api/db/data-access/prisma.config.ts.
Prisma schema loaded from libs/shared/api/db/data-access/prisma/schema.prisma.
Error: Prisma schema validation - (get-config wasm)
Error code: P1012
error: Error validating: This line is not a valid field or attribute definition.
--> libs/shared/api/db/data-access/prisma/schema.prisma:77
|
76 | country String @default("France") @db.VarChar(100)
77 | position Geometry(Point, 4326)?
78 |
|
Validation Error Count: 1
[Context: getConfig]
Prisma CLI Version : 7.8.0
Has anyone managed to successfully compile without "Unsupported"?
thanks in advance!
How to reproduce (optional)
Expected behavior (optional)
No response
Information about Prisma Schema, Client Queries and Environment (optional)
// Add any relevant Prisma Client queries hereOS:
Database:
Node.js version:
Run
prisma -vto see your Prisma version and paste itAll reactions