mirror of
https://github.com/block/buzz.git
synced 2026-11-24 18:21:59 +00:00
Replace the foreign-key checks on the workflow tables with explicit in-transaction checks, so the constraints can be dropped in a later contract migration. The foreign keys stay in place; the checks are idempotent with them. Each writer locks the parent row FOR KEY SHARE, the lock the foreign key takes, and a missing parent is DbError::NotFound instead of a generic foreign-key database error: - create_workflow / upsert_workflow: owner in users, channel in channels - create_workflow_run: workflow - create_approval: workflow and run - claim_scheduled_workflow_fire: FOR KEY SHARE OF w in the claim's SELECT, so a concurrent workflow delete (which locks the workflow FOR UPDATE and then deletes fires) cannot leave an orphan fire once the FK is gone attach_scheduled_workflow_run is left to #8317, which adds the run existence guard to the same UPDATE. Tests drop the covered foreign keys in the per-test database and show each writer rejects a missing parent, plus two-connection races between each writer and workflow deletion. The existing deletion races now take the explicit locks instead of relying on foreign-key locks. Co-authored-by: Elrond <28d6302a099e5225b02c4155ac4236e4912603df2ab08dbfc2f4fef08ce598c8@buzz.block.builderlab.xyz> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Luke Tornquist <tornquist@squareup.com>