Adds `organization_id` (FK to `organizations`, `ON DELETE RESTRICT`) and `organization_source` (new enum: `workspace`, `chatd`, `effective_group`) to `aibridge_interceptions`, with a check constraint that keeps them set or unset together. Cost and pricing run later, in `RecordTokenUsage`, so they need the organization that AIGOV-716a resolves once per request stored on the interception row. `RecordInterceptionRequest` gains `organization_id` (18) and `organization_source` (19), and the aibridged API moves to v1.5. `RecordInterception` stores a valid pair; any other combination is logged as a warning and stored as NULLs, so a gateway bug never turns into an HTTP 500 for the user. A well-formed ID for an organization that does not exist fails on the FK, like an unknown `initiator_id`. Nothing sends the fields yet, so behaviour is unchanged until AIGOV-716a. **Malformed values are stored as empty, not rejected.** A failed `RecordInterception` returns HTTP 500 to the user, so the server logs a warning and stores NULLs instead. The one exception is a well-formed ID for an organization that does not exist: the foreign key rejects it, the same as an unknown `initiator_id` today. Part of AIGOV-712 *This PR was generated by Coder Agents on behalf of @SasSwart.*
7 lines
254 B
SQL
7 lines
254 B
SQL
DROP INDEX IF EXISTS idx_aibridge_interceptions_organization_id;
|
|
|
|
ALTER TABLE aibridge_interceptions
|
|
DROP COLUMN IF EXISTS organization_source,
|
|
DROP COLUMN IF EXISTS organization_id;
|
|
DROP TYPE IF EXISTS aibridge_interception_organization_source;
|