activerecord-cockroachdb-adapter icon indicating copy to clipboard operation
activerecord-cockroachdb-adapter copied to clipboard

`validate: false` is always appended to schema dumps

Open BuonOmo opened this issue 1 year ago • 0 comments

All of these tests are failing:

  • test_dump_foreign_key_targeting_different_schema
  • test_schema_dumping
  • test_schema_dumping_on_delete_and_on_update_options
  • test_schema_dumping_with_validate_false
  • test_schema_dumping_with_validate_true
  • test_schema_dumping_with_custom_fk_ignore_pattern

I haven't verified for all of them, but for most the bug is actually that the fk is not validated. This likely comes from :

https://github.com/cockroachdb/cockroach/blob/bfd7d1dfd002cf8b7d504d9732e2ae494c1abb9b/pkg/sql/backfill.go#L2593-L2605

We can't support adding a validated foreign key constraint in the same transaction as the CREATE TABLE statement. This would require adding the backreference to the other table and then validating the constraint for whatever rows were inserted into the referencing table in this transaction, which requires multiple schema changer states across multiple transactions.

We could partially fix this by queuing a validation job to run post- transaction. Better yet would be to absorb this into the transactional schema change framework eventually.

For now, just always add the FK as unvalidated.

 fk.ForeignKeyDesc().Validity = descpb.ConstraintValidity_Unvalidated

BuonOmo avatar Jan 22 '24 23:01 BuonOmo