fix: sync canonical schema with 0061 migration to fix sqlc column mismatch

0001_init.up.sql still used old names (llm_providers, llm_provider_id)
and included dropped tts_providers/tts_models tables. sqlc could not
parse the PL/pgSQL EXECUTE in migration 0061, so generated code retained
stale columns (input_modalities, supports_reasoning) causing runtime
"column does not exist" errors when adding models.

- Update 0001_init.up.sql to current schema (providers, provider_id,
  no tts tables, add provider_oauth_tokens)
- Use ALTER TABLE IF EXISTS in 0010/0041/0042 for backward compat
- Regenerate sqlc
This commit is contained in:
Acbox
2026-04-08 00:45:06 +08:00
parent b71df81d5c
commit 889b6dbaa4
6 changed files with 109 additions and 126 deletions
+36 -76
View File
@@ -53,7 +53,7 @@ VALUES (
$4,
$5
)
RETURNING id, model_id, name, provider_id, type, config, created_at, updated_at, input_modalities, supports_reasoning
RETURNING id, model_id, name, provider_id, type, config, created_at, updated_at
`
type CreateModelParams struct {
@@ -82,8 +82,6 @@ func (q *Queries) CreateModel(ctx context.Context, arg CreateModelParams) (Model
&i.Config,
&i.CreatedAt,
&i.UpdatedAt,
&i.InputModalities,
&i.SupportsReasoning,
)
return i, err
}
@@ -200,7 +198,7 @@ func (q *Queries) DeleteProvider(ctx context.Context, id pgtype.UUID) error {
}
const getModelByID = `-- name: GetModelByID :one
SELECT id, model_id, name, provider_id, type, config, created_at, updated_at, input_modalities, supports_reasoning FROM models WHERE id = $1
SELECT id, model_id, name, provider_id, type, config, created_at, updated_at FROM models WHERE id = $1
`
func (q *Queries) GetModelByID(ctx context.Context, id pgtype.UUID) (Model, error) {
@@ -215,14 +213,12 @@ func (q *Queries) GetModelByID(ctx context.Context, id pgtype.UUID) (Model, erro
&i.Config,
&i.CreatedAt,
&i.UpdatedAt,
&i.InputModalities,
&i.SupportsReasoning,
)
return i, err
}
const getModelByModelID = `-- name: GetModelByModelID :one
SELECT id, model_id, name, provider_id, type, config, created_at, updated_at, input_modalities, supports_reasoning FROM models WHERE model_id = $1
SELECT id, model_id, name, provider_id, type, config, created_at, updated_at FROM models WHERE model_id = $1
`
func (q *Queries) GetModelByModelID(ctx context.Context, modelID string) (Model, error) {
@@ -237,14 +233,12 @@ func (q *Queries) GetModelByModelID(ctx context.Context, modelID string) (Model,
&i.Config,
&i.CreatedAt,
&i.UpdatedAt,
&i.InputModalities,
&i.SupportsReasoning,
)
return i, err
}
const getModelByProviderAndModelID = `-- name: GetModelByProviderAndModelID :one
SELECT id, model_id, name, provider_id, type, config, created_at, updated_at, input_modalities, supports_reasoning FROM models
SELECT id, model_id, name, provider_id, type, config, created_at, updated_at FROM models
WHERE provider_id = $1
AND model_id = $2
LIMIT 1
@@ -267,8 +261,6 @@ func (q *Queries) GetModelByProviderAndModelID(ctx context.Context, arg GetModel
&i.Config,
&i.CreatedAt,
&i.UpdatedAt,
&i.InputModalities,
&i.SupportsReasoning,
)
return i, err
}
@@ -317,7 +309,7 @@ func (q *Queries) GetProviderByName(ctx context.Context, name string) (Provider,
const getSpeechModelWithProvider = `-- name: GetSpeechModelWithProvider :one
SELECT
m.id, m.model_id, m.name, m.provider_id, m.type, m.config, m.created_at, m.updated_at, m.input_modalities, m.supports_reasoning,
m.id, m.model_id, m.name, m.provider_id, m.type, m.config, m.created_at, m.updated_at,
p.client_type AS provider_type
FROM models m
JOIN providers p ON p.id = m.provider_id
@@ -326,17 +318,15 @@ WHERE m.id = $1
`
type GetSpeechModelWithProviderRow struct {
ID pgtype.UUID `json:"id"`
ModelID string `json:"model_id"`
Name pgtype.Text `json:"name"`
ProviderID pgtype.UUID `json:"provider_id"`
Type string `json:"type"`
Config []byte `json:"config"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
InputModalities []string `json:"input_modalities"`
SupportsReasoning bool `json:"supports_reasoning"`
ProviderType string `json:"provider_type"`
ID pgtype.UUID `json:"id"`
ModelID string `json:"model_id"`
Name pgtype.Text `json:"name"`
ProviderID pgtype.UUID `json:"provider_id"`
Type string `json:"type"`
Config []byte `json:"config"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
ProviderType string `json:"provider_type"`
}
func (q *Queries) GetSpeechModelWithProvider(ctx context.Context, id pgtype.UUID) (GetSpeechModelWithProviderRow, error) {
@@ -351,15 +341,13 @@ func (q *Queries) GetSpeechModelWithProvider(ctx context.Context, id pgtype.UUID
&i.Config,
&i.CreatedAt,
&i.UpdatedAt,
&i.InputModalities,
&i.SupportsReasoning,
&i.ProviderType,
)
return i, err
}
const listEnabledModels = `-- name: ListEnabledModels :many
SELECT m.id, m.model_id, m.name, m.provider_id, m.type, m.config, m.created_at, m.updated_at, m.input_modalities, m.supports_reasoning
SELECT m.id, m.model_id, m.name, m.provider_id, m.type, m.config, m.created_at, m.updated_at
FROM models m
JOIN providers p ON m.provider_id = p.id
WHERE p.enable = true
@@ -384,8 +372,6 @@ func (q *Queries) ListEnabledModels(ctx context.Context) ([]Model, error) {
&i.Config,
&i.CreatedAt,
&i.UpdatedAt,
&i.InputModalities,
&i.SupportsReasoning,
); err != nil {
return nil, err
}
@@ -398,7 +384,7 @@ func (q *Queries) ListEnabledModels(ctx context.Context) ([]Model, error) {
}
const listEnabledModelsByProviderClientType = `-- name: ListEnabledModelsByProviderClientType :many
SELECT m.id, m.model_id, m.name, m.provider_id, m.type, m.config, m.created_at, m.updated_at, m.input_modalities, m.supports_reasoning
SELECT m.id, m.model_id, m.name, m.provider_id, m.type, m.config, m.created_at, m.updated_at
FROM models m
JOIN providers p ON m.provider_id = p.id
WHERE p.enable = true
@@ -424,8 +410,6 @@ func (q *Queries) ListEnabledModelsByProviderClientType(ctx context.Context, cli
&i.Config,
&i.CreatedAt,
&i.UpdatedAt,
&i.InputModalities,
&i.SupportsReasoning,
); err != nil {
return nil, err
}
@@ -438,7 +422,7 @@ func (q *Queries) ListEnabledModelsByProviderClientType(ctx context.Context, cli
}
const listEnabledModelsByType = `-- name: ListEnabledModelsByType :many
SELECT m.id, m.model_id, m.name, m.provider_id, m.type, m.config, m.created_at, m.updated_at, m.input_modalities, m.supports_reasoning
SELECT m.id, m.model_id, m.name, m.provider_id, m.type, m.config, m.created_at, m.updated_at
FROM models m
JOIN providers p ON m.provider_id = p.id
WHERE p.enable = true
@@ -464,8 +448,6 @@ func (q *Queries) ListEnabledModelsByType(ctx context.Context, type_ string) ([]
&i.Config,
&i.CreatedAt,
&i.UpdatedAt,
&i.InputModalities,
&i.SupportsReasoning,
); err != nil {
return nil, err
}
@@ -512,7 +494,7 @@ func (q *Queries) ListModelVariantsByModelUUID(ctx context.Context, modelUuid pg
}
const listModels = `-- name: ListModels :many
SELECT id, model_id, name, provider_id, type, config, created_at, updated_at, input_modalities, supports_reasoning FROM models
SELECT id, model_id, name, provider_id, type, config, created_at, updated_at FROM models
ORDER BY created_at DESC
`
@@ -534,8 +516,6 @@ func (q *Queries) ListModels(ctx context.Context) ([]Model, error) {
&i.Config,
&i.CreatedAt,
&i.UpdatedAt,
&i.InputModalities,
&i.SupportsReasoning,
); err != nil {
return nil, err
}
@@ -548,7 +528,7 @@ func (q *Queries) ListModels(ctx context.Context) ([]Model, error) {
}
const listModelsByModelID = `-- name: ListModelsByModelID :many
SELECT id, model_id, name, provider_id, type, config, created_at, updated_at, input_modalities, supports_reasoning FROM models
SELECT id, model_id, name, provider_id, type, config, created_at, updated_at FROM models
WHERE model_id = $1
ORDER BY created_at DESC
`
@@ -571,8 +551,6 @@ func (q *Queries) ListModelsByModelID(ctx context.Context, modelID string) ([]Mo
&i.Config,
&i.CreatedAt,
&i.UpdatedAt,
&i.InputModalities,
&i.SupportsReasoning,
); err != nil {
return nil, err
}
@@ -585,7 +563,7 @@ func (q *Queries) ListModelsByModelID(ctx context.Context, modelID string) ([]Mo
}
const listModelsByProviderClientType = `-- name: ListModelsByProviderClientType :many
SELECT m.id, m.model_id, m.name, m.provider_id, m.type, m.config, m.created_at, m.updated_at, m.input_modalities, m.supports_reasoning
SELECT m.id, m.model_id, m.name, m.provider_id, m.type, m.config, m.created_at, m.updated_at
FROM models m
JOIN providers p ON m.provider_id = p.id
WHERE p.client_type = $1
@@ -610,8 +588,6 @@ func (q *Queries) ListModelsByProviderClientType(ctx context.Context, clientType
&i.Config,
&i.CreatedAt,
&i.UpdatedAt,
&i.InputModalities,
&i.SupportsReasoning,
); err != nil {
return nil, err
}
@@ -624,7 +600,7 @@ func (q *Queries) ListModelsByProviderClientType(ctx context.Context, clientType
}
const listModelsByProviderID = `-- name: ListModelsByProviderID :many
SELECT id, model_id, name, provider_id, type, config, created_at, updated_at, input_modalities, supports_reasoning FROM models
SELECT id, model_id, name, provider_id, type, config, created_at, updated_at FROM models
WHERE provider_id = $1
ORDER BY created_at DESC
`
@@ -647,8 +623,6 @@ func (q *Queries) ListModelsByProviderID(ctx context.Context, providerID pgtype.
&i.Config,
&i.CreatedAt,
&i.UpdatedAt,
&i.InputModalities,
&i.SupportsReasoning,
); err != nil {
return nil, err
}
@@ -661,7 +635,7 @@ func (q *Queries) ListModelsByProviderID(ctx context.Context, providerID pgtype.
}
const listModelsByProviderIDAndType = `-- name: ListModelsByProviderIDAndType :many
SELECT id, model_id, name, provider_id, type, config, created_at, updated_at, input_modalities, supports_reasoning FROM models
SELECT id, model_id, name, provider_id, type, config, created_at, updated_at FROM models
WHERE provider_id = $1
AND type = $2
ORDER BY created_at DESC
@@ -690,8 +664,6 @@ func (q *Queries) ListModelsByProviderIDAndType(ctx context.Context, arg ListMod
&i.Config,
&i.CreatedAt,
&i.UpdatedAt,
&i.InputModalities,
&i.SupportsReasoning,
); err != nil {
return nil, err
}
@@ -704,7 +676,7 @@ func (q *Queries) ListModelsByProviderIDAndType(ctx context.Context, arg ListMod
}
const listModelsByType = `-- name: ListModelsByType :many
SELECT id, model_id, name, provider_id, type, config, created_at, updated_at, input_modalities, supports_reasoning FROM models
SELECT id, model_id, name, provider_id, type, config, created_at, updated_at FROM models
WHERE type = $1
ORDER BY created_at DESC
`
@@ -727,8 +699,6 @@ func (q *Queries) ListModelsByType(ctx context.Context, type_ string) ([]Model,
&i.Config,
&i.CreatedAt,
&i.UpdatedAt,
&i.InputModalities,
&i.SupportsReasoning,
); err != nil {
return nil, err
}
@@ -777,7 +747,7 @@ func (q *Queries) ListProviders(ctx context.Context) ([]Provider, error) {
}
const listSpeechModels = `-- name: ListSpeechModels :many
SELECT m.id, m.model_id, m.name, m.provider_id, m.type, m.config, m.created_at, m.updated_at, m.input_modalities, m.supports_reasoning,
SELECT m.id, m.model_id, m.name, m.provider_id, m.type, m.config, m.created_at, m.updated_at,
p.client_type AS provider_type
FROM models m
JOIN providers p ON p.id = m.provider_id
@@ -786,17 +756,15 @@ ORDER BY m.created_at DESC
`
type ListSpeechModelsRow struct {
ID pgtype.UUID `json:"id"`
ModelID string `json:"model_id"`
Name pgtype.Text `json:"name"`
ProviderID pgtype.UUID `json:"provider_id"`
Type string `json:"type"`
Config []byte `json:"config"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
InputModalities []string `json:"input_modalities"`
SupportsReasoning bool `json:"supports_reasoning"`
ProviderType string `json:"provider_type"`
ID pgtype.UUID `json:"id"`
ModelID string `json:"model_id"`
Name pgtype.Text `json:"name"`
ProviderID pgtype.UUID `json:"provider_id"`
Type string `json:"type"`
Config []byte `json:"config"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
ProviderType string `json:"provider_type"`
}
func (q *Queries) ListSpeechModels(ctx context.Context) ([]ListSpeechModelsRow, error) {
@@ -817,8 +785,6 @@ func (q *Queries) ListSpeechModels(ctx context.Context) ([]ListSpeechModelsRow,
&i.Config,
&i.CreatedAt,
&i.UpdatedAt,
&i.InputModalities,
&i.SupportsReasoning,
&i.ProviderType,
); err != nil {
return nil, err
@@ -832,7 +798,7 @@ func (q *Queries) ListSpeechModels(ctx context.Context) ([]ListSpeechModelsRow,
}
const listSpeechModelsByProviderID = `-- name: ListSpeechModelsByProviderID :many
SELECT id, model_id, name, provider_id, type, config, created_at, updated_at, input_modalities, supports_reasoning FROM models
SELECT id, model_id, name, provider_id, type, config, created_at, updated_at FROM models
WHERE provider_id = $1
AND type = 'speech'
ORDER BY created_at DESC
@@ -856,8 +822,6 @@ func (q *Queries) ListSpeechModelsByProviderID(ctx context.Context, providerID p
&i.Config,
&i.CreatedAt,
&i.UpdatedAt,
&i.InputModalities,
&i.SupportsReasoning,
); err != nil {
return nil, err
}
@@ -915,7 +879,7 @@ SET
config = $5,
updated_at = now()
WHERE id = $6
RETURNING id, model_id, name, provider_id, type, config, created_at, updated_at, input_modalities, supports_reasoning
RETURNING id, model_id, name, provider_id, type, config, created_at, updated_at
`
type UpdateModelParams struct {
@@ -946,8 +910,6 @@ func (q *Queries) UpdateModel(ctx context.Context, arg UpdateModelParams) (Model
&i.Config,
&i.CreatedAt,
&i.UpdatedAt,
&i.InputModalities,
&i.SupportsReasoning,
)
return i, err
}
@@ -1009,7 +971,7 @@ ON CONFLICT (provider_id, model_id) DO UPDATE SET
type = EXCLUDED.type,
config = EXCLUDED.config,
updated_at = now()
RETURNING id, model_id, name, provider_id, type, config, created_at, updated_at, input_modalities, supports_reasoning
RETURNING id, model_id, name, provider_id, type, config, created_at, updated_at
`
type UpsertRegistryModelParams struct {
@@ -1038,8 +1000,6 @@ func (q *Queries) UpsertRegistryModel(ctx context.Context, arg UpsertRegistryMod
&i.Config,
&i.CreatedAt,
&i.UpdatedAt,
&i.InputModalities,
&i.SupportsReasoning,
)
return i, err
}