Rename declared event type columns to avoid confusion with event_types #2128

Closed
opened 2026-11-23 13:13:56 +00:00 by sam · 1 comment
Owner

The original premise was wrong. events.events.type, events.triggers.event_type and events.groups.event_type never hold an events.event_types name, so they can't disagree with event_type_id after a rename. They hold the event kind the connector declares in its capabilities (for example incident.opened), plus three built-in kinds with no connector: schedule.tick (modules/events/schedule.go), approval.answer and account.link (modules/events/events.go). events.event_types is a different thing: an operator-defined classifier (rule and schema) on one source, already referenced only by event_type_id. There is no drafts.drafts table.

The defect is the naming: event_type next to event_type_id on events.triggers reads as two references to one thing.

Decision

Keep both concepts. Rename the declared-kind columns to declared_event_type. Not connector_event_type, because the built-in kinds have no connector. Don't fold declared kinds into events.event_types: they have a different lifecycle (they come from a connector manifest, and schedule.tick has no source).

Change

Edit the baseline internal/platform/pg/migrations/00003_events.sql in place (no new migration file; the database is recreated):

  • events.events.type becomes declared_event_type. Update the partial index events_schedule_slot (WHERE source_id IS NULL AND declared_event_type = 'schedule.tick').
  • events.triggers.event_type becomes declared_event_type.
  • events.groups.event_type becomes declared_event_type.
  • Add a comment on each table saying the column is the kind the connector declares, matched by value, and is not a reference to events.event_types.

Go, in modules/events:

  • internal/store/store.go: Event.Type, Trigger.EventType, the triggerColumns list, the trigger upsert, Triggers (matching declared_event_type = $3 OR declared_event_type = ''), Recent (the type filter), and the e.type = 'schedule.tick' case in the outcome query.
  • internal/store/groups.go and internal/store/drafting.go: the events.groups insert, the open-groups query (its join t.event_type = g.event_type), and the event select.
  • events.go, grouping.go, schedule.go, drafting.go, api.go (triggerInput.EventType, triggerView.EventType, proposedTrigger.EventType, the type query parameter on the events list, eventView.Type, and the body.event_type error locations in checkEventType).
  • modules/proposals/trigger.go and modules/proposals/api.go: the EventType fields carried from a group into a trigger proposal and its JSON (event_type).

Rename the Go fields to DeclaredEventType and the JSON fields and query parameter to declared_event_type, so the API carries the same distinction. Then run task openapi:generate and update the dashboard callers: ui/src/lib/api.ts, ui/src/events/trigger.ts, ui/src/events/TriggerList.vue, ui/src/workflows/use-workflow-list.ts, ui/src/proposals/ProposalPage.vue. Check ui/src/captures/state.ts and ui/src/captures/event-types.ts: their event_type is the capture view's event type id (modules/events/api_capture.go, captureView.EventType) and should become event_type_id for the same reason.

Done when

  • No column, Go field or JSON field named event_type or type holds a declared kind; every one is declared_event_type.
  • events.event_types is referenced only through event_type_id, and its name is read from events.event_types when shown.
  • task check passes.
The original premise was wrong. `events.events.type`, `events.triggers.event_type` and `events.groups.event_type` never hold an `events.event_types` name, so they can't disagree with `event_type_id` after a rename. They hold the event kind the connector declares in its capabilities (for example `incident.opened`), plus three built-in kinds with no connector: `schedule.tick` (`modules/events/schedule.go`), `approval.answer` and `account.link` (`modules/events/events.go`). `events.event_types` is a different thing: an operator-defined classifier (`rule` and `schema`) on one source, already referenced only by `event_type_id`. There is no `drafts.drafts` table. The defect is the naming: `event_type` next to `event_type_id` on `events.triggers` reads as two references to one thing. ## Decision Keep both concepts. Rename the declared-kind columns to `declared_event_type`. Not `connector_event_type`, because the built-in kinds have no connector. Don't fold declared kinds into `events.event_types`: they have a different lifecycle (they come from a connector manifest, and `schedule.tick` has no source). ## Change Edit the baseline `internal/platform/pg/migrations/00003_events.sql` in place (no new migration file; the database is recreated): - `events.events.type` becomes `declared_event_type`. Update the partial index `events_schedule_slot` (`WHERE source_id IS NULL AND declared_event_type = 'schedule.tick'`). - `events.triggers.event_type` becomes `declared_event_type`. - `events.groups.event_type` becomes `declared_event_type`. - Add a comment on each table saying the column is the kind the connector declares, matched by value, and is not a reference to `events.event_types`. Go, in `modules/events`: - `internal/store/store.go`: `Event.Type`, `Trigger.EventType`, the `triggerColumns` list, the trigger upsert, `Triggers` (matching `declared_event_type = $3 OR declared_event_type = ''`), `Recent` (the `type` filter), and the `e.type = 'schedule.tick'` case in the outcome query. - `internal/store/groups.go` and `internal/store/drafting.go`: the `events.groups` insert, the open-groups query (its join `t.event_type = g.event_type`), and the event select. - `events.go`, `grouping.go`, `schedule.go`, `drafting.go`, `api.go` (`triggerInput.EventType`, `triggerView.EventType`, `proposedTrigger.EventType`, the `type` query parameter on the events list, `eventView.Type`, and the `body.event_type` error locations in `checkEventType`). - `modules/proposals/trigger.go` and `modules/proposals/api.go`: the `EventType` fields carried from a group into a trigger proposal and its JSON (`event_type`). Rename the Go fields to `DeclaredEventType` and the JSON fields and query parameter to `declared_event_type`, so the API carries the same distinction. Then run `task openapi:generate` and update the dashboard callers: `ui/src/lib/api.ts`, `ui/src/events/trigger.ts`, `ui/src/events/TriggerList.vue`, `ui/src/workflows/use-workflow-list.ts`, `ui/src/proposals/ProposalPage.vue`. Check `ui/src/captures/state.ts` and `ui/src/captures/event-types.ts`: their `event_type` is the capture view's event type id (`modules/events/api_capture.go`, `captureView.EventType`) and should become `event_type_id` for the same reason. ## Done when - No column, Go field or JSON field named `event_type` or `type` holds a declared kind; every one is `declared_event_type`. - `events.event_types` is referenced only through `event_type_id`, and its name is read from `events.event_types` when shown. - `task check` passes.
sam added the bugmedium labels 2026-11-23 13:13:56 +00:00
sam changed title from Event types are referenced by name next to their ID to Rename declared event type columns to avoid confusion with event_types 2026-11-23 19:54:33 +00:00
Author
Owner

Landed in 1c10378a4. Verified with task check and against a throwaway PostgreSQL 18 instance (baseline migrations 00001-00012, source + event type + trigger with declared_event_type and body.declared_event_type error location, events_schedule_slot partial unique index on schedule.tick, capture view event_type_id, and /api/events?declared_event_type filter).

Landed in 1c10378a4. Verified with task check and against a throwaway PostgreSQL 18 instance (baseline migrations 00001-00012, source + event type + trigger with declared_event_type and body.declared_event_type error location, events_schedule_slot partial unique index on schedule.tick, capture view event_type_id, and /api/events?declared_event_type filter).
sam closed this issue 2026-11-23 19:54:35 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sam/archie#2128