Rename the trigger node type to debounce, migrating stored flows

The store rewrites `"type": "trigger"` to `debounce` in every published and
draft flow when it opens, bumps the version and commits once. No alias stays
behind, so `trigger` is now an unknown type.
This commit is contained in:
2026-10-15 09:34:40 +02:00
parent 4a776e52c4
commit cfb9e53d68
9 changed files with 98 additions and 35 deletions
+34
View File
@@ -166,6 +166,40 @@ class FlowStore:
if not (self.root / ".git").exists():
self._git("init", "-q")
self._commit("Initialise flow store", allow_empty=True)
self._migrate()
def _migrate(self) -> None:
"""Rewrite node types stored under a name they no longer have.
The node type ``trigger`` became ``debounce`` on 2026-10-15, with no
alias left for the old name. Each published and draft document is read
as plain JSON and only the ``type`` of a matching node changes, so a
field this version does not model survives, and the old document stays
in git. The version goes up by one, so an editor still holding the old
document gets a conflict on its next save instead of writing the old
name back. A store with nothing to rename is left alone.
"""
changed = []
paths = [*self.root.glob("*/flow.json"), *self.root.glob("*/flow.draft.json")]
for path in sorted(paths):
try:
data = json.loads(path.read_text())
nodes = [n for n in data["nodes"] if n.get("type") == "trigger"]
except Exception:
# Unreadable to the engine too, which reports it when it loads.
continue
if not nodes:
continue
for node in nodes:
node["type"] = "debounce"
data["version"] = data.get("version", 1) + 1
path.write_text(json.dumps(data, indent=2, ensure_ascii=False) + "\n")
changed.append(f"{path.parent.name}/{path.name}")
if changed:
logger.warning(
"Renamed node type 'trigger' to 'debounce' in %s", ", ".join(changed)
)
self._commit("Rename node type 'trigger' to 'debounce'")
# -------------------------------------------------------------------------
# git