pgschema icon indicating copy to clipboard operation
pgschema copied to clipboard

Foreign key constraints is ignored if it references tables from pgschemaignore in multi-file setup

Open marcintustin opened this issue 1 year ago • 3 comments

Check out this diff. I just updated to the latest main version (reports itself as 1.4.2; also affects @latest reporting as 1.4.2), and the foreign keys are gone. This does not affect 1.4.1.

diff --git i/schemas/public/tables/ref_sla_suppliers.sql w/schemas/public/tables/ref_sla_suppliers.sql
index e037d30..297abfc 100644
--- i/schemas/public/tables/ref_sla_suppliers.sql
+++ w/schemas/public/tables/ref_sla_suppliers.sql
@@ -9,9 +9,5 @@ CREATE TABLE IF NOT EXISTS ref_sla_suppliers (
     supplier_id integer,
     supplier_id_uuid uuid,
     is_sla boolean DEFAULT true,
-    CONSTRAINT ref_sla_suppliers_pkey PRIMARY KEY (ref_id),
-    CONSTRAINT org_id_fk FOREIGN KEY (org_id) REFERENCES organizations (org_id),
-    CONSTRAINT project_id_fk FOREIGN KEY (project_id) REFERENCES projects (project_id),
-    CONSTRAINT supplier_id_fk FOREIGN KEY (supplier_id) REFERENCES suppliers (supplier_id),
-    CONSTRAINT supplier_id_uuid_fk FOREIGN KEY (supplier_id_uuid) REFERENCES suppliers (id_uuid)
+    CONSTRAINT ref_sla_suppliers_pkey PRIMARY KEY (ref_id)
 );

marcintustin avatar Nov 19 '25 18:11 marcintustin

I added a test suite to cover FK https://github.com/pgschema/pgschema/tree/main/testdata/diff/create_table/add_fk and was not able to reproduce yet.

Please provide the detailed steps, how do you call pgschema (have you happened to use a plan generated from the old release?)

tianzhou avatar Nov 23 '25 14:11 tianzhou

I just dump, no plan. I’ll get the latest main tomorrow and test again.

Marcin Tustin Tel: +1 917 553 3974

On Sun, Nov 23, 2025 at 09:50 Tianzhou @.***> wrote:

tianzhou left a comment (pgschema/pgschema#167) https://github.com/pgschema/pgschema/issues/167#issuecomment-3568034688

I added a test suite to cover FK https://github.com/pgschema/pgschema/tree/main/testdata/diff/create_table/add_fk and was not able to reproduce yet.

Please provide the detailed steps, how do you call pgschema (have you happened to use a plan generated from the old release?)

— Reply to this email directly, view it on GitHub https://github.com/pgschema/pgschema/issues/167#issuecomment-3568034688, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJOUOHPDTPTR3UEOF5UUWT36HCVBAVCNFSM6AAAAACMTMW4VSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTKNRYGAZTINRYHA . You are receiving this because you authored the thread.Message ID: @.***>

marcintustin avatar Nov 23 '25 15:11 marcintustin

So I'm doing this

pgschema dump --host DATABASE_SERVER --db dib --user marcintustin --schema public --file schemas/public/main.sql --multi-file

I think what's happening here is that dump is ignoring foreign keys to tables excluded by .pgschemaignore

$ cat .pgschemaignore 
[tables]
patterns = ["*", "!dim_*", "!fct_*", "!ref_*", "!required_objects*"]

[views]
patterns = ["*", "!v_*", "!mv_*", "!required_objects*"]

[functions]


[procedures]


[types]


[sequences]
patterns = ["*"]

Which I suggest is not the behaviour I'd expect, BUT maybe is more inline with how you envision people using the tool. Maybe add a flag to not exclude those foreign keys? Or just don't exclude those foreign keys :)

marcintustin avatar Nov 24 '25 15:11 marcintustin