Skip to content

SQUARE-23-Insight-AI-one-per-customer - #1141

Merged
pchero merged 11 commits into
mainfrom
SQUARE-23-Insight-AI-one-per-customer
Jul 28, 2026
Merged

SQUARE-23-Insight-AI-one-per-customer#1141
pchero merged 11 commits into
mainfrom
SQUARE-23-Insight-AI-one-per-customer

Conversation

@pchero

@pchero pchero commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Enforces at most one active (non-deleted) type=insight AI per customer at the DB level, with a clear 409 API error on violation, per SQUARE-23. A generated column plus unique index on ai_ais mirrors the existing ai_aicalls.active_reference_key precedent (VOIP-1234); aihandler translates the resulting duplicate-key error into cerrors.AlreadyExists across every reachable Create/Update path.

  • bin-ai-manager: Add active_insight_key SQLite test-schema stand-in and regression test for one-insight-AI-per-customer
  • bin-ai-manager: Translate ai_ais duplicate-key error into AI_INSIGHT_ALREADY_EXISTS (409) in Create
  • bin-ai-manager: Translate ai_ais duplicate-key error into AI_INSIGHT_ALREADY_EXISTS (409) in all three Update branches
  • bin-ai-manager: Extract shared aiInsightDuplicateErr helper for AI_INSIGHT_ALREADY_EXISTS translation, eliminating 4-way duplication
  • bin-dbscheme-manager: Add ai_ais.active_insight_key migration enforcing one active Insight AI per customer

Migration is not applied to any shared environment by this PR. Before it is applied, customers with 2+ existing active Insight AIs must be identified via a read-only audit query and resolved (default proposal: keep the most recently created, matching square-admin's existing fallback) via the existing DELETE /ais/{id} API — see docs/plans/2026-07-29-insight-ai-one-per-customer-design.md section 3 for the full audit/cleanup approach.

pchero added 11 commits July 29, 2026 03:07
- bin-ai-manager: Add design doc for enforcing one active type=insight AI per customer
- bin-ai-manager: Address design review feedback
- bin-ai-manager: Address design review feedback
- bin-ai-manager: Address design review feedback
- bin-ai-manager: Add implementation plan for one-insight-AI-per-customer constraint
- bin-ai-manager: Address implementation plan review feedback
- bin-ai-manager: Add active_insight_key SQLite test-schema stand-in and regression test for one-insight-AI-per-customer
- bin-dbscheme-manager: Add ai_ais.active_insight_key migration enforcing one active Insight AI per customer
- bin-ai-manager: Translate ai_ais duplicate-key error into AI_INSIGHT_ALREADY_EXISTS (409) in Create
- bin-ai-manager: Translate ai_ais duplicate-key error into AI_INSIGHT_ALREADY_EXISTS (409) in all three Update branches
- bin-ai-manager: Extract shared helper for AI_INSIGHT_ALREADY_EXISTS translation, eliminating 4-way duplication
@pchero
pchero merged commit d7c7429 into main Jul 28, 2026
3 of 4 checks passed
@pchero
pchero deleted the SQUARE-23-Insight-AI-one-per-customer branch July 28, 2026 20:00
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