Commit 779bf2c
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 3ee4d35 commit 779bf2c
File tree
3 files changed
+342
-187
lines changed- src/django_pg_migration_tools
- tests/django_pg_migration_tools
3 files changed
+342
-187
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 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | 63 | | |
67 | 64 | | |
68 | 65 | | |
| |||
99 | 96 | | |
100 | 97 | | |
101 | 98 | | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | 99 | | |
106 | 100 | | |
107 | 101 | | |
| |||
140 | 134 | | |
141 | 135 | | |
142 | 136 | | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | 137 | | |
147 | 138 | | |
148 | 139 | | |
| |||
190 | 181 | | |
191 | 182 | | |
192 | 183 | | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | 184 | | |
198 | 185 | | |
199 | 186 | | |
| |||
286 | 273 | | |
287 | 274 | | |
288 | 275 | | |
289 | | - | |
290 | | - | |
291 | | - | |
292 | 276 | | |
293 | 277 | | |
294 | 278 | | |
| |||
0 commit comments