Skip to content

docs(adr): ADR 005 — functions and triggers as typed code (#91) - #190

Merged
productdevbook merged 1 commit into
mainfrom
docs/adr-005-functions-triggers
May 20, 2026
Merged

productdevbook merged 1 commit into
mainfrom
docs/adr-005-functions-triggers

Conversation

@productdevbook

Copy link
Copy Markdown
Owner

Summary

Frames the response to #91 (@deslunes — "Functions and triggers as code"). Two-phase rollout:

  • Phase 1 (this ADR + paired impl PR): `CREATE FUNCTION` with a typed expression body, `CREATE TRIGGER` DDL, `DROP FUNCTION` / `DROP TRIGGER`, and call-site type inference (`fn.call({ args })` → `Expression`). PG-only.
  • Phase 2 (deferred — sketched in the ADR): procedural plpgsql control flow (IF/LOOP/RAISE), variable declarations, magic variables (NEW/OLD/TG_OP/FOUND).

Why typed body, not raw SQL

The ADR argues against the half-measure of raw-SQL function bodies: it ships DDL ergonomics without the type safety the issue is actually asking for. The expression body is small enough to do right in Phase 1; control flow is the hard part and goes to Phase 2.

The issue author's own framing — "partially implement it, with guardrails so that it stays simple" — maps cleanly onto this split.

Test plan

Doc-only PR. CI will run.

🤖 Generated with Claude Code

Frames the response to #91: two-phase rollout. Phase 1 ships
CREATE FUNCTION with a typed expression body + CREATE TRIGGER DDL,
both PG-only. Phase 2 is the procedural plpgsql control flow
(IF/LOOP/RAISE) — sketched here, deferred to its own implementation.

The ADR's main argument: a raw-SQL body half-measure declares
victory at the easy half. The issue is asking for type safety over
the body, so Phase 1 commits to the typed surface even at the cost
of refusing control flow (which would land in Phase 2 additively).

Includes the AST shape, builder API, printer plan, and call-site
inference design — enough for the implementation PR to follow.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@productdevbook
productdevbook merged commit 77fcb90 into main May 20, 2026
1 check passed
@productdevbook
productdevbook deleted the docs/adr-005-functions-triggers branch May 20, 2026 02:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant