2026-07-17 00:45:24 +02:00
|
|
|
-- AI Assistant plugin initial migration
|
2026-09-16 00:43:04 +02:00
|
|
|
-- FIX 2026-09-16: ai_chat_sessions/ai_chat_messages removed — AI chat moved
|
|
|
|
|
-- to comm_conversations/comm_messages (Alembic 0137 dropped these tables).
|
|
|
|
|
-- Fresh installs must NOT recreate the ghost tables.
|
2026-07-17 00:45:24 +02:00
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS ai_providers (
|
|
|
|
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
|
|
|
name VARCHAR(100) NOT NULL,
|
|
|
|
|
provider_type VARCHAR(50) NOT NULL,
|
|
|
|
|
api_key TEXT NOT NULL DEFAULT '',
|
|
|
|
|
base_url VARCHAR(500) NOT NULL DEFAULT '',
|
|
|
|
|
is_active BOOLEAN NOT NULL DEFAULT TRUE,
|
|
|
|
|
is_default BOOLEAN NOT NULL DEFAULT FALSE,
|
|
|
|
|
config JSONB NOT NULL DEFAULT '{}',
|
|
|
|
|
tenant_id UUID NOT NULL,
|
|
|
|
|
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
2026-07-17 01:08:13 +02:00
|
|
|
updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
|
|
|
|
deleted_at TIMESTAMPTZ
|
2026-07-17 00:45:24 +02:00
|
|
|
);
|
|
|
|
|
CREATE INDEX IF NOT EXISTS ix_ai_providers_tenant ON ai_providers(tenant_id);
|
|
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS ai_models (
|
|
|
|
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
|
|
|
provider_id UUID NOT NULL REFERENCES ai_providers(id) ON DELETE CASCADE,
|
|
|
|
|
model_id VARCHAR(200) NOT NULL,
|
|
|
|
|
display_name VARCHAR(200) NOT NULL,
|
|
|
|
|
context_window INTEGER NOT NULL DEFAULT 4096,
|
|
|
|
|
supports_tools BOOLEAN NOT NULL DEFAULT FALSE,
|
|
|
|
|
supports_streaming BOOLEAN NOT NULL DEFAULT TRUE,
|
|
|
|
|
is_active BOOLEAN NOT NULL DEFAULT TRUE,
|
|
|
|
|
config JSONB NOT NULL DEFAULT '{}',
|
|
|
|
|
tenant_id UUID NOT NULL,
|
|
|
|
|
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
2026-07-17 01:08:13 +02:00
|
|
|
updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
|
|
|
|
deleted_at TIMESTAMPTZ
|
2026-07-17 00:45:24 +02:00
|
|
|
);
|
|
|
|
|
CREATE INDEX IF NOT EXISTS ix_ai_models_provider ON ai_models(provider_id);
|
|
|
|
|
CREATE INDEX IF NOT EXISTS ix_ai_models_tenant ON ai_models(tenant_id);
|
|
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS ai_presets (
|
|
|
|
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
|
|
|
name VARCHAR(100) NOT NULL,
|
|
|
|
|
model_id VARCHAR(200) NOT NULL,
|
|
|
|
|
provider_id UUID REFERENCES ai_providers(id) ON DELETE SET NULL,
|
|
|
|
|
temperature REAL NOT NULL DEFAULT 0.7,
|
|
|
|
|
max_tokens INTEGER NOT NULL DEFAULT 2048,
|
|
|
|
|
top_p REAL NOT NULL DEFAULT 1.0,
|
|
|
|
|
system_prompt TEXT NOT NULL DEFAULT '',
|
|
|
|
|
config JSONB NOT NULL DEFAULT '{}',
|
|
|
|
|
is_active BOOLEAN NOT NULL DEFAULT TRUE,
|
|
|
|
|
tenant_id UUID NOT NULL,
|
|
|
|
|
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
2026-07-17 01:08:13 +02:00
|
|
|
updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
|
|
|
|
deleted_at TIMESTAMPTZ
|
2026-07-17 00:45:24 +02:00
|
|
|
);
|
|
|
|
|
CREATE INDEX IF NOT EXISTS ix_ai_presets_tenant ON ai_presets(tenant_id);
|
|
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS ai_agents (
|
|
|
|
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
|
|
|
name VARCHAR(100) NOT NULL,
|
|
|
|
|
description TEXT NOT NULL DEFAULT '',
|
|
|
|
|
system_prompt TEXT NOT NULL DEFAULT '',
|
|
|
|
|
preset_id UUID REFERENCES ai_presets(id) ON DELETE SET NULL,
|
|
|
|
|
tool_ids JSONB NOT NULL DEFAULT '[]',
|
|
|
|
|
is_default BOOLEAN NOT NULL DEFAULT FALSE,
|
|
|
|
|
is_active BOOLEAN NOT NULL DEFAULT TRUE,
|
|
|
|
|
config JSONB NOT NULL DEFAULT '{}',
|
|
|
|
|
tenant_id UUID NOT NULL,
|
|
|
|
|
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
2026-07-17 01:08:13 +02:00
|
|
|
updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
|
|
|
|
deleted_at TIMESTAMPTZ
|
2026-07-17 00:45:24 +02:00
|
|
|
);
|
|
|
|
|
CREATE INDEX IF NOT EXISTS ix_ai_agents_tenant ON ai_agents(tenant_id);
|