Commit de312d9
committed
Make constraint queries schema-aware for multi-tenancy
Prior to this change, the ConstraintQueries class queried
pg_catalog.pg_constraint without filtering by PostgreSQL schema.
This caused incorrect behavior in multi-tenant environments using
django-tenants, where each tenant has its own schema. The queries
would detect constraints from other tenants' schemas, leading to
false positives (e.g., ConstraintAlreadyExists errors when creating
a second tenant).
This change adds INNER JOINs with pg_catalog.pg_class and
pg_catalog.pg_namespace to filter constraints by current_schema().
This ensures that constraint checks only look at the current tenant's
schema, not across all schemas in the database.
Affected queries:
- CHECK_EXISTING_CONSTRAINT
- CHECK_CONSTRAINT_IS_VALID
- CHECK_CONSTRAINT_IS_NOT_VALID
Related issue: #921 parent 5c2cbaf commit de312d9
File tree
2 files changed
+342
-171
lines changed- src/django_pg_migration_tools
- tests/django_pg_migration_tools
2 files changed
+342
-171
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
56 | | - | |
57 | | - | |
58 | | - | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
59 | 62 | | |
60 | 63 | | |
61 | 64 | | |
62 | 65 | | |
63 | | - | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
64 | 69 | | |
65 | | - | |
66 | | - | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
67 | 73 | | |
68 | 74 | | |
69 | 75 | | |
70 | 76 | | |
71 | | - | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
72 | 80 | | |
73 | | - | |
74 | | - | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
75 | 84 | | |
76 | 85 | | |
77 | 86 | | |
| |||
0 commit comments