Files
buzz/migrations/0040_workflow_revision_binding.sql
Logan Johnson a11e396c2c Invalidate workflow revision bindings across legacy writes
Clear bindings at the database materialization boundary, even on equal-value legacy updates. Rebind inside atomic signed ingest while holding the row lock.

Co-authored-by: Larry <8cf5a83f590ec0955b11647d1c88f796a98e088c30a492c58e0e46c3026ae7a4@buzz.block.builderlab.xyz>
Signed-off-by: Logan Johnson <loganj@squareup.com>
Signed-off-by: Larry <8cf5a83f590ec0955b11647d1c88f796a98e088c30a492c58e0e46c3026ae7a4@buzz.block.builderlab.xyz>
Signed-off-by: Logan Johnson <loganj@squareup.com>
2026-09-04 06:20:21 -04:00

25 lines
1.1 KiB
PL/PgSQL

-- Preserve exact signed workflow revisions without changing legacy execution.
-- Existing rows remain NULL until a new signed definition is ingested.
ALTER TABLE workflows
ADD COLUMN definition_event_id BYTEA
CHECK (definition_event_id IS NULL OR octet_length(definition_event_id) = 32);
ALTER TABLE workflow_runs
ADD COLUMN definition_event_id BYTEA
CHECK (definition_event_id IS NULL OR octet_length(definition_event_id) = 32);
-- A legacy writer does not mention definition_event_id. Column-targeted triggers
-- fire even for equal-value rewrites, where comparing OLD/NEW would invent
-- provenance. New writers rebind separately while still holding the row lock
-- in the signed-event transaction. Operational status/enabled updates keep it.
CREATE FUNCTION invalidate_workflow_revision() RETURNS TRIGGER AS $$
BEGIN
NEW.definition_event_id := NULL;
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
CREATE TRIGGER workflows_invalidate_revision
BEFORE UPDATE OF id, community_id, owner_pubkey, channel_id, name, definition, definition_hash
ON workflows
FOR EACH ROW EXECUTE FUNCTION invalidate_workflow_revision();