Prepare schema for group-level AI catalog item enablement

What does this MR do and why?

Part of the AI Catalog group inheritance epic: a group enables an agent or flow once, and every project under it inherits that enablement. ai_catalog_item_consumers only holds direct enablements today.

This MR adds the schema. A kind column on ai_catalog_item_consumers marks a row as direct (0) or group inheritance (1). The Rails enum comes in the models MR. The default stays 0 on purpose: nothing sets kind yet, so dropping it now would break inserts between deploys. Removing it is tracked in a separate issue.

The kind: 1 row is the group's own row. Projects under that group inherit from it without getting rows of their own. Existing rows that use parent_item_consumer_id, from the earlier bulk-enablement approach, stay kind: 0.

Flow triggers always belong to a project, but an inheritance record needs to belong to a group. So ai_flow_triggers gets a nullable group_id with an index and FK to namespaces, project_id becomes nullable, and a check constraint makes sure exactly one of the two is set. That constraint is required by the sharding key spec once the table has two sharding keys.

Schema only here, no model, validation, or factory changes.

References

#627506 (closed)

How to set up and validate locally

Ai::Catalog::ItemConsumer.where(kind: 1).count # => 0
Ai::Catalog::ItemConsumer.where(kind: 0).count # => Total number of ItemConusmers in your GDK
Ai::FlowTrigger.where(project_id: nil).count # => 0
Enable a catalog item and create a trigger

These flows insert into ai_catalog_item_consumers and ai_flow_triggers. They should keep working exactly as before, with kind defaulting to 0 and project_id still set on every trigger.

Enable an AI catalog item on a project

  1. Go to http://gdk.test:3000/explore/ai-catalog/agents and open any agent, or use /explore/ai-catalog/flows for a flow.

  2. Select Enable and pick a project you have Maintainer or Owner access to.

  3. Go to the project, then Automate > Agents (or Flows). The item should be listed as enabled.

  4. Check the new row in bundle exec rails c:

    consumer = Ai::Catalog::ItemConsumer.last
    consumer.kind
    # => 0
    consumer.project_id.present?
    # => true

Create a flow trigger

  1. In the same project go to Automate > Triggers and select New trigger.

  2. Pick the flow you enabled above, choose an event such as Mention, fill in a description, and save.

  3. The trigger should appear in the list. Check the row:

    trigger = Ai::FlowTrigger.last
    trigger.project_id.present?
    # => true
    trigger.group_id
    # => nil

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #627506 (closed)

Edited by Jaydip Pansuriya

Merge request reports

Loading
Loading