diff --git a/crates/manager-core/migrations/0061_shared_triggers.sql b/crates/manager-core/migrations/0061_shared_triggers.sql new file mode 100644 index 0000000..7578682 --- /dev/null +++ b/crates/manager-core/migrations/0061_shared_triggers.sql @@ -0,0 +1,21 @@ +-- §11.6 / §4.5: SHARED-collection triggers. +-- +-- A §11.6 shared collection is group-owned and written by any subtree app via +-- the `kv::shared_collection(...)` handles. Until now such writes fired NO +-- trigger (the "group trigger has no app to watch" deferral): the per-app +-- trigger dispatch keys on the writer app's OWN collections, and a shared +-- collection lives in a distinct group-keyed store. +-- +-- A SHARED trigger closes that gap: a group-owned trigger template marked +-- `shared = true` watches the group's shared collection (not per-app +-- collections). On a shared-collection write the emitter matches these triggers +-- by the OWNING GROUP's chain and runs the handler under the WRITER app +-- (`cx.app_id`) — the same "group template runs under the firing app" model. +-- +-- The `shared` marker is the namespace boundary: a `shared = false` trigger +-- (the default, incl. every existing row) watches per-app collections exactly +-- as before; a `shared = true` trigger watches shared collections only. The two +-- never cross (the per-app match queries add `AND t.shared = FALSE`, the shared +-- match queries `AND t.shared = TRUE`). + +ALTER TABLE triggers ADD COLUMN shared BOOLEAN NOT NULL DEFAULT FALSE; diff --git a/crates/manager-core/tests/expected_schema.txt b/crates/manager-core/tests/expected_schema.txt index ef6a6af..1f9774f 100644 --- a/crates/manager-core/tests/expected_schema.txt +++ b/crates/manager-core/tests/expected_schema.txt @@ -409,6 +409,7 @@ table: triggers name: text NOT NULL default=(gen_random_uuid())::text group_id: uuid NULL sealed: boolean NOT NULL default=false + shared: boolean NOT NULL default=false table: vars id: uuid NOT NULL default=gen_random_uuid() @@ -940,3 +941,4 @@ constraints on vars: 0058: template suppressions 0059: sealed templates 0060: group suppressions + 0061: shared triggers