| 1 | -- Auto for Ask: each question goes to the connection's model that suits it. |
| 2 | -- 1 on a route means Auto; its `model` is then not read. Code that does not |
| 3 | -- know this column keeps answering with `model`, so this runs before it. |
| 4 | ALTER TABLE model_routes ADD COLUMN auto INTEGER NOT NULL DEFAULT 0; |
| 5 | |
| 6 | -- Auto is the default, and Ask's routes made before it get it unless their |
| 7 | -- owner chose a model: the old picker started at the first model the |
| 8 | -- provider listed (or none), so a route with that model is one nobody |
| 9 | -- picked. An Azure deployment is named by its owner, so it stays. |
| 10 | UPDATE model_routes SET auto = 1 |
| 11 | WHERE task = 'ask' |
| 12 | AND connection_id IN ( |
| 13 | SELECT id FROM connections |
| 14 | WHERE provider != 'azure_openai' AND models IS NOT NULL AND json_valid(models) AND json_array_length(models) > 0 |
| 15 | ) |
| 16 | AND ( |
| 17 | model IS NULL |
| 18 | OR model = (SELECT json_extract(c.models, '$[0]') FROM connections c WHERE c.id = model_routes.connection_id) |
| 19 | ); |