172_composite_model_routes.sql 1.5 KB

123456789101112131415161718192021222324252627282930
  1. CREATE TABLE IF NOT EXISTS composite_model_routes (
  2. id BIGSERIAL PRIMARY KEY,
  3. group_id BIGINT NOT NULL REFERENCES groups(id) ON DELETE CASCADE,
  4. public_model VARCHAR(200) NOT NULL,
  5. match_type VARCHAR(20) NOT NULL DEFAULT 'exact',
  6. target_platform VARCHAR(50) NOT NULL,
  7. upstream_model VARCHAR(200) NOT NULL DEFAULT '',
  8. endpoint VARCHAR(50) NOT NULL DEFAULT 'any',
  9. priority INTEGER NOT NULL DEFAULT 100,
  10. enabled BOOLEAN NOT NULL DEFAULT TRUE,
  11. notes TEXT,
  12. created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
  13. updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
  14. deleted_at TIMESTAMPTZ NULL,
  15. CONSTRAINT composite_model_routes_match_type_check CHECK (match_type IN ('exact', 'prefix')),
  16. CONSTRAINT composite_model_routes_endpoint_check CHECK (endpoint IN ('any', 'messages', 'count_tokens', 'responses', 'chat_completions', 'embeddings', 'images', 'gemini')),
  17. CONSTRAINT composite_model_routes_target_platform_check CHECK (target_platform IN ('anthropic', 'openai', 'gemini', 'antigravity', 'grok'))
  18. );
  19. CREATE UNIQUE INDEX IF NOT EXISTS idx_composite_model_routes_unique_active
  20. ON composite_model_routes (group_id, endpoint, match_type, public_model)
  21. WHERE deleted_at IS NULL;
  22. CREATE INDEX IF NOT EXISTS idx_composite_model_routes_group_enabled
  23. ON composite_model_routes (group_id, enabled)
  24. WHERE deleted_at IS NULL;
  25. CREATE INDEX IF NOT EXISTS idx_composite_model_routes_group_priority
  26. ON composite_model_routes (group_id, priority, id)
  27. WHERE deleted_at IS NULL;