From 816f143ffd6a0780b2157ed9f76650b182905fd8 Mon Sep 17 00:00:00 2001 From: MechaCat02 Date: Tue, 23 Jun 2026 21:09:22 +0200 Subject: [PATCH] =?UTF-8?q?feat(triggers):=20add=20`name`=20column=20+=20b?= =?UTF-8?q?ackfill=20(=C2=A74.5,=20schema=20step)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Schema groundwork for the trigger `name` identity (the manifest merge key that will let `apply` Update a trigger in place rather than only Create/Delete). A `gen_random_uuid()` default keeps the existing write paths valid and unique without code changes; existing rows are backfilled to the readable `{kind}-{n}` form; `UNIQUE(app_id, name)` is enforced. No behavior change yet — the manager-core write paths and the apply diff start using the name in the follow-up. Verified the migration applies and the trigger journeys (which create triggers via the unnamed path → default name) stay green. Co-Authored-By: Claude Opus 4.8 (1M context) --- .../migrations/0046_trigger_name.sql | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 crates/manager-core/migrations/0046_trigger_name.sql diff --git a/crates/manager-core/migrations/0046_trigger_name.sql b/crates/manager-core/migrations/0046_trigger_name.sql new file mode 100644 index 0000000..a941aa8 --- /dev/null +++ b/crates/manager-core/migrations/0046_trigger_name.sql @@ -0,0 +1,29 @@ +-- Trigger `name` (§4.5): an explicit per-app identifier that becomes the +-- manifest merge/upsert key (Step B switches the apply diff to key on it). +-- Until now triggers were identified only by their per-kind semantic tuple, +-- so the declarative tool could only Create/Delete them, never Update. +-- +-- Backfill existing rows with `{kind}-{n}` (n = per-(app,kind) sequence by +-- creation order) — the spec-sanctioned fallback when there's no cleaner +-- entity token. Then enforce NOT NULL + UNIQUE(app_id, name). + +-- A `gen_random_uuid()` default keeps existing INSERTs (which don't yet +-- supply a name) valid and unique — the manager-core write paths start +-- providing meaningful names in the follow-up; new rows until then get a +-- harmless unique placeholder. +ALTER TABLE triggers + ADD COLUMN name TEXT NOT NULL DEFAULT gen_random_uuid()::text; + +-- Rewrite the just-defaulted existing rows to the readable `{kind}-{n}` form. +UPDATE triggers t +SET name = sub.nm +FROM ( + SELECT id, + kind || '-' || row_number() OVER ( + PARTITION BY app_id, kind ORDER BY created_at, id + ) AS nm + FROM triggers +) sub +WHERE t.id = sub.id; + +CREATE UNIQUE INDEX triggers_app_name_uniq ON triggers (app_id, name);