Skip to content
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

Lint to detect missing event triggers for PostgREST automatic schema cache reloading #21

Open
steve-chavez opened this issue Mar 29, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@steve-chavez
Copy link
Member

Problem

A user was complaining about supabase-js/PostgREST failing to detect new table changes. The root cause was the user somehow wiped the functions + event triggers (maybe Prisma or other ORM that drops the db).

The functions are documented in https://postgrest.org/en/v12/references/schema_cache.html#finer-grained-event-trigger. On Supabase they're expected to be on the extensions schema.

  • extensions.pgrst_ddl_watch
  • extensions.pgrst_drop_watch

Proposal

Could we WARN whenever the expected triggers are missing?

Note

The issue_graphql_placeholder trigger was also missing for this user, so perhaps this can be a lint for all the expected event triggers.

@steve-chavez steve-chavez added the enhancement New feature or request label Mar 29, 2024
@olirice
Copy link
Collaborator

olirice commented Mar 29, 2024

What's the expected remediation for this?
The user won't have super so they can't create an event trigger.

Would we tell them to reach out to support? If so, would it make more sense to scan internally and resolve it proactively?

@steve-chavez
Copy link
Member Author

Yes, I solved it manually for the user.

The thing is that:

drop event trigger pgrst_drop_watch; -- fails
-- ERROR:  42501: must be owner of event trigger pgrst_drop_watch

drop function extensions.pgrst_drop_watch; --fails
-- ERROR:  2BP01: cannot drop function pgrst_drop_watch() because other objects depend on it
-- DETAIL:  event trigger pgrst_drop_watch depends on function pgrst_drop_watch()
-- HINT:  Use DROP ... CASCADE to drop the dependent objects too.

drop function extensions.pgrst_drop_watch cascade; -- succeeds and drops the event trigger 

Which is really surprising behavior. It seems like a pg bug to me. Maybe we can work around it on supautils?

@steve-chavez
Copy link
Member Author

If so, would it make more sense to scan internally and resolve it proactively?

Right, this probably doesn't make sense as a lint then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants