mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix: only write AI model prices that changed (#27923)
Previously, the AI Gateway price seeder rewrote every row of `ai_model_prices` on each server start, because `ON CONFLICT` fires on a key conflict rather than on a value difference. `updated_at` therefore recorded when the server last restarted rather than when a price last changed. Guard the `DO UPDATE` branch so a conflicting row is only rewritten when one of its four prices differs. The comparison uses `IS DISTINCT FROM` rather than `<>` because the price columns are nullable, and `<>` yields NULL when either side is NULL, which would skip the update and leave a stale price in place. Related to https://linear.app/codercom/issue/AIGOV-567/experimental-cli-command-to-set-prices-for-unpriced-ai-models > [!NOTE] > Initially generated by Claude Opus 5, modified and reviewed by @ssncferreira
This commit is contained in:
Generated
+3
@@ -1611,6 +1611,9 @@ type sqlcQuerier interface {
|
||||
// Upsert a batch of (provider, model) rows from a JSON array. Each element
|
||||
// must have provider, model, and the four price fields; null prices are
|
||||
// written as SQL NULL.
|
||||
// A conflicting row is only rewritten when a price differs, so updated_at
|
||||
// records when a price last changed. Prices are nullable and a NULL on
|
||||
// either side counts as a difference.
|
||||
UpsertAIModelPrices(ctx context.Context, seed json.RawMessage) error
|
||||
// Returns true if a new rows was inserted, false otherwise.
|
||||
UpsertAISeatState(ctx context.Context, arg UpsertAISeatStateParams) (bool, error)
|
||||
|
||||
Reference in New Issue
Block a user