Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

PostgresAdapter beforeSchemaInit does not handle sql views #8994

Closed
JesperWe opened this issue Nov 2, 2024 · 1 comment
Closed

PostgresAdapter beforeSchemaInit does not handle sql views #8994

JesperWe opened this issue Nov 2, 2024 · 1 comment
Labels

Comments

@JesperWe
Copy link
Contributor

JesperWe commented Nov 2, 2024

Describe the Bug

The docs state about beforeSchemaInit:

Runs before the schema is built. You can use this hook to extend your database structure with tables that won't be managed by Payload. ... One use case is preserving your existing database structure when migrating to Payload.

The ability to perserve existing database structure is however limited to databases that have tables that are not to be managed by Payload.
If the DB has SQL views defiend, Drizzle will attempt to delete those views and there is no way in the PostgresSchema type to add views, it only supports Enums, Relations and Tables.

Drizzle itself supports adding pgView, but that feature does not seem to be propagated.

Link to the code that reproduces this issue

https://github.com/payloadcms/payload/blob/beta/packages/drizzle/src/postgres/types.ts

Reproduction Steps

One easy way to reproduce is to enable the very popular PostGIS extension in a Postgres database

CREATE EXTENSION postgis;

and then try to enable Payload for that database. The extra spatial_ref_sys table required by PostGIS can be handled in beforeSchemaInit but the required views can not. Drizzle will try to delete them, which will fail.

Which area(s) are affected? (Select all that apply)

db-postgres

Environment Info

Binaries:
Node: 20.11.0
npm: 10.8.2
Yarn: 1.22.19
pnpm: 9.12.2
Relevant Packages:
payload: 3.0.0-beta.123
next: 15.0.1
@payloadcms/db-mongodb: 3.0.0-beta.123
@payloadcms/db-postgres: 3.0.0-beta.123
@payloadcms/graphql: 3.0.0-beta.123
@payloadcms/next/utilities: 3.0.0-beta.123
@payloadcms/richtext-lexical: 3.0.0-beta.123
@payloadcms/richtext-slate: 3.0.0-beta.123
@payloadcms/translations: 3.0.0-beta.123
@payloadcms/ui/shared: 3.0.0-beta.123
react: 19.0.0-rc-65a56d0e-20241020
react-dom: 19.0.0-rc-65a56d0e-20241020

@JesperWe JesperWe added status: needs-triage Possible bug which hasn't been reproduced yet v3 validate-reproduction labels Nov 2, 2024
@JesperWe JesperWe changed the title PostgresAdapter beforeSchemaInit does not handle database views PostgresAdapter beforeSchemaInit does not handle sql views Nov 2, 2024
@jmikrut
Copy link
Member

jmikrut commented Nov 2, 2024

Hey @JesperWe — I think this is something that we can likely add to Payload. Good call. I will add this to the roadmap and we should be able to get to it shortly!

@payloadcms payloadcms locked and limited conversation to collaborators Nov 2, 2024
@jmikrut jmikrut converted this issue into discussion #8996 Nov 2, 2024
@github-actions github-actions bot removed the status: needs-triage Possible bug which hasn't been reproduced yet label Nov 2, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
Projects
None yet
Development

No branches or pull requests

2 participants