Files
sub2api/backend/migrations/172_composite_model_routes.sql
T
李建琦 6d655c9903
Release / update-version (push) Has been cancelled
Release / build-frontend (push) Has been cancelled
Release / release (push) Has been cancelled
Release / sync-version-file (push) Has been cancelled
CI / shell (push) Canceled after 0s
CI / test (push) Canceled after 0s
CI / frontend (push) Canceled after 0s
CI / golangci-lint (push) Canceled after 0s
Security Scan / backend-security (push) Canceled after 0s
Security Scan / frontend-security (push) Canceled after 0s
Sub2API v1.0 - AI API 网关(二开初始版本,基于上游 Wei-Shaw/sub2api)
2026-08-21 18:30:13 +08:00

31 lines
1.5 KiB
SQL

CREATE TABLE IF NOT EXISTS composite_model_routes (
id BIGSERIAL PRIMARY KEY,
group_id BIGINT NOT NULL REFERENCES groups(id) ON DELETE CASCADE,
public_model VARCHAR(200) NOT NULL,
match_type VARCHAR(20) NOT NULL DEFAULT 'exact',
target_platform VARCHAR(50) NOT NULL,
upstream_model VARCHAR(200) NOT NULL DEFAULT '',
endpoint VARCHAR(50) NOT NULL DEFAULT 'any',
priority INTEGER NOT NULL DEFAULT 100,
enabled BOOLEAN NOT NULL DEFAULT TRUE,
notes TEXT,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
deleted_at TIMESTAMPTZ NULL,
CONSTRAINT composite_model_routes_match_type_check CHECK (match_type IN ('exact', 'prefix')),
CONSTRAINT composite_model_routes_endpoint_check CHECK (endpoint IN ('any', 'messages', 'count_tokens', 'responses', 'chat_completions', 'embeddings', 'images', 'gemini')),
CONSTRAINT composite_model_routes_target_platform_check CHECK (target_platform IN ('anthropic', 'openai', 'gemini', 'antigravity', 'grok'))
);
CREATE UNIQUE INDEX IF NOT EXISTS idx_composite_model_routes_unique_active
ON composite_model_routes (group_id, endpoint, match_type, public_model)
WHERE deleted_at IS NULL;
CREATE INDEX IF NOT EXISTS idx_composite_model_routes_group_enabled
ON composite_model_routes (group_id, enabled)
WHERE deleted_at IS NULL;
CREATE INDEX IF NOT EXISTS idx_composite_model_routes_group_priority
ON composite_model_routes (group_id, priority, id)
WHERE deleted_at IS NULL;