lazyBoy/migrations/021_space_model_providers.sql

21 lines
899 B
MySQL
Raw Permalink Normal View History

2026-09-10 06:38:31 +00:00
-- Each provider keeps its own key, model, and base URL so switching
-- xAI → OpenCode Go (and back) does not wipe what was already saved.
-- The active choice still lives on spaces.default_model_*; this table is
-- the memory for the providers that are not currently selected.
-- API keys stay here and are never returned to the client.
CREATE TABLE IF NOT EXISTS space_model_providers (
space_id TEXT NOT NULL REFERENCES spaces (id) ON DELETE CASCADE,
provider TEXT NOT NULL,
model_id TEXT NOT NULL DEFAULT '',
base_url TEXT,
api_key TEXT,
updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
PRIMARY KEY (space_id, provider)
);
INSERT INTO space_model_providers (space_id, provider, model_id, base_url, api_key)
SELECT id, default_model_provider, default_model_id, default_model_base_url, default_model_api_key
FROM spaces
ON CONFLICT (space_id, provider) DO NOTHING;