diff --git a/app/plugins/builtins/ai_assistant/migrations/0001_initial.sql b/app/plugins/builtins/ai_assistant/migrations/0001_initial.sql index 9e44b92..67c55d0 100644 --- a/app/plugins/builtins/ai_assistant/migrations/0001_initial.sql +++ b/app/plugins/builtins/ai_assistant/migrations/0001_initial.sql @@ -1,4 +1,7 @@ -- AI Assistant plugin initial migration +-- 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. CREATE TABLE IF NOT EXISTS ai_providers ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), @@ -68,35 +71,3 @@ CREATE TABLE IF NOT EXISTS ai_agents ( deleted_at TIMESTAMPTZ ); CREATE INDEX IF NOT EXISTS ix_ai_agents_tenant ON ai_agents(tenant_id); - -CREATE TABLE IF NOT EXISTS ai_chat_sessions ( - id UUID PRIMARY KEY DEFAULT gen_random_uuid(), - user_id UUID NOT NULL, - agent_id UUID REFERENCES ai_agents(id) ON DELETE SET NULL, - title VARCHAR(255) NOT NULL DEFAULT 'Neuer Chat', - is_pinned BOOLEAN NOT NULL DEFAULT FALSE, - is_sidebar BOOLEAN NOT NULL DEFAULT FALSE, - tenant_id UUID NOT NULL, - created_at TIMESTAMPTZ NOT NULL DEFAULT now(), - updated_at TIMESTAMPTZ NOT NULL DEFAULT now(), - deleted_at TIMESTAMPTZ -); -CREATE INDEX IF NOT EXISTS ix_ai_sessions_user ON ai_chat_sessions(user_id); -CREATE INDEX IF NOT EXISTS ix_ai_sessions_tenant ON ai_chat_sessions(tenant_id); - -CREATE TABLE IF NOT EXISTS ai_chat_messages ( - id UUID PRIMARY KEY DEFAULT gen_random_uuid(), - session_id UUID NOT NULL REFERENCES ai_chat_sessions(id) ON DELETE CASCADE, - role VARCHAR(20) NOT NULL, - content TEXT NOT NULL DEFAULT '', - tool_calls JSONB, - tool_results JSONB, - tokens INTEGER NOT NULL DEFAULT 0, - model_used VARCHAR(200) NOT NULL DEFAULT '', - tenant_id UUID NOT NULL, - created_at TIMESTAMPTZ NOT NULL DEFAULT now(), - updated_at TIMESTAMPTZ NOT NULL DEFAULT now(), - deleted_at TIMESTAMPTZ -); -CREATE INDEX IF NOT EXISTS ix_ai_messages_session ON ai_chat_messages(session_id); -CREATE INDEX IF NOT EXISTS ix_ai_messages_tenant ON ai_chat_messages(tenant_id); diff --git a/app/plugins/builtins/ai_assistant/migrations/0002_folders_attachments.sql b/app/plugins/builtins/ai_assistant/migrations/0002_folders_attachments.sql index edfe247..460a95c 100644 --- a/app/plugins/builtins/ai_assistant/migrations/0002_folders_attachments.sql +++ b/app/plugins/builtins/ai_assistant/migrations/0002_folders_attachments.sql @@ -1,4 +1,8 @@ --- AI Assistant plugin migration 0002: chat folders + attachments +-- AI Assistant plugin migration 0002: chat folders +-- FIX 2026-09-16: ai_chat_attachments and the folder_id ALTER on +-- ai_chat_sessions removed — AI chat moved to comm_conversations/ +-- comm_messages (Alembic 0137 dropped the legacy tables). Only the +-- ai_chat_folders table remains (still used for chat folder ordering). CREATE TABLE IF NOT EXISTS ai_chat_folders ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), @@ -13,22 +17,3 @@ CREATE TABLE IF NOT EXISTS ai_chat_folders ( CREATE INDEX IF NOT EXISTS ix_ai_folders_user ON ai_chat_folders(user_id); CREATE INDEX IF NOT EXISTS ix_ai_folders_tenant ON ai_chat_folders(tenant_id); CREATE INDEX IF NOT EXISTS ix_ai_folders_parent ON ai_chat_folders(parent_id); - -ALTER TABLE ai_chat_sessions ADD COLUMN IF NOT EXISTS folder_id UUID REFERENCES ai_chat_folders(id) ON DELETE SET NULL; - -CREATE TABLE IF NOT EXISTS ai_chat_attachments ( - id UUID PRIMARY KEY DEFAULT gen_random_uuid(), - message_id UUID REFERENCES ai_chat_messages(id) ON DELETE CASCADE, - session_id UUID NOT NULL REFERENCES ai_chat_sessions(id) ON DELETE CASCADE, - filename VARCHAR(255) NOT NULL, - mime_type VARCHAR(255) NOT NULL DEFAULT 'application/octet-stream', - size_bytes INTEGER NOT NULL DEFAULT 0, - storage_path VARCHAR(1024) NOT NULL, - tenant_id UUID NOT NULL, - created_at TIMESTAMPTZ NOT NULL DEFAULT now(), - updated_at TIMESTAMPTZ NOT NULL DEFAULT now(), - deleted_at TIMESTAMPTZ -); -CREATE INDEX IF NOT EXISTS ix_ai_attachments_message ON ai_chat_attachments(message_id); -CREATE INDEX IF NOT EXISTS ix_ai_attachments_session ON ai_chat_attachments(session_id); -CREATE INDEX IF NOT EXISTS ix_ai_attachments_tenant ON ai_chat_attachments(tenant_id); diff --git a/app/plugins/builtins/ai_assistant/migrations/0003_sort_order.sql b/app/plugins/builtins/ai_assistant/migrations/0003_sort_order.sql index f9c5462..41eb18a 100644 --- a/app/plugins/builtins/ai_assistant/migrations/0003_sort_order.sql +++ b/app/plugins/builtins/ai_assistant/migrations/0003_sort_order.sql @@ -1,8 +1,11 @@ -- Migration 0003: Add sort_order columns for drag&drop reordering +-- FIX 2026-09-16: ai_chat_sessions was dropped by Alembic 0137 (AI chat +-- moved to comm_conversations/comm_messages). The ALTER/INDEX statements +-- targeting ai_chat_sessions made this migration fail on every startup +-- ("relation ai_chat_sessions does not exist"), which deactivated the +-- whole ai_assistant plugin. Only the ai_chat_folders statements remain +-- (that table still exists and is used for chat folder ordering). -ALTER TABLE ai_chat_sessions ADD COLUMN IF NOT EXISTS sort_order INTEGER NOT NULL DEFAULT 0; ALTER TABLE ai_chat_folders ADD COLUMN IF NOT EXISTS sort_order INTEGER NOT NULL DEFAULT 0; -CREATE INDEX IF NOT EXISTS ix_ai_sessions_folder ON ai_chat_sessions(folder_id); -CREATE INDEX IF NOT EXISTS ix_ai_sessions_sort ON ai_chat_sessions(sort_order); CREATE INDEX IF NOT EXISTS ix_ai_folders_sort ON ai_chat_folders(sort_order);