Skip to content

Commit b49a816

Browse files
fix: database migrations, API methods, and label removal logic
1 parent 825e2f1 commit b49a816

5 files changed

Lines changed: 22 additions & 19 deletions

File tree

db/migrations/001_initial.sql

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ CREATE TABLE IF NOT EXISTS model_configs (
160160

161161
DELETE FROM model_configs WHERE model_id = '@cf/moonshotai/kimi-k2.5';
162162

163-
CREATE OR REPLACE FUNCTION public.codra_replace_deprecated_model(input jsonb, old_value text, new_value text)
163+
CREATE OR REPLACE FUNCTION pg_temp.codra_replace_deprecated_model(input jsonb, old_value text, new_value text)
164164
RETURNS jsonb
165165
LANGUAGE sql
166166
IMMUTABLE
@@ -169,14 +169,14 @@ AS $$
169169
WHEN 'string' THEN CASE WHEN input #>> '{}' = old_value THEN to_jsonb(new_value) ELSE input END
170170
WHEN 'array' THEN COALESCE(
171171
(
172-
SELECT jsonb_agg(public.codra_replace_deprecated_model(value, old_value, new_value) ORDER BY ord)
172+
SELECT jsonb_agg(pg_temp.codra_replace_deprecated_model(value, old_value, new_value) ORDER BY ord)
173173
FROM jsonb_array_elements(input) WITH ORDINALITY AS item(value, ord)
174174
),
175175
'[]'::jsonb
176176
)
177177
WHEN 'object' THEN COALESCE(
178178
(
179-
SELECT jsonb_object_agg(key, public.codra_replace_deprecated_model(value, old_value, new_value))
179+
SELECT jsonb_object_agg(key, pg_temp.codra_replace_deprecated_model(value, old_value, new_value))
180180
FROM jsonb_each(input)
181181
),
182182
'{}'::jsonb
@@ -190,22 +190,22 @@ SET
190190
main_model = CASE WHEN main_model = '@cf/moonshotai/kimi-k2.5' THEN '@cf/moonshotai/kimi-k2.6' ELSE main_model END,
191191
fallback_models = CASE
192192
WHEN fallback_models IS NULL THEN NULL
193-
ELSE public.codra_replace_deprecated_model(fallback_models, '@cf/moonshotai/kimi-k2.5', '@cf/moonshotai/kimi-k2.6')
193+
ELSE pg_temp.codra_replace_deprecated_model(fallback_models, '@cf/moonshotai/kimi-k2.5', '@cf/moonshotai/kimi-k2.6')
194194
END,
195195
size_overrides = CASE
196196
WHEN size_overrides IS NULL THEN NULL
197-
ELSE public.codra_replace_deprecated_model(size_overrides, '@cf/moonshotai/kimi-k2.5', '@cf/moonshotai/kimi-k2.6')
197+
ELSE pg_temp.codra_replace_deprecated_model(size_overrides, '@cf/moonshotai/kimi-k2.5', '@cf/moonshotai/kimi-k2.6')
198198
END,
199199
parsed_json = CASE
200200
WHEN parsed_json IS NULL THEN NULL
201-
ELSE public.codra_replace_deprecated_model(parsed_json, '@cf/moonshotai/kimi-k2.5', '@cf/moonshotai/kimi-k2.6')
201+
ELSE pg_temp.codra_replace_deprecated_model(parsed_json, '@cf/moonshotai/kimi-k2.5', '@cf/moonshotai/kimi-k2.6')
202202
END
203203
WHERE main_model = '@cf/moonshotai/kimi-k2.5'
204204
OR fallback_models::text LIKE '%@cf/moonshotai/kimi-k2.5%'
205205
OR size_overrides::text LIKE '%@cf/moonshotai/kimi-k2.5%'
206206
OR parsed_json::text LIKE '%@cf/moonshotai/kimi-k2.5%';
207207

208-
DROP FUNCTION IF EXISTS public.codra_replace_deprecated_model(jsonb, text, text);
208+
DROP FUNCTION IF EXISTS pg_temp.codra_replace_deprecated_model(jsonb, text, text);
209209

210210
DO $$
211211
DECLARE
@@ -281,6 +281,7 @@ BEGIN
281281
ALTER TABLE jobs ADD COLUMN IF NOT EXISTS repository_id INTEGER;
282282

283283
IF has_old_job_repo_columns THEN
284+
EXECUTE 'CREATE INDEX IF NOT EXISTS tmp_jobs_owner_repo_idx ON jobs(owner, repo)';
284285
EXECUTE '
285286
UPDATE jobs j
286287
SET repository_id = r.id
@@ -289,6 +290,7 @@ BEGIN
289290
AND r.owner = j.owner
290291
AND r.repo = j.repo
291292
';
293+
EXECUTE 'DROP INDEX tmp_jobs_owner_repo_idx';
292294
END IF;
293295

294296
SELECT data_type

scripts/migrate.mjs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ async function ensureModelCatalog() {
294294
OR (mc.provider = 'google' AND provider_record.name = 'Google')
295295
OR (mc.provider = 'openai' AND provider_record.name = 'OpenAI')
296296
OR (mc.provider = 'anthropic' AND provider_record.name = 'Anthropic')
297+
OR (mc.provider = 'openrouter' AND provider_record.name = 'OpenRouter')
297298
)
298299
`,
299300
);
@@ -401,7 +402,7 @@ async function normalizeRepoConfigs() {
401402
}
402403

403404
await query(`
404-
CREATE OR REPLACE FUNCTION public.codra_replace_deprecated_model(input jsonb, old_value text, new_value text)
405+
CREATE OR REPLACE FUNCTION pg_temp.codra_replace_deprecated_model(input jsonb, old_value text, new_value text)
405406
RETURNS jsonb
406407
LANGUAGE sql
407408
IMMUTABLE
@@ -410,14 +411,14 @@ async function normalizeRepoConfigs() {
410411
WHEN 'string' THEN CASE WHEN input #>> '{}' = old_value THEN to_jsonb(new_value) ELSE input END
411412
WHEN 'array' THEN COALESCE(
412413
(
413-
SELECT jsonb_agg(public.codra_replace_deprecated_model(value, old_value, new_value) ORDER BY ord)
414+
SELECT jsonb_agg(pg_temp.codra_replace_deprecated_model(value, old_value, new_value) ORDER BY ord)
414415
FROM jsonb_array_elements(input) WITH ORDINALITY AS item(value, ord)
415416
),
416417
'[]'::jsonb
417418
)
418419
WHEN 'object' THEN COALESCE(
419420
(
420-
SELECT jsonb_object_agg(key, public.codra_replace_deprecated_model(value, old_value, new_value))
421+
SELECT jsonb_object_agg(key, pg_temp.codra_replace_deprecated_model(value, old_value, new_value))
421422
FROM jsonb_each(input)
422423
),
423424
'{}'::jsonb
@@ -434,15 +435,15 @@ async function normalizeRepoConfigs() {
434435
main_model = CASE WHEN main_model = $1 THEN $2 ELSE main_model END,
435436
fallback_models = CASE
436437
WHEN fallback_models IS NULL THEN NULL
437-
ELSE public.codra_replace_deprecated_model(fallback_models, $1, $2)
438+
ELSE pg_temp.codra_replace_deprecated_model(fallback_models, $1, $2)
438439
END,
439440
size_overrides = CASE
440441
WHEN size_overrides IS NULL THEN NULL
441-
ELSE public.codra_replace_deprecated_model(size_overrides, $1, $2)
442+
ELSE pg_temp.codra_replace_deprecated_model(size_overrides, $1, $2)
442443
END,
443444
parsed_json = CASE
444445
WHEN parsed_json IS NULL THEN NULL
445-
ELSE public.codra_replace_deprecated_model(parsed_json, $1, $2)
446+
ELSE pg_temp.codra_replace_deprecated_model(parsed_json, $1, $2)
446447
END
447448
WHERE main_model = $1
448449
OR fallback_models::text LIKE '%' || $1 || '%'
@@ -452,7 +453,7 @@ async function normalizeRepoConfigs() {
452453
[kimiK25Model, kimiK26Model],
453454
);
454455

455-
await query('DROP FUNCTION IF EXISTS public.codra_replace_deprecated_model(jsonb, text, text)');
456+
await query('DROP FUNCTION IF EXISTS pg_temp.codra_replace_deprecated_model(jsonb, text, text)');
456457
}
457458

458459
async function main() {

src/client/lib/api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ export const api = {
204204
},
205205
updateModelConfig(id: string, config: ModelConfigPayload) {
206206
return request<{ ok: boolean; config: ModelConfig }>(`/api/models/${pathSegment(id)}`, {
207-
method: 'POST',
207+
method: 'PATCH',
208208
body: JSON.stringify(config),
209209
});
210210
},

src/client/pages/repos.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ function tiersEqual(a: ModelRouteConfig['size_overrides'] = [], b: ModelRouteCon
7575
return a.length === b.length && a.every((tier, index) => {
7676
const other = b[index];
7777
return Boolean(
78-
other &&
78+
tier && other &&
7979
tier.max_lines === other.max_lines &&
8080
tier.model === other.model &&
8181
stringArraysEqual(tier.fallbacks ?? [], other.fallbacks ?? []),

src/server/core/github.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -610,12 +610,12 @@ export class GitHubClient {
610610
const currentByLowerName = new Map(currentLabels.map(label => [label.toLowerCase(), label]));
611611

612612
const uniqueLabels = Array.from(new Set(labels.map(label => label.toLowerCase())));
613-
await Promise.all(uniqueLabels.map(async (label) => {
614-
const currentLabel = currentByLowerName.get(label.toLowerCase());
613+
for (const label of uniqueLabels) {
614+
const currentLabel = currentByLowerName.get(label);
615615
if (currentLabel) {
616616
await this.removeIssueLabel(owner, repo, issueNumber, currentLabel);
617617
}
618-
}));
618+
}
619619
}
620620

621621
async removeIssueLabel(owner: string, repo: string, issueNumber: number, label: string) {

0 commit comments

Comments
 (0)