refactor: drop chat_model_configs provider column (#26877)

The provider type already lives authoritatively in ai_providers.type,
reachable on every active row through ai_provider_id, which the
chat_model_configs_ai_provider_required_when_active CHECK makes
mandatory. The stored provider string was a denormalized copy the system
kept in sync with a startup backfill and no longer needs.

Every surface now derives provider type from the linked ai_providers
row. Telemetry is the one exception: it keeps emitting provider, now
sourced from ai_providers.type via a JOIN, so the BigQuery column and the
Nexus dashboards that read it are unaffected. The experimental HTTP/SDK
response drops provider and makes ai_provider_id required, since those
endpoints return only active configs; consumers resolve provider type
from ai_provider_id and the AI providers listing.

This ships in a single release with no compatibility window: production
reads the table via SELECT *, so a pre-drop binary fails config reads the
moment the column is gone. Operators must scale to zero before upgrading,
and there is no rollback.

Closes CODAGT-599
This commit is contained in:
Mathias Fredriksson
2026-07-01 15:59:55 +03:00
committed by GitHub
parent cf75dd0f46
commit 047c47495b
92 changed files with 1072 additions and 1197 deletions
+12 -44
View File
@@ -18,20 +18,23 @@ WHERE
-- name: GetChatModelConfigs :many
SELECT
*
cmc.*
FROM
chat_model_configs
chat_model_configs cmc
LEFT JOIN
ai_providers ap ON ap.id = cmc.ai_provider_id
WHERE
deleted = FALSE
cmc.deleted = FALSE
ORDER BY
provider ASC,
model ASC,
updated_at DESC,
id DESC;
ap.type::text ASC,
cmc.model ASC,
cmc.updated_at DESC,
cmc.id DESC;
-- name: GetEnabledChatModelConfigs :many
SELECT
cmc.*
sqlc.embed(cmc),
ap.type::text AS provider
FROM
chat_model_configs cmc
JOIN
@@ -42,7 +45,7 @@ WHERE
AND ap.enabled = TRUE
AND ap.deleted = FALSE
ORDER BY
cmc.provider ASC,
ap.type::text ASC,
cmc.model ASC,
cmc.updated_at DESC,
cmc.id DESC;
@@ -65,7 +68,6 @@ WHERE
-- name: InsertChatModelConfig :one
INSERT INTO chat_model_configs (
provider,
model,
display_name,
created_by,
@@ -77,7 +79,6 @@ INSERT INTO chat_model_configs (
options,
ai_provider_id
) VALUES (
@provider::text,
@model::text,
@display_name::text,
sqlc.narg('created_by')::uuid,
@@ -96,7 +97,6 @@ RETURNING
UPDATE
chat_model_configs
SET
provider = @provider::text,
model = @model::text,
display_name = @display_name::text,
updated_by = sqlc.narg('updated_by')::uuid,
@@ -133,38 +133,6 @@ SET
WHERE
id = @id::uuid;
-- name: DeleteChatModelConfigsByProvider :exec
UPDATE
chat_model_configs
SET
deleted = TRUE,
deleted_at = NOW(),
updated_at = NOW()
WHERE
provider = @provider::text
AND deleted = FALSE;
-- name: BackfillChatModelConfigProvider :execresult
-- old_provider is matched as text; new_provider is also cast to ai_provider_type
-- for the EXISTS check against ai_providers.type.
-- ai_provider_id IS NOT NULL is defensive; the check constraint already
-- enforces that non-deleted rows always have a provider ID.
UPDATE
chat_model_configs
SET
provider = @new_provider::text,
updated_at = NOW()
WHERE
provider = @old_provider::text
AND deleted = FALSE
AND ai_provider_id IS NOT NULL
AND EXISTS (
SELECT 1 FROM ai_providers
WHERE id = chat_model_configs.ai_provider_id
AND type = @new_provider::ai_provider_type
AND deleted = FALSE
);
-- name: DeleteChatModelConfigsByAIProviderID :exec
UPDATE
chat_model_configs