fix(plugins): ai_assistant Migrationen von gedroppten ai_chat-Tabellen befreien
Check Cross-Plugin Imports / check (push) Has been cancelled

Produktionsbug: Plugin ai_assistant war migration_failed/inactive, weil
Migration 0003 ALTER TABLE ai_chat_sessions ausfuehrte — die Tabelle wurde
von Alembic 0137 (2026-08-21, Umstieg auf comm-Tabellen) gedroppt. Bei jedem
Container-Start crashte die Migration und deaktivierte das Plugin
(KI-Chat und /api/v1/ai/* lieferten 403).

Fix:
- 0003: ai_chat_sessions-Statements entfernt, nur ai_chat_folders behalten
- 0001: Ghost-Tabellen ai_chat_sessions/ai_chat_messages entfernt
  (frische Installs duerfen sie nicht rekreieren — Schema-Drift)
- 0002: ai_chat_attachments + toter folder_id-ALTER entfernt,
  nur ai_chat_folders behalten

Runner skipt getrackte Migrationen per Dateiname (kein Hash-Check),
Prod-Risiko null; 0003 laeuft beim naechsten Start sauber durch und
aktiviert das Plugin wieder.
This commit is contained in:
Agent Zero
2026-09-16 00:43:04 +02:00
parent e8e07fa13a
commit 0383dd2f64
3 changed files with 14 additions and 55 deletions
@@ -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);