-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
feat(db-postgres): add point field support #9078
Conversation
7c9f9ce
to
da706cf
Compare
da706cf
to
d942d8c
Compare
573b428
to
807df29
Compare
This reverts commit b3e1fe4.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great to see all the work here. I didn't pull this down, int test coverage is likely all we need.
packages/db-postgres/package.json
Outdated
"console-table-printer": "2.12.1", | ||
"drizzle-kit": "0.26.2", | ||
"drizzle-orm": "0.35.1", | ||
"console-table-printer": "2.11.2", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unexpected. Was there a problem?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
merge conflict mistake ✅
packages/db-postgres/src/connect.ts
Outdated
@@ -100,6 +100,11 @@ export const connect: Connect = async function connect( | |||
process.exit(1) | |||
} | |||
|
|||
if (this.extensionsFilter.has('postgis') && !this.postgisCreated) { | |||
await this.drizzle.execute(`CREATE EXTENSION IF NOT EXISTS postgis`) | |||
this.postgisCreated = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add an extensions
object for future things like pg_search
so that the root of the adapter doesn't get messy. For now we'll just have this.extensions.postgis = true
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ + made it a bit more universal with createExtensions
packages/db-postgres/src/index.ts
Outdated
@@ -97,6 +98,7 @@ export function postgresAdapter(args: Args): DatabaseAdapterObj<PostgresAdapter> | |||
pgSchema: adapterSchema, | |||
pool: undefined, | |||
poolOptions: args.pool, | |||
postgisCreated: false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use extensions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅
packages/db-postgres/src/types.ts
Outdated
@@ -29,6 +29,7 @@ export type Args = { | |||
* @default false | |||
*/ | |||
disableCreateDatabase?: boolean | |||
extensionsFilter?: string[] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think, is this redundant if we have extensionsFilter
? Ideally somebody could enable extensions that Payload doesn't know or care about but still passes this to drizzle. 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually drizzle's extensionsFilter
supports only postgis
https://github.com/drizzle-team/drizzle-orm/blob/83daf2d5cf023112de878bc2249ee2c41a2a5b1b/drizzle-kit/src/cli/validations/cli.ts#L26 so it's kinda useless property. I updated how we handle extensions and now you can pass for example:
extensions: ['vector']
and it'll actually create the vector
extension on connect / when running migrations. I think it's useful
customType<{ data: Point; driverData: string }>({ | ||
dataType() { | ||
return `geometry(Point,4326)` | ||
}, | ||
fromDriver(value: string) { | ||
return parseEWKB(value) | ||
}, | ||
toDriver(value: Point) { | ||
return `SRID=4326;point(${value[0]} ${value[1]})` | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have much to learn. Does this support DEFAULT
? Any other gotchas going this low level with a custom data type for postgres?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, if we ever need to get away from this, it seems like it'd be a breaking change/require migration will be needed. We might want to get a status update on the underlying issues you found from Drizzle before we roll this out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DEFAULT
- yes, but actually even in MongoDB we had a bug with it, so now we support both
The geometry
export from drizzle-or/pg-core
has fully the same implementation regardless geometry(Point)
(uppercase vs lowecase https://github.com/drizzle-team/drizzle-orm/blob/83daf2d5cf023112de878bc2249ee2c41a2a5b1b/drizzle-orm/src/pg-core/columns/postgis_extension/geometry.ts#L38).
I made a PR to Drizzle which will solve our issue drizzle-team/drizzle-orm#3517, but we can use this fine as well, migration won't be needed as the type is the same.
68a59ec
to
6072b15
Compare
🚀 This is included in version v3.0.0-beta.127 |
What?
Adds full support for the point field to Postgres and Vercel Postgres adapters through the Postgis extension. Fully the same API as with MongoDB, including support for
near
,within
andintersects
operators.Additionally, exposes to adapter args:
tablesFilter
https://orm.drizzle.team/docs/drizzle-kit-push#including-tables-schemas-and-extensions.extensions
list of extensions to create, for example['vector', 'pg_search']
,postgis
is created automatically if there's any point fieldWhy?
It's essential to support that field type, especially if the postgres adapter should be out of beta on 3.0 stable.
How?
drizzle-orm
to0.36.1
anddrizzle-kit
to0.28.0
as we need this change feat: add tablesFilter to pushSchema api drizzle-team/drizzle-orm#3141near
operator works throughST_DWithin
orintersects
throughST_Intersects
.Resolves these discussions:
#8996
#8644