feat(db-postgres): add point field support (#9078)

### 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` and `intersects`
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
field

### Why?
It's essential to support that field type, especially if the postgres
adapter should be out of beta on 3.0 stable.

### How?
* Bumps `drizzle-orm` to `0.36.1` and `drizzle-kit` to `0.28.0` as we
need this change https://github.com/drizzle-team/drizzle-orm/pull/3141
* Uses its functions to achieve querying functionality, for example the
`near` operator works through `ST_DWithin` or `intersects` through
`ST_Intersects`.
* Removes MongoDB condition from all point field tests, but keeps for
SQLite

Resolves these discussions:
https://github.com/payloadcms/payload/discussions/8996
https://github.com/payloadcms/payload/discussions/8644
This commit is contained in:
Sasha
2024-11-11 16:31:47 +02:00
committed by GitHub
parent a421503111
commit 0a15388edb
44 changed files with 887 additions and 404 deletions

View File

@@ -36,6 +36,7 @@ import {
convertPathToJSONTraversal,
countDistinct,
createDatabase,
createExtensions,
createJSONQuery,
createMigration,
defaultDrizzleSnapshot,
@@ -75,15 +76,22 @@ export function vercelPostgresAdapter(args: Args = {}): DatabaseAdapterObj<Verce
adapterSchema = { enum: pgEnum, table: pgTable }
}
const extensions = (args.extensions ?? []).reduce((acc, name) => {
acc[name] = true
return acc
}, {})
return createDatabaseAdapter<VercelPostgresAdapter>({
name: 'postgres',
afterSchemaInit: args.afterSchemaInit ?? [],
beforeSchemaInit: args.beforeSchemaInit ?? [],
createDatabase,
createExtensions,
defaultDrizzleSnapshot,
disableCreateDatabase: args.disableCreateDatabase ?? false,
drizzle: undefined,
enums: {},
extensions,
features: {
json: true,
},
@@ -107,6 +115,7 @@ export function vercelPostgresAdapter(args: Args = {}): DatabaseAdapterObj<Verce
sessions: {},
tableNameMap: new Map<string, string>(),
tables: {},
tablesFilter: args.tablesFilter,
transactionOptions: args.transactionOptions || undefined,
versionsSuffix: args.versionsSuffix || '_v',