pgschema
pgschema copied to clipboard
Allow creating triggers/dependencies on ignored tables
I've run into a common use case with services like Supabase and wanted to suggest a feature.
- I'm using
pgschemato manage mypublicschema, butauthschema is managed by Supabase. - I need to ignore the
auth.userstable in.pgschemaignoreto avoid accidentally changing it. This works perfectly. - However, I also need to create a trigger on
auth.users(e.g., to create a user profile in mypublicschema after a new user signs up). - This creates a conflict: the planner fails because it can't find
auth.users, since the ignore file tells the planner to pretend it doesn't exist.
What Happens Now
This setup causes the plan command to fail.
.pgschemaignore:
[tables]
patterns = ["users"]
schemas/auth/main.sql:
-- This trigger needs to be created on the ignored 'users' table.
CREATE TRIGGER on_user_created
AFTER INSERT ON auth.users
FOR EACH ROW
EXECUTE FUNCTION public.create_profile_for_new_user();
Command & Error:
$ pgschema plan --schema auth
...
Error: failed to parse desired state schema file: table auth.users not found for trigger on_user_created
The ideal behavior would be for the plan command to succeed, acknowledging that the trigger is being attached to an ignored (but present) table.
Expected Plan Output:
Plan: 1 to add.
Summary by type:
triggers: 1 to add
Triggers:
+ on_user_created
DDL to be executed:
--------------------------------------------------
CREATE TRIGGER on_user_created AFTER INSERT ON users ...;
This feature would allow users to manage their entire application schema declaratively within pgschema, even when integrating with third-party schemas.
Thanks so much! The fix was super fast — really appreciate it. 😍