Add flowTriggers field to catalog item consumer

What does this MR do and why?

This is the backend half of a two-part change, split for GraphQL multiversion compatibility (Danger flagged the original combined MR).

A configured flow can have more than one trigger, but AiCatalogItemConsumer only exposed a singular flowTrigger field. Its batch loader called loader.call(consumerId, trigger) in a loop, so when a consumer had several triggers, each call overwrote the previous one and only one survived.

This MR adds a flowTriggers list field that returns every trigger for the consumer, ordered by id (via a new ordered_by_id scope so the order is deterministic). The singular flowTrigger field is kept but deprecated, so the current frontend on master keeps working until the follow-up frontend MR migrates and removes it.

This MR is purely additive and safe to deploy on its own.

References

Follow-up frontend MR (targets this branch): !249631 (merged)

No related issue. A reviewer is being asked to confirm whether multiple triggers per flow is intended behavior.

Database review

This MR adds one scope, Ai::FlowTrigger.ordered_by_id, used together with the existing by_item_consumer_ids scope in the flowTriggers GraphQL batch loader.

Query:

SELECT "ai_flow_triggers".*
FROM "ai_flow_triggers"
WHERE "ai_flow_triggers"."ai_catalog_item_consumer_id" IN (1, 2, 3)
ORDER BY "ai_flow_triggers"."id" ASC;

The IN (...) list holds the item-consumer ids batched in a single GraphQL request. ai_catalog_item_consumer_id is already covered by the non-unique index index_ai_flow_triggers_on_ai_catalog_item_consumer_id; id is the primary key.

Execution plan (local dev DB):

Sort  (cost=6.33..6.35 rows=6 width=176)
  Sort Key: id
  ->  Index Scan using index_ai_flow_triggers_on_ai_catalog_item_consumer_id on ai_flow_triggers  (cost=0.15..6.25 rows=6 width=176)
        Index Cond: (ai_catalog_item_consumer_id = ANY ('{1,2,3}'::bigint[]))

No migration or schema change. No new index required.

How to set up and validate locally

  1. In the GraphQL explorer, query an aiCatalogItem's configurationForProject { flowTriggers { id eventTypes } }.
  2. Configure a flow with more than one trigger and confirm all triggers are returned, ordered by id.

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist.

Edited by Austin Regnery

Merge request reports

Loading
Loading