pgschema icon indicating copy to clipboard operation
pgschema copied to clipboard

Allow creating triggers/dependencies on ignored tables

Open natty-pluz opened this issue 1 year ago • 1 comments

I've run into a common use case with services like Supabase and wanted to suggest a feature.

  1. I'm using pgschema to manage my public schema, but auth schema is managed by Supabase.
  2. I need to ignore the auth.users table in .pgschemaignore to avoid accidentally changing it. This works perfectly.
  3. However, I also need to create a trigger on auth.users (e.g., to create a user profile in my public schema after a new user signs up).
  4. 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.

natty-pluz avatar Oct 08 '25 02:10 natty-pluz

Thanks so much! The fix was super fast — really appreciate it. 😍

natty-pluz avatar Oct 08 '25 09:10 natty-pluz