Skip to content

feat: management API endpoints for functions (index / show / delete)#2137

Open
mm-zacharydavison wants to merge 1 commit intosequinstream:mainfrom
mm-zacharydavison:zach/feat/function-api-delete
Open

feat: management API endpoints for functions (index / show / delete)#2137
mm-zacharydavison wants to merge 1 commit intosequinstream:mainfrom
mm-zacharydavison:zach/feat/function-api-delete

Conversation

@mm-zacharydavison
Copy link
Copy Markdown

@mm-zacharydavison mm-zacharydavison commented Apr 24, 2026

Summary

Adds REST management API endpoints for functions:

  • GET /api/functions — list all functions for the authenticated account
  • GET /api/functions/:id_or_name — fetch one
  • DELETE /api/functions/:id_or_name — delete one

Why

Today sequin config apply upserts functions but never removes them (see the comment at upsert_functions/2 — omitting a function from YAML does not delete it). The only way to delete a function is the LiveView UI. That makes automated lifecycle management (e.g. cleaning up orphaned functions after rename/recolor deploys, or from orchestrator tools) impossible via the management API.

This PR fills that gap with the read + delete half of the CRUD surface. Create/update are intentionally not included — they remain owned by config apply and the LiveView UI, where validation and complex function-type handling already live. Opening that up later is a separate conversation; the read + delete endpoints are the minimum useful surface and composed cleanly on top of existing Consumers functions.

Implementation notes

  • Extends Consumers.find_function/2 with :id_or_name, mirroring the existing lookup pattern for HTTP endpoints and sinks (Function.where_id_or_name/2 already existed).
  • Controller mirrors HttpEndpointController / SinkConsumerController conventions. JSON view reuses Sequin.Transforms.to_external/1.
  • Delete preserves the existing foreign-key guards on sink_consumers.function_id and sink_consumers.routing_id — a function still attached to a sink cannot be deleted.

Tests

Controller tests cover:

  • Index (scoped to account, excludes others)
  • Show by id, show by name, cross-account 404
  • Delete by id, delete by name, cross-account 404 (delete forbidden when function is in use by a sink)

Related context

Our team runs a red-black orchestrator on top of Sequin (sequin-red-black) that creates colored variants of functions (<pipeline>_<color>-transform) per deploy. After activating a new color and dropping the old, the old functions become orphans that only the UI can delete. This endpoint is the primary piece we need for end-to-end cleanup automation.

Happy to adjust scope / naming / placement per maintainer preference.

@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. enhancement New feature or request labels Apr 24, 2026
@mm-zacharydavison mm-zacharydavison force-pushed the zach/feat/function-api-delete branch from 4fa6f39 to 9fd88e2 Compare April 24, 2026 10:50
Exposes index / show / delete for functions at /api/functions. Fills
a gap that forced operators into either the LiveView UI or direct DB
access to clean up orphaned transforms/enrichments — config apply is
upsert-only and never removes them.

- Extends Consumers.find_function/2 with :id_or_name lookup, matching
  how other resources accept either a UUID or a human name.
- Controller mirrors HttpEndpointController conventions; JSON view
  reuses Sequin.Transforms.to_external/1.
- Delete preserves the existing foreign-key guards on
  sink_consumers.function_id and sink_consumers.routing_id, so sinks
  still pin their functions.

Create/update are deliberately out of scope — those remain owned by
sequin config apply / the web UI, where validation is centralized.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@mm-zacharydavison mm-zacharydavison force-pushed the zach/feat/function-api-delete branch from 9fd88e2 to b765ce9 Compare April 24, 2026 10:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant