Skip to content

refactor(ai-gateway): stop writing obsolete models_by_provider table#2818

Open
kilo-code-bot[bot] wants to merge 2 commits intomainfrom
remove-models-by-provider-sql-writes
Open

refactor(ai-gateway): stop writing obsolete models_by_provider table#2818
kilo-code-bot[bot] wants to merge 2 commits intomainfrom
remove-models-by-provider-sql-writes

Conversation

@kilo-code-bot
Copy link
Copy Markdown
Contributor

@kilo-code-bot kilo-code-bot Bot commented Apr 25, 2026

Summary

  • The models_by_provider SQL table has been fully superseded by Redis storage (GATEWAY_METADATA_REDIS_KEYS). This PR removes the last runtime code that still wrote to or read from it.
  • syncAndStoreProviders no longer opens a DB transaction; it only mirrors to Redis.
  • The /api/openrouter/models-by-provider route and models-by-provider-index.server.ts loader now read the snapshot from Redis (allProviders key) instead of Postgres.
  • The Drizzle schema entry is kept (so the schema still matches the live DB) but annotated as obsolete with a JSDoc comment; the table can be dropped in a follow-up migration.

Verification

  • Admin Sync Providers page triggers a sync and reports generated_at / totals from the Redis-backed result.
  • /api/openrouter/models-by-provider and org defaults lookups resolve via Redis.

Visual Changes

N/A — admin page drops the "Row ID" line since there is no SQL row anymore.

Reviewer Notes

  • No migration in this PR. A future PR can DROP TABLE models_by_provider once we're confident nothing external depends on it.
  • MODELS_BY_PROVIDER_ADMIN_URL is retained because other code (byok-router, this route's error message) still references it as the admin panel link.

The canonical storage is now Redis; the SQL table is no longer read or
written by any runtime code. Mark the Drizzle schema entry as obsolete
and repoint the remaining readers at the existing Redis keys.
return results[0];
});

await mirrorToRedis({
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: Sync can silently succeed without storing a snapshot

redisSet() returns false when REDIS_URL is unset, and mirrorToRedis() ignores those return values. Now that the SQL write is gone, this mutation can report success while persisting nothing, which leaves /api/openrouter/models-by-provider and the Redis-backed readers with no data immediately afterward. Consider failing the sync when any Redis write returns false, or keeping the existing SQL fallback until Redis is guaranteed in every environment.

@kilo-code-bot
Copy link
Copy Markdown
Contributor Author

kilo-code-bot Bot commented Apr 25, 2026

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (5 files)
  • apps/web/src/app/admin/sync-providers/SyncProvidersContent.tsx
  • apps/web/src/app/api/openrouter/models-by-provider/route.ts
  • apps/web/src/lib/ai-gateway/providers/openrouter/models-by-provider-index.server.ts
  • apps/web/src/lib/ai-gateway/providers/openrouter/sync-providers.ts
  • packages/db/src/schema.ts

Reviewed by gpt-5.4-20260305 · 367,014 tokens

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