You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
CONSTRAINT a_id_fk FOREIGN KEY (a_id) REFERENCES a (id)
2269
+
) LOCALITY REGIONAL BY ROW
2270
+
2271
+
# Insert data that will cause a foreign key violation when we try to add the composite FK.
2272
+
statement ok
2273
+
INSERT INTO a (id, crdb_region) VALUES ('4227eceb-71d6-422c-808b-6a12ec8a1e54', 'us-east-1')
2274
+
2275
+
statement ok
2276
+
INSERT INTO b (id, a_id, crdb_region) VALUES ('8f6ce660-423e-4823-8e41-bf001a007b46', '4227eceb-71d6-422c-808b-6a12ec8a1e54', 'ca-central-1')
2277
+
2278
+
# This statement should fail with a foreign key violation, and the schema change
2279
+
# should properly revert without causing infinite retries due to the missing RBRUsingConstraint.
2280
+
# Prior to the bugfix, the rollback logic would would drop the constraint but
2281
+
# not clear the RBRUsingConstraint field, causing validation to fail during
2282
+
# the rollback.
2283
+
statement error pgcode 23503 pq: foreign key violation: "b" row crdb_region='ca-central-1', a_id='4227eceb-71d6-422c-808b-6a12ec8a1e54', id='8f6ce660-423e-4823-8e41-bf001a007b46' has no match in "a"
2284
+
ALTER TABLE b
2285
+
DROP CONSTRAINT a_id_fk,
2286
+
ADD CONSTRAINT a_crdb_region_id_fk
2287
+
FOREIGN KEY (crdb_region, a_id) REFERENCES a (crdb_region, id) ON UPDATE CASCADE ON DELETE CASCADE,
2288
+
SET (infer_rbr_region_col_using_constraint = a_crdb_region_id_fk)
2289
+
2290
+
# Verify the tables are still functional after the failed schema change.
0 commit comments