Files
Memoh/db/queries/provider_oauth.sql
Acbox a04b8fd564 refactor: unify providers and models tables
- Rename `llm_providers` → `providers`, `llm_provider_oauth_tokens` → `provider_oauth_tokens`
- Remove `tts_providers` and `tts_models` tables; speech models now live in the unified `models` table with `type = 'speech'`
- Replace top-level `api_key`/`base_url` columns with a JSONB `config` field on `providers`
- Rename `llm_provider_id` → `provider_id` across all references
- Add `edge-speech` client type and `conf/providers/edge.yaml` default provider
- Create new read-only speech endpoints (`/speech-providers`, `/speech-models`) backed by filtered views of the unified tables
- Remove old TTS CRUD handlers; simplify speech page to read-only + test
- Update registry loader to skip malformed YAML files instead of failing entirely
- Fix YAML quoting for model names containing colons in openrouter.yaml
- Regenerate sqlc, swagger, and TypeScript SDK
2026-04-07 00:26:06 +08:00

53 lines
1.4 KiB
SQL

-- name: UpsertProviderOAuthToken :one
INSERT INTO provider_oauth_tokens (
provider_id,
access_token,
refresh_token,
expires_at,
scope,
token_type,
state,
pkce_code_verifier
)
VALUES (
sqlc.arg(provider_id),
sqlc.arg(access_token),
sqlc.arg(refresh_token),
sqlc.arg(expires_at),
sqlc.arg(scope),
sqlc.arg(token_type),
sqlc.arg(state),
sqlc.arg(pkce_code_verifier)
)
ON CONFLICT (provider_id) DO UPDATE SET
access_token = EXCLUDED.access_token,
refresh_token = EXCLUDED.refresh_token,
expires_at = EXCLUDED.expires_at,
scope = EXCLUDED.scope,
token_type = EXCLUDED.token_type,
state = EXCLUDED.state,
pkce_code_verifier = EXCLUDED.pkce_code_verifier,
updated_at = now()
RETURNING *;
-- name: GetProviderOAuthTokenByProvider :one
SELECT * FROM provider_oauth_tokens WHERE provider_id = sqlc.arg(provider_id);
-- name: GetProviderOAuthTokenByState :one
SELECT * FROM provider_oauth_tokens WHERE state = sqlc.arg(state) AND state != '';
-- name: UpdateProviderOAuthState :exec
INSERT INTO provider_oauth_tokens (provider_id, state, pkce_code_verifier)
VALUES (
sqlc.arg(provider_id),
sqlc.arg(state),
sqlc.arg(pkce_code_verifier)
)
ON CONFLICT (provider_id) DO UPDATE SET
state = EXCLUDED.state,
pkce_code_verifier = EXCLUDED.pkce_code_verifier,
updated_at = now();
-- name: DeleteProviderOAuthToken :exec
DELETE FROM provider_oauth_tokens WHERE provider_id = sqlc.arg(provider_id);