fix(campaigns): preserve modification-request audit row after test deletion
Approving a remove_test modification request deletes the underlying Test row, which was cascading through test_id's ON DELETE CASCADE and wiping out the request row itself before it could be read back. Changed to ON DELETE SET NULL so the audit record (justification, reviewer, decision) survives. Adds regression coverage plus double-approve/reject idempotency tests.
This commit is contained in:
@@ -259,10 +259,14 @@ class CampaignModificationRequest(Base):
|
||||
nullable=True,
|
||||
)
|
||||
action = Column(String, nullable=False) # add_test, remove_test
|
||||
# SET NULL (not CASCADE): approving a "remove_test" request deletes the
|
||||
# underlying Test row (see remove_test_from_campaign), and this request
|
||||
# row is the audit record of that decision — it must survive the test's
|
||||
# deletion, not be wiped out along with it.
|
||||
test_id = Column(
|
||||
UUID(as_uuid=True),
|
||||
ForeignKey("tests.id", ondelete="CASCADE"),
|
||||
nullable=False,
|
||||
ForeignKey("tests.id", ondelete="SET NULL"),
|
||||
nullable=True,
|
||||
)
|
||||
order_index = Column(Integer, nullable=True)
|
||||
phase = Column(String, nullable=True)
|
||||
|
||||
Reference in New Issue
Block a user