Allow openai and openrouter AI providers in the schema
CI / ci (push) Successful in 1m32s
CI / ci (pull_request) Successful in 1m30s

0001 limited ai_settings.provider and ai_runs.provider to
openai_compatible, anthropic and ollama, so the openai and openrouter
presets could not be stored. Migration 0004 rebuilds both tables with the
wider CHECK, keeping the three existing values and every row.

ai_runs is referenced by suggestion_batches and week_plans, so it is
rebuilt by copying rows aside and recreating the table under its own name
with foreign keys deferred; the create-then-rename rebuild from 0003 leaves
the dropped table's references counted as violations at commit.

Tests cover upgrading a database with ai_settings, ai_runs and referencing
rows, and storing every preset provider in both tables.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-04 08:54:03 -04:00
co-authored by Claude Opus 5.5
parent 61c767ea32
commit b6e433cc98
3 changed files with 178 additions and 6 deletions
+19 -2
View File
@@ -305,7 +305,7 @@ func TestSchemaEnumChecksRejectInvalidValues(t *testing.T) {
{"household_settings", "plan_draft_dow", 5.5},
{"household_settings", "suggestions_dow", 0.5},
{"household_settings", "chat_autosend_dow", 3.5},
{"ai_runs", "provider", "openai"},
{"ai_runs", "provider", "gemini"},
{"ai_runs", "status", "done"},
{"dinners", "status", "deck"},
{"dinners", "origin", "ai"},
@@ -322,7 +322,7 @@ func TestSchemaEnumChecksRejectInvalidValues(t *testing.T) {
{"rotation_reviews", "decision", "promote"},
{"shopping_lists", "status", "frozen"},
{"shopping_items", "needed", 2},
{"ai_settings", "provider", "openai"},
{"ai_settings", "provider", "gemini"},
{"recipe_search_settings", "provider", "google"},
{"chat_settings", "last_test_status", "pending"},
{"notification_prefs", "event", "weekly_digest"},
@@ -360,6 +360,23 @@ func TestSchemaRotationReviewEventAllowed(t *testing.T) {
}
}
// TestSchemaAIProvidersAllowed checks every provider preset can be stored in
// both ai_settings and ai_runs.
func TestSchemaAIProvidersAllowed(t *testing.T) {
s := seededStore(t)
for _, provider := range []string{"openai_compatible", "anthropic", "ollama", "openai", "openrouter"} {
for _, table := range []string{"ai_settings", "ai_runs"} {
inRolledBackTx(t, s, func(tx *sql.Tx) {
row := testRow(table, 1)
row["provider"] = provider
if err := insertSchemaRow(tx, table, row); err != nil {
t.Errorf("%s.provider %s rejected: %v", table, provider, err)
}
})
}
}
}
func TestSchemaDinnerStatuses(t *testing.T) {
s := seededStore(t)
for _, status := range []string{"suggested", "quest_log", "tried", "regular", "archived"} {