chore: 初始化仓库,导入项目基线代码
Academy v0.8.3 完整代码基线:Go 后端(internal/cmd/cli/mcp-server/docreader)、 Vue 前端(frontend)、数据库迁移(migrations)、部署编排(docker/helm/deploy)与文档。 今日开发的培训推送管理改动随后单独提交。
This commit is contained in:
commit
7ec21f35b0
5767 files changed
+1436788
No files matched your search
@@ -0,0 +1,34 @@
|
||||
DROP TABLE IF EXISTS tenant_invitations;
|
||||
DROP TABLE IF EXISTS tenant_api_keys;
|
||||
DROP TABLE IF EXISTS wiki_page_revisions;
|
||||
DROP TABLE IF EXISTS wiki_page_issues;
|
||||
DROP TABLE IF EXISTS wiki_pages;
|
||||
DROP TABLE IF EXISTS wiki_folders;
|
||||
DROP TABLE IF EXISTS user_kb_pins;
|
||||
DROP TABLE IF EXISTS user_resource_favorites;
|
||||
DROP TABLE IF EXISTS tenant_disabled_shared_agents;
|
||||
DROP TABLE IF EXISTS agent_shares;
|
||||
DROP TABLE IF EXISTS organization_join_requests;
|
||||
DROP TABLE IF EXISTS kb_shares;
|
||||
DROP TABLE IF EXISTS organization_tenant_members;
|
||||
DROP TABLE IF EXISTS organizations;
|
||||
DROP TABLE IF EXISTS custom_agents;
|
||||
DROP TABLE IF EXISTS mcp_tool_approvals;
|
||||
DROP TABLE IF EXISTS mcp_services;
|
||||
DROP TABLE IF EXISTS knowledge_tags;
|
||||
DROP TABLE IF EXISTS auth_tokens;
|
||||
DROP TABLE IF EXISTS audit_logs;
|
||||
DROP TABLE IF EXISTS tenant_members;
|
||||
DROP TABLE IF EXISTS users;
|
||||
DROP TABLE IF EXISTS chunks;
|
||||
DROP TABLE IF EXISTS messages;
|
||||
DROP TABLE IF EXISTS temporary_documents;
|
||||
DROP TABLE IF EXISTS sessions;
|
||||
DROP TABLE IF EXISTS knowledges;
|
||||
DROP TABLE IF EXISTS knowledge_bases;
|
||||
DROP TABLE IF EXISTS storage_backends;
|
||||
DROP TABLE IF EXISTS resource_access_grants;
|
||||
DROP TABLE IF EXISTS resource_bindings;
|
||||
DROP TABLE IF EXISTS resources;
|
||||
DROP TABLE IF EXISTS models;
|
||||
DROP TABLE IF EXISTS tenants;
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,17 @@
|
||||
CREATE TABLE IF NOT EXISTS wiki_log_entries (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
tenant_id INTEGER NOT NULL,
|
||||
knowledge_base_id VARCHAR(36) NOT NULL,
|
||||
action VARCHAR(32) NOT NULL,
|
||||
knowledge_id VARCHAR(36) NOT NULL DEFAULT '',
|
||||
doc_title TEXT NOT NULL DEFAULT '',
|
||||
summary TEXT NOT NULL DEFAULT '',
|
||||
pages_affected TEXT NOT NULL DEFAULT '[]',
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_wiki_log_entries_kb_id_desc
|
||||
ON wiki_log_entries (knowledge_base_id, id DESC);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_wiki_log_entries_tenant_id
|
||||
ON wiki_log_entries (tenant_id);
|
||||
@@ -0,0 +1,3 @@
|
||||
DROP TABLE IF EXISTS wiki_log_entries;
|
||||
|
||||
DELETE FROM wiki_pages WHERE page_type = 'log';
|
||||
@@ -0,0 +1,8 @@
|
||||
-- Fold the relative directory back into file_name before dropping the column.
|
||||
UPDATE knowledges
|
||||
SET file_name = folder_path || '/' || file_name
|
||||
WHERE folder_path <> '' AND file_name <> '';
|
||||
|
||||
DROP INDEX IF EXISTS idx_knowledges_folder_path;
|
||||
|
||||
ALTER TABLE knowledges DROP COLUMN folder_path;
|
||||
@@ -0,0 +1,23 @@
|
||||
-- Folder tree support for knowledge bases (SQLite / lite mode).
|
||||
--
|
||||
-- Mirrors migrations/versioned/000079_knowledge_folder_path.up.sql.
|
||||
ALTER TABLE knowledges ADD COLUMN folder_path VARCHAR(1024) NOT NULL DEFAULT '';
|
||||
|
||||
-- Backfill legacy folder uploads, which encoded their relative directory in
|
||||
-- file_name. SQLite has no regex, so the directory prefix is isolated with the
|
||||
-- rtrim trick: trimming every non-slash character off the right leaves exactly
|
||||
-- the prefix up to and including the last '/'.
|
||||
UPDATE knowledges
|
||||
SET folder_path = substr(
|
||||
rtrim(file_name, replace(file_name, '/', '')),
|
||||
1,
|
||||
length(rtrim(file_name, replace(file_name, '/', ''))) - 1
|
||||
),
|
||||
file_name = substr(
|
||||
file_name,
|
||||
length(rtrim(file_name, replace(file_name, '/', ''))) + 1
|
||||
)
|
||||
WHERE file_name LIKE '%/%';
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_knowledges_folder_path
|
||||
ON knowledges (tenant_id, knowledge_base_id, folder_path);
|
||||
@@ -0,0 +1 @@
|
||||
ALTER TABLE knowledge_bases DROP COLUMN auto_tag_config;
|
||||
@@ -0,0 +1 @@
|
||||
ALTER TABLE knowledge_bases ADD COLUMN auto_tag_config TEXT;
|
||||
@@ -0,0 +1,13 @@
|
||||
DROP TABLE IF EXISTS memory_item_embeddings;
|
||||
DROP INDEX IF EXISTS idx_mem_affinity_scope;
|
||||
DROP TABLE IF EXISTS memory_doc_affinity;
|
||||
DROP INDEX IF EXISTS idx_mem_topic_scope;
|
||||
DROP TABLE IF EXISTS memory_topic_stats;
|
||||
DROP INDEX IF EXISTS idx_memory_items_key;
|
||||
DROP INDEX IF EXISTS idx_memory_items_scope;
|
||||
DROP TABLE IF EXISTS memory_items;
|
||||
DROP INDEX IF EXISTS idx_mem_tomb_fp;
|
||||
DROP INDEX IF EXISTS idx_memory_tombstones_scope;
|
||||
DROP TABLE IF EXISTS memory_tombstones;
|
||||
DROP INDEX IF EXISTS idx_memory_subjects_scope;
|
||||
DROP TABLE IF EXISTS memory_subjects;
|
||||
@@ -0,0 +1,118 @@
|
||||
-- Cross-session long-term memory (Lite). Mirrors migrations/versioned/000084.
|
||||
-- Row ids are generated in Go, so there is no server-side default here.
|
||||
|
||||
CREATE TABLE IF NOT EXISTS memory_subjects (
|
||||
id VARCHAR(36) PRIMARY KEY,
|
||||
tenant_id INTEGER NOT NULL,
|
||||
subject_id VARCHAR(512) NOT NULL,
|
||||
enabled BOOLEAN NOT NULL DEFAULT 1,
|
||||
block_text TEXT NOT NULL DEFAULT '',
|
||||
block_updated_at DATETIME,
|
||||
item_count INTEGER NOT NULL DEFAULT 0,
|
||||
last_extracted_at DATETIME,
|
||||
extract_cursor DATETIME,
|
||||
pending_sessions TEXT,
|
||||
extract_scheduled_at DATETIME,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS idx_memory_subjects_scope
|
||||
ON memory_subjects (tenant_id, subject_id);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS memory_items (
|
||||
id VARCHAR(36) PRIMARY KEY,
|
||||
tenant_id INTEGER NOT NULL,
|
||||
subject_id VARCHAR(512) NOT NULL,
|
||||
kind VARCHAR(32) NOT NULL,
|
||||
content TEXT NOT NULL,
|
||||
topic VARCHAR(255) NOT NULL DEFAULT '',
|
||||
normalized_key VARCHAR(255) NOT NULL DEFAULT '',
|
||||
importance INTEGER NOT NULL DEFAULT 3,
|
||||
origin VARCHAR(16) NOT NULL DEFAULT 'extracted',
|
||||
status VARCHAR(16) NOT NULL DEFAULT 'active',
|
||||
source_session_id VARCHAR(36),
|
||||
source_message_id VARCHAR(36),
|
||||
valid_from DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
invalid_at DATETIME,
|
||||
expires_at DATETIME,
|
||||
superseded_by VARCHAR(36),
|
||||
last_used_at DATETIME,
|
||||
use_count INTEGER NOT NULL DEFAULT 0,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_memory_items_scope
|
||||
ON memory_items (tenant_id, subject_id, status);
|
||||
CREATE INDEX IF NOT EXISTS idx_memory_items_key
|
||||
ON memory_items (tenant_id, subject_id, normalized_key);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS memory_tombstones (
|
||||
id VARCHAR(36) PRIMARY KEY,
|
||||
tenant_id INTEGER NOT NULL,
|
||||
subject_id VARCHAR(512) NOT NULL,
|
||||
topic VARCHAR(255) NOT NULL DEFAULT '',
|
||||
fingerprint VARCHAR(64) NOT NULL,
|
||||
source_message_id VARCHAR(36),
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_memory_tombstones_scope
|
||||
ON memory_tombstones (tenant_id, subject_id);
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS idx_mem_tomb_fp
|
||||
ON memory_tombstones (tenant_id, subject_id, fingerprint);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS memory_topic_stats (
|
||||
id VARCHAR(36) PRIMARY KEY,
|
||||
tenant_id INTEGER NOT NULL,
|
||||
subject_id VARCHAR(512) NOT NULL,
|
||||
normalized_key VARCHAR(255) NOT NULL,
|
||||
topic VARCHAR(255) NOT NULL DEFAULT '',
|
||||
hits INTEGER NOT NULL DEFAULT 0,
|
||||
last_seen_at DATETIME,
|
||||
promoted_at DATETIME,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS idx_mem_topic_scope
|
||||
ON memory_topic_stats (tenant_id, subject_id, normalized_key);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS memory_doc_affinity (
|
||||
id VARCHAR(36) PRIMARY KEY,
|
||||
tenant_id INTEGER NOT NULL,
|
||||
subject_id VARCHAR(512) NOT NULL,
|
||||
knowledge_id VARCHAR(36) NOT NULL,
|
||||
knowledge_base_id VARCHAR(36) NOT NULL DEFAULT '',
|
||||
title VARCHAR(512) NOT NULL DEFAULT '',
|
||||
hits INTEGER NOT NULL DEFAULT 0,
|
||||
last_used_at DATETIME,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS idx_mem_affinity_scope
|
||||
ON memory_doc_affinity (tenant_id, subject_id, knowledge_id);
|
||||
|
||||
ALTER TABLE tenants ADD COLUMN memory_config TEXT;
|
||||
ALTER TABLE messages ADD COLUMN used_memories TEXT;
|
||||
|
||||
ALTER TABLE memory_subjects ADD COLUMN consolidated_at DATETIME;
|
||||
ALTER TABLE memory_subjects ADD COLUMN forced_consolidated_at DATETIME;
|
||||
|
||||
ALTER TABLE memory_topic_stats ADD COLUMN aliases TEXT NOT NULL DEFAULT '[]';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS memory_item_embeddings (
|
||||
item_id VARCHAR(36) PRIMARY KEY,
|
||||
tenant_id INTEGER NOT NULL,
|
||||
subject_id VARCHAR(512) NOT NULL,
|
||||
model_id VARCHAR(64) NOT NULL DEFAULT '',
|
||||
dims INTEGER NOT NULL DEFAULT 0,
|
||||
vector BLOB,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_mem_emb_scope
|
||||
ON memory_item_embeddings (tenant_id, subject_id);
|
||||
@@ -0,0 +1,15 @@
|
||||
DROP INDEX IF EXISTS idx_tenant_invitations_token;
|
||||
DROP INDEX IF EXISTS idx_tenant_invitations_unique_pending;
|
||||
|
||||
-- Legacy unique index cannot coexist with multiple share-link rows.
|
||||
DELETE FROM tenant_invitations
|
||||
WHERE invitee_user_id = ''
|
||||
AND deleted_at IS NULL;
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS idx_tenant_invitations_unique_pending
|
||||
ON tenant_invitations(tenant_id, invitee_user_id)
|
||||
WHERE status = 'pending' AND deleted_at IS NULL;
|
||||
|
||||
ALTER TABLE tenant_invitations DROP COLUMN accepted_count;
|
||||
ALTER TABLE tenant_invitations DROP COLUMN token;
|
||||
ALTER TABLE messages DROP COLUMN attachments;
|
||||
@@ -0,0 +1,21 @@
|
||||
-- Mirrors versioned migrations:
|
||||
-- 000034_add_attachments messages.attachments
|
||||
-- 000054_invitation_tokens tenant_invitations.token / accepted_count
|
||||
|
||||
ALTER TABLE messages ADD COLUMN attachments TEXT NOT NULL DEFAULT '[]';
|
||||
|
||||
ALTER TABLE tenant_invitations ADD COLUMN token VARCHAR(64) NOT NULL DEFAULT '';
|
||||
ALTER TABLE tenant_invitations ADD COLUMN accepted_count INTEGER NOT NULL DEFAULT 0;
|
||||
|
||||
-- Share-link rows use invitee_user_id=''; relax the pending uniqueness index
|
||||
-- so multiple share links can coexist on one tenant (see versioned 000054).
|
||||
DROP INDEX IF EXISTS idx_tenant_invitations_unique_pending;
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS idx_tenant_invitations_unique_pending
|
||||
ON tenant_invitations(tenant_id, invitee_user_id)
|
||||
WHERE status = 'pending'
|
||||
AND deleted_at IS NULL
|
||||
AND invitee_user_id <> '';
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS idx_tenant_invitations_token
|
||||
ON tenant_invitations(token)
|
||||
WHERE token <> '' AND deleted_at IS NULL;
|
||||
@@ -0,0 +1,8 @@
|
||||
DROP INDEX IF EXISTS idx_task_dead_letters_task_type;
|
||||
DROP INDEX IF EXISTS idx_task_dead_letters_tenant;
|
||||
DROP INDEX IF EXISTS idx_task_dead_letters_scope;
|
||||
DROP INDEX IF EXISTS idx_task_pending_ops_tenant;
|
||||
DROP INDEX IF EXISTS idx_task_pending_ops_scope;
|
||||
|
||||
DROP TABLE IF EXISTS task_dead_letters;
|
||||
DROP TABLE IF EXISTS task_pending_ops;
|
||||
@@ -0,0 +1,44 @@
|
||||
-- Mirrors versioned migration 000041_task_queue_and_wiki_indexes:
|
||||
-- durable pending-op queue and dead-letter archive for SQLite.
|
||||
|
||||
CREATE TABLE IF NOT EXISTS task_pending_ops (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
tenant_id INTEGER NOT NULL,
|
||||
task_type VARCHAR(64) NOT NULL,
|
||||
scope VARCHAR(32) NOT NULL,
|
||||
scope_id VARCHAR(64) NOT NULL,
|
||||
op VARCHAR(32) NOT NULL,
|
||||
dedup_key VARCHAR(128) NOT NULL DEFAULT '',
|
||||
payload TEXT NOT NULL DEFAULT '{}',
|
||||
fail_count INTEGER NOT NULL DEFAULT 0,
|
||||
enqueued_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
claimed_at DATETIME
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_task_pending_ops_scope
|
||||
ON task_pending_ops (task_type, scope, scope_id, id);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_task_pending_ops_tenant
|
||||
ON task_pending_ops (tenant_id);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS task_dead_letters (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
tenant_id INTEGER NOT NULL,
|
||||
task_type VARCHAR(64) NOT NULL,
|
||||
scope VARCHAR(32) NOT NULL,
|
||||
scope_id VARCHAR(64) NOT NULL,
|
||||
related_id VARCHAR(64) NOT NULL DEFAULT '',
|
||||
payload TEXT NOT NULL,
|
||||
last_error TEXT NOT NULL DEFAULT '',
|
||||
fail_count INTEGER NOT NULL,
|
||||
failed_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_task_dead_letters_scope
|
||||
ON task_dead_letters (scope, scope_id, failed_at DESC);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_task_dead_letters_tenant
|
||||
ON task_dead_letters (tenant_id, failed_at DESC);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_task_dead_letters_task_type
|
||||
ON task_dead_letters (task_type, failed_at DESC);
|
||||
@@ -0,0 +1,4 @@
|
||||
DROP INDEX IF EXISTS idx_system_settings_category;
|
||||
DROP TABLE IF EXISTS system_settings;
|
||||
DROP INDEX IF EXISTS idx_users_is_system_admin;
|
||||
ALTER TABLE users DROP COLUMN is_system_admin;
|
||||
@@ -0,0 +1,22 @@
|
||||
-- Mirrors versioned migration 000053_system_admin_and_settings:
|
||||
-- users.is_system_admin + system_settings table.
|
||||
|
||||
ALTER TABLE users ADD COLUMN is_system_admin BOOLEAN NOT NULL DEFAULT 0;
|
||||
CREATE INDEX IF NOT EXISTS idx_users_is_system_admin ON users (is_system_admin);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS system_settings (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
key VARCHAR(128) NOT NULL UNIQUE,
|
||||
value TEXT NOT NULL,
|
||||
value_type VARCHAR(16) NOT NULL,
|
||||
category VARCHAR(32) NOT NULL,
|
||||
description TEXT NOT NULL DEFAULT '',
|
||||
is_secret BOOLEAN NOT NULL DEFAULT 0,
|
||||
requires_restart BOOLEAN NOT NULL DEFAULT 0,
|
||||
last_modified_by VARCHAR(36) NOT NULL DEFAULT '',
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_system_settings_category
|
||||
ON system_settings (category);
|
||||
@@ -0,0 +1,6 @@
|
||||
ALTER TABLE knowledges DROP COLUMN pending_subtasks_count;
|
||||
|
||||
DROP INDEX IF EXISTS idx_kpspan_parent;
|
||||
DROP INDEX IF EXISTS idx_kpspan_status_started;
|
||||
DROP INDEX IF EXISTS idx_kpspan_knowledge_attempt;
|
||||
DROP TABLE IF EXISTS knowledge_processing_spans;
|
||||
@@ -0,0 +1,39 @@
|
||||
-- Mirrors versioned migrations:
|
||||
-- 000055_knowledge_processing_spans knowledge_processing_spans table
|
||||
-- 000056_knowledge_pending_subtasks knowledges.pending_subtasks_count
|
||||
-- 000066_expand_knowledge_span_name name VARCHAR(255)
|
||||
|
||||
CREATE TABLE IF NOT EXISTS knowledge_processing_spans (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
knowledge_id VARCHAR(64) NOT NULL,
|
||||
attempt INTEGER NOT NULL DEFAULT 1,
|
||||
span_id VARCHAR(64) NOT NULL,
|
||||
parent_span_id VARCHAR(64),
|
||||
name VARCHAR(255) NOT NULL,
|
||||
kind VARCHAR(16) NOT NULL,
|
||||
status VARCHAR(16) NOT NULL,
|
||||
input TEXT,
|
||||
output TEXT,
|
||||
metadata TEXT,
|
||||
error_code VARCHAR(64),
|
||||
error_message TEXT,
|
||||
error_detail TEXT,
|
||||
started_at DATETIME,
|
||||
finished_at DATETIME,
|
||||
duration_ms INTEGER,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
CONSTRAINT uq_kpspan_attempt_span UNIQUE (knowledge_id, attempt, span_id)
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_kpspan_knowledge_attempt
|
||||
ON knowledge_processing_spans (knowledge_id, attempt);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_kpspan_status_started
|
||||
ON knowledge_processing_spans (status, started_at);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_kpspan_parent
|
||||
ON knowledge_processing_spans (parent_span_id)
|
||||
WHERE parent_span_id IS NOT NULL;
|
||||
|
||||
ALTER TABLE knowledges ADD COLUMN pending_subtasks_count INTEGER NOT NULL DEFAULT 0;
|
||||
@@ -0,0 +1 @@
|
||||
ALTER TABLE embed_channels DROP COLUMN allow_memory;
|
||||
@@ -0,0 +1,3 @@
|
||||
-- Mirrors versioned migration 000060_embed_channels: embed_channels.allow_memory.
|
||||
|
||||
ALTER TABLE embed_channels ADD COLUMN allow_memory BOOLEAN NOT NULL DEFAULT 0;
|
||||
@@ -0,0 +1,18 @@
|
||||
ALTER TABLE knowledges ADD COLUMN tag_id VARCHAR(36);
|
||||
CREATE INDEX IF NOT EXISTS idx_knowledges_tag ON knowledges(tag_id);
|
||||
|
||||
UPDATE knowledges
|
||||
SET tag_id = (
|
||||
SELECT ktr.tag_id
|
||||
FROM knowledge_tag_relations ktr
|
||||
WHERE ktr.knowledge_id = knowledges.id
|
||||
ORDER BY ktr.created_at ASC
|
||||
LIMIT 1
|
||||
)
|
||||
WHERE EXISTS (
|
||||
SELECT 1 FROM knowledge_tag_relations ktr WHERE ktr.knowledge_id = knowledges.id
|
||||
);
|
||||
|
||||
DROP INDEX IF EXISTS idx_ktr_tag;
|
||||
DROP INDEX IF EXISTS idx_ktr_knowledge;
|
||||
DROP TABLE IF EXISTS knowledge_tag_relations;
|
||||
@@ -0,0 +1,25 @@
|
||||
-- Mirrors versioned migration 000063_knowledge_multi_tags:
|
||||
-- many-to-many join table between knowledges and knowledge_tags.
|
||||
|
||||
CREATE TABLE IF NOT EXISTS knowledge_tag_relations (
|
||||
knowledge_id VARCHAR(36) NOT NULL,
|
||||
tag_id VARCHAR(36) NOT NULL,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (knowledge_id, tag_id)
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_ktr_knowledge
|
||||
ON knowledge_tag_relations (knowledge_id);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_ktr_tag
|
||||
ON knowledge_tag_relations (tag_id);
|
||||
|
||||
-- Migrate existing single-tag data into the join table.
|
||||
INSERT INTO knowledge_tag_relations (knowledge_id, tag_id, created_at)
|
||||
SELECT id, tag_id, updated_at
|
||||
FROM knowledges
|
||||
WHERE tag_id IS NOT NULL AND tag_id != ''
|
||||
AND deleted_at IS NULL;
|
||||
|
||||
DROP INDEX IF EXISTS idx_knowledges_tag;
|
||||
ALTER TABLE knowledges DROP COLUMN tag_id;
|
||||
@@ -0,0 +1,9 @@
|
||||
DROP INDEX IF EXISTS idx_mcp_oauth_tokens_principal;
|
||||
DROP INDEX IF EXISTS idx_mcp_oauth_tokens_tenant_principal_svc;
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS idx_mcp_oauth_tokens_tenant_user_svc
|
||||
ON mcp_oauth_tokens(tenant_id, user_id, service_id);
|
||||
|
||||
ALTER TABLE mcp_oauth_tokens DROP COLUMN principal_id;
|
||||
ALTER TABLE mcp_oauth_tokens DROP COLUMN principal_type;
|
||||
ALTER TABLE tenants DROP COLUMN api_principal_config;
|
||||
@@ -0,0 +1,22 @@
|
||||
-- Mirrors versioned migration 000064_principal_model:
|
||||
-- principal identity for MCP OAuth tokens and tenant API config.
|
||||
|
||||
ALTER TABLE tenants ADD COLUMN api_principal_config TEXT;
|
||||
|
||||
ALTER TABLE mcp_oauth_tokens ADD COLUMN principal_type VARCHAR(32);
|
||||
ALTER TABLE mcp_oauth_tokens ADD COLUMN principal_id VARCHAR(512);
|
||||
|
||||
UPDATE mcp_oauth_tokens
|
||||
SET principal_type = 'web_user',
|
||||
principal_id = user_id
|
||||
WHERE (principal_type IS NULL OR principal_type = '')
|
||||
AND user_id IS NOT NULL
|
||||
AND user_id <> '';
|
||||
|
||||
DROP INDEX IF EXISTS idx_mcp_oauth_tokens_tenant_user_svc;
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS idx_mcp_oauth_tokens_tenant_principal_svc
|
||||
ON mcp_oauth_tokens(tenant_id, principal_type, principal_id, service_id);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_mcp_oauth_tokens_principal
|
||||
ON mcp_oauth_tokens(principal_type, principal_id);
|
||||
@@ -0,0 +1 @@
|
||||
ALTER TABLE messages DROP COLUMN usage;
|
||||
@@ -0,0 +1,4 @@
|
||||
-- Mirrors versioned migration 000085_message_usage:
|
||||
-- per-turn LLM token usage persisted with the assistant message.
|
||||
|
||||
ALTER TABLE messages ADD COLUMN usage TEXT;
|
||||
@@ -0,0 +1 @@
|
||||
ALTER TABLE mcp_tool_approvals DROP COLUMN enabled;
|
||||
@@ -0,0 +1,2 @@
|
||||
-- Per-tool MCP enable/disable policy. Missing rows are treated as enabled.
|
||||
ALTER TABLE mcp_tool_approvals ADD COLUMN enabled BOOLEAN NOT NULL DEFAULT 1;
|
||||
@@ -0,0 +1,3 @@
|
||||
DROP TABLE IF EXISTS browser_task_interruptions;
|
||||
DROP TABLE IF EXISTS browser_pairings;
|
||||
DROP TABLE IF EXISTS browser_devices;
|
||||
@@ -0,0 +1,33 @@
|
||||
-- Browser authorization is durable; live browser processes remain ephemeral.
|
||||
CREATE TABLE browser_devices (
|
||||
scope_key VARCHAR(32) PRIMARY KEY,
|
||||
id VARCHAR(32) NOT NULL UNIQUE,
|
||||
tenant BIGINT NOT NULL,
|
||||
"user" VARCHAR(36) NOT NULL,
|
||||
label VARCHAR(100) NOT NULL,
|
||||
token_hash VARCHAR(64) NOT NULL UNIQUE,
|
||||
previous_hash VARCHAR(64) NOT NULL DEFAULT '',
|
||||
previous_until DATETIME NOT NULL,
|
||||
expires_at DATETIME NOT NULL,
|
||||
renew_after DATETIME NOT NULL,
|
||||
created_at DATETIME NOT NULL,
|
||||
last_seen_at DATETIME NOT NULL,
|
||||
revoked_at DATETIME,
|
||||
owner VARCHAR(32) NOT NULL DEFAULT '',
|
||||
owner_url VARCHAR(500) NOT NULL DEFAULT '',
|
||||
lease_key VARCHAR(32) NOT NULL DEFAULT '',
|
||||
lease_until DATETIME NOT NULL
|
||||
);
|
||||
CREATE TABLE browser_pairings (
|
||||
scope_key VARCHAR(32) PRIMARY KEY,
|
||||
token_hash VARCHAR(64) NOT NULL UNIQUE,
|
||||
tenant BIGINT NOT NULL,
|
||||
"user" VARCHAR(36) NOT NULL,
|
||||
expires_at DATETIME NOT NULL
|
||||
);
|
||||
CREATE INDEX browser_pairings_expiry ON browser_pairings(expires_at);
|
||||
CREATE TABLE browser_task_interruptions (
|
||||
scope_key VARCHAR(32) NOT NULL,
|
||||
session VARCHAR(36) NOT NULL,
|
||||
PRIMARY KEY (scope_key, session)
|
||||
);
|
||||
@@ -0,0 +1,4 @@
|
||||
DROP INDEX IF EXISTS idx_memory_replaces;
|
||||
DROP TABLE IF EXISTS memory_extraction_sessions;
|
||||
ALTER TABLE memory_items DROP COLUMN replaces_id;
|
||||
ALTER TABLE memory_subjects DROP COLUMN extraction_state;
|
||||
@@ -0,0 +1,61 @@
|
||||
-- Per-session extraction progress and deferred proposal replacement.
|
||||
ALTER TABLE memory_subjects ADD COLUMN extraction_state TEXT;
|
||||
ALTER TABLE memory_items ADD COLUMN replaces_id VARCHAR(36) NOT NULL DEFAULT '';
|
||||
|
||||
-- Progress is an indexed row per conversation; subject rows only hold a lease.
|
||||
CREATE TABLE memory_extraction_sessions (
|
||||
tenant_id BIGINT NOT NULL,
|
||||
subject_id VARCHAR(512) NOT NULL,
|
||||
session_id VARCHAR(36) NOT NULL,
|
||||
revision BIGINT NOT NULL DEFAULT 0,
|
||||
cursor_at DATETIME, cursor_id VARCHAR(36) NOT NULL DEFAULT '',
|
||||
pending BOOLEAN NOT NULL DEFAULT false,
|
||||
failure_count INTEGER NOT NULL DEFAULT 0,
|
||||
failure_code VARCHAR(64) NOT NULL DEFAULT '',
|
||||
failed_from_at DATETIME, failed_from_id VARCHAR(36) NOT NULL DEFAULT '',
|
||||
failed_to_at DATETIME, failed_to_id VARCHAR(36) NOT NULL DEFAULT '',
|
||||
failed_at DATETIME, updated_at DATETIME NOT NULL,
|
||||
PRIMARY KEY (tenant_id, subject_id, session_id)
|
||||
);
|
||||
CREATE INDEX idx_memory_extraction_pending ON memory_extraction_sessions (tenant_id, subject_id, pending, updated_at, session_id);
|
||||
CREATE INDEX idx_memory_replaces ON memory_items (tenant_id, subject_id, replaces_id, status);
|
||||
|
||||
-- Recover the old active record when a legacy pending inference prematurely
|
||||
-- superseded it. Keep an explicit target so confirmation can still replace it.
|
||||
UPDATE memory_items
|
||||
SET replaces_id = (
|
||||
SELECT old.id FROM memory_items AS old
|
||||
WHERE old.tenant_id = memory_items.tenant_id
|
||||
AND old.subject_id = memory_items.subject_id
|
||||
AND old.superseded_by = memory_items.id AND old.status = 'superseded'
|
||||
ORDER BY old.valid_from DESC, old.id DESC LIMIT 1
|
||||
)
|
||||
WHERE status = 'pending' AND EXISTS (
|
||||
SELECT 1 FROM memory_items AS old
|
||||
WHERE old.tenant_id = memory_items.tenant_id
|
||||
AND old.subject_id = memory_items.subject_id
|
||||
AND old.superseded_by = memory_items.id AND old.status = 'superseded'
|
||||
);
|
||||
|
||||
-- Restore at most one record per key, and never displace a newer active fact.
|
||||
UPDATE memory_items
|
||||
SET status = 'active', invalid_at = NULL, superseded_by = ''
|
||||
WHERE status = 'superseded'
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM memory_items AS active
|
||||
WHERE active.tenant_id = memory_items.tenant_id
|
||||
AND active.subject_id = memory_items.subject_id
|
||||
AND active.normalized_key = memory_items.normalized_key AND active.status = 'active'
|
||||
)
|
||||
AND id = (
|
||||
SELECT old.id FROM memory_items AS old
|
||||
WHERE old.tenant_id = memory_items.tenant_id
|
||||
AND old.subject_id = memory_items.subject_id
|
||||
AND old.normalized_key = memory_items.normalized_key AND old.status = 'superseded'
|
||||
AND EXISTS (
|
||||
SELECT 1 FROM memory_items AS pending
|
||||
WHERE pending.tenant_id = old.tenant_id AND pending.subject_id = old.subject_id
|
||||
AND pending.status = 'pending' AND pending.replaces_id = old.id
|
||||
)
|
||||
ORDER BY old.valid_from DESC, old.id DESC LIMIT 1
|
||||
);
|
||||
@@ -0,0 +1 @@
|
||||
DROP INDEX IF EXISTS idx_mem_emb_search;
|
||||
@@ -0,0 +1,5 @@
|
||||
-- Mirror of versioned 000095. SQLite has no vector type, so ranking stays in
|
||||
-- the application here; what it can share is the index that keeps the read to
|
||||
-- one subject's vectors instead of the whole table.
|
||||
CREATE INDEX IF NOT EXISTS idx_mem_emb_search
|
||||
ON memory_item_embeddings (tenant_id, subject_id, model_id, dims);
|
||||
@@ -0,0 +1,2 @@
|
||||
-- Intentionally retain Stream mode: rollback must not re-enable unauthenticated message bodies.
|
||||
SELECT 1;
|
||||
@@ -0,0 +1,4 @@
|
||||
-- HTTP signatures do not authenticate message bodies.
|
||||
-- Operators must also enable Stream in the DingTalk developer console.
|
||||
UPDATE im_channels SET mode = 'websocket', updated_at = CURRENT_TIMESTAMP
|
||||
WHERE platform = 'dingtalk' AND mode = 'webhook';
|
||||
@@ -0,0 +1,7 @@
|
||||
DROP INDEX IF EXISTS idx_sessions_parent_session_id;
|
||||
|
||||
ALTER TABLE sessions DROP COLUMN fork_bootstrap;
|
||||
ALTER TABLE sessions DROP COLUMN forked_from_message_id;
|
||||
ALTER TABLE sessions DROP COLUMN parent_session_id;
|
||||
|
||||
ALTER TABLE messages DROP COLUMN sandbox_checkpoint;
|
||||
@@ -0,0 +1,13 @@
|
||||
-- Mirrors versioned migration 000097_session_fork:
|
||||
-- session lineage plus the per-turn sandbox checkpoint used as a fork point.
|
||||
-- Existing Lite databases are already at version 13 and never replay 000000_init,
|
||||
-- so these columns must be added here.
|
||||
|
||||
ALTER TABLE sessions ADD COLUMN parent_session_id TEXT;
|
||||
ALTER TABLE sessions ADD COLUMN forked_from_message_id TEXT;
|
||||
ALTER TABLE sessions ADD COLUMN fork_bootstrap TEXT;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_sessions_parent_session_id
|
||||
ON sessions (parent_session_id);
|
||||
|
||||
ALTER TABLE messages ADD COLUMN sandbox_checkpoint TEXT;
|
||||
@@ -0,0 +1,2 @@
|
||||
DROP INDEX IF EXISTS idx_fork_snapshot_leases_created_at;
|
||||
DROP TABLE IF EXISTS fork_snapshot_leases;
|
||||
@@ -0,0 +1,12 @@
|
||||
-- Mirrors versioned migration 000098_fork_snapshot_lease:
|
||||
-- durable snapshot IDs taken before the forked session row is committed.
|
||||
|
||||
CREATE TABLE IF NOT EXISTS fork_snapshot_leases (
|
||||
snapshot_id TEXT PRIMARY KEY,
|
||||
tenant_id INTEGER NOT NULL DEFAULT 0,
|
||||
sandbox_config_id TEXT NOT NULL DEFAULT '',
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_fork_snapshot_leases_created_at
|
||||
ON fork_snapshot_leases (created_at);
|
||||
@@ -0,0 +1,3 @@
|
||||
CREATE INDEX IF NOT EXISTS idx_chunks_chunk_type ON chunks(chunk_type);
|
||||
CREATE INDEX IF NOT EXISTS idx_chunks_content_hash ON chunks(content_hash);
|
||||
CREATE INDEX IF NOT EXISTS idx_chunks_tenant_kg ON chunks(tenant_id, knowledge_id);
|
||||
@@ -0,0 +1,4 @@
|
||||
-- Drop chunks indexes that only slow down writes (see versioned/000100).
|
||||
DROP INDEX IF EXISTS idx_chunks_chunk_type;
|
||||
DROP INDEX IF EXISTS idx_chunks_content_hash;
|
||||
DROP INDEX IF EXISTS idx_chunks_tenant_kg;
|
||||
@@ -0,0 +1,3 @@
|
||||
ALTER TABLE knowledge_bases DROP COLUMN generated_profile;
|
||||
ALTER TABLE knowledge_bases DROP COLUMN profile_config;
|
||||
ALTER TABLE knowledges DROP COLUMN profile;
|
||||
@@ -0,0 +1,3 @@
|
||||
ALTER TABLE knowledges ADD COLUMN profile TEXT;
|
||||
ALTER TABLE knowledge_bases ADD COLUMN profile_config TEXT;
|
||||
ALTER TABLE knowledge_bases ADD COLUMN generated_profile TEXT;
|
||||
@@ -0,0 +1,4 @@
|
||||
DROP INDEX IF EXISTS idx_mcp_endpoints_deleted;
|
||||
DROP INDEX IF EXISTS idx_mcp_endpoints_token_hash;
|
||||
DROP INDEX IF EXISTS idx_mcp_endpoints_tenant;
|
||||
DROP TABLE IF EXISTS mcp_endpoints;
|
||||
@@ -0,0 +1,27 @@
|
||||
-- Mirrors versioned migration 000102_mcp_endpoints:
|
||||
-- workspace-published MCP server endpoints with per-endpoint token, KB scope
|
||||
-- and tool allowlist.
|
||||
|
||||
CREATE TABLE IF NOT EXISTS mcp_endpoints (
|
||||
id VARCHAR(36) PRIMARY KEY,
|
||||
tenant_id INTEGER NOT NULL,
|
||||
name VARCHAR(255) NOT NULL DEFAULT '',
|
||||
description TEXT NOT NULL DEFAULT '',
|
||||
enabled INTEGER NOT NULL DEFAULT 1,
|
||||
token_hash VARCHAR(64) NOT NULL DEFAULT '',
|
||||
token_hint VARCHAR(16) NOT NULL DEFAULT '',
|
||||
knowledge_base_ids TEXT NOT NULL DEFAULT '[]',
|
||||
tools TEXT NOT NULL DEFAULT '[]',
|
||||
default_agent_id VARCHAR(36) NOT NULL DEFAULT '',
|
||||
rate_limit_per_minute INTEGER NOT NULL DEFAULT 60,
|
||||
last_used_at DATETIME,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
deleted_at DATETIME
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_mcp_endpoints_tenant ON mcp_endpoints (tenant_id);
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS idx_mcp_endpoints_token_hash
|
||||
ON mcp_endpoints (token_hash)
|
||||
WHERE token_hash != '' AND deleted_at IS NULL;
|
||||
CREATE INDEX IF NOT EXISTS idx_mcp_endpoints_deleted ON mcp_endpoints (deleted_at) WHERE deleted_at IS NOT NULL;
|
||||
@@ -0,0 +1,27 @@
|
||||
-- Restore messages.artifacts from the table before dropping it, so files
|
||||
-- generated after the upgrade survive a rollback. created_at is normalised to
|
||||
-- RFC 3339 so Go can decode the restored JSON; mod_time is already RFC 3339.
|
||||
UPDATE messages
|
||||
SET artifacts = (
|
||||
SELECT json_group_array(json(item))
|
||||
FROM (
|
||||
SELECT json_object(
|
||||
'url', url,
|
||||
'file_name', file_name,
|
||||
'file_type', file_type,
|
||||
'file_size', file_size,
|
||||
'content_hash', content_hash,
|
||||
'source_path', source_path,
|
||||
'mod_time', NULLIF(mod_time, ''),
|
||||
'created_at', strftime('%Y-%m-%dT%H:%M:%fZ', created_at)
|
||||
) AS item
|
||||
FROM message_artifacts
|
||||
WHERE message_artifacts.message_id = messages.id
|
||||
ORDER BY position
|
||||
)
|
||||
)
|
||||
WHERE id IN (SELECT message_id FROM message_artifacts);
|
||||
|
||||
DROP INDEX IF EXISTS idx_message_artifacts_session_created;
|
||||
DROP INDEX IF EXISTS idx_message_artifacts_message_position;
|
||||
DROP TABLE IF EXISTS message_artifacts;
|
||||
@@ -0,0 +1,59 @@
|
||||
-- Mirrors versioned migration 000103_message_artifacts_table:
|
||||
-- skill-generated files move out of messages.artifacts into their own table,
|
||||
-- which becomes the only source of truth. After the backfill the legacy column
|
||||
-- is cleared (message loads still SELECT *) but kept; the down migration
|
||||
-- rebuilds it from the table.
|
||||
|
||||
CREATE TABLE IF NOT EXISTS message_artifacts (
|
||||
id VARCHAR(36) PRIMARY KEY,
|
||||
session_id VARCHAR(36) NOT NULL,
|
||||
message_id VARCHAR(36) NOT NULL,
|
||||
position INTEGER NOT NULL,
|
||||
url TEXT NOT NULL DEFAULT '',
|
||||
file_name TEXT NOT NULL DEFAULT '',
|
||||
file_type VARCHAR(32) NOT NULL DEFAULT '',
|
||||
file_size INTEGER NOT NULL DEFAULT 0,
|
||||
content_hash VARCHAR(64) NOT NULL DEFAULT '',
|
||||
source_path TEXT NOT NULL DEFAULT '',
|
||||
mod_time VARCHAR(64) NOT NULL DEFAULT '',
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS idx_message_artifacts_message_position
|
||||
ON message_artifacts (message_id, position);
|
||||
CREATE INDEX IF NOT EXISTS idx_message_artifacts_session_created
|
||||
ON message_artifacts (session_id, created_at);
|
||||
|
||||
-- mod_time is kept as the RFC 3339 text Go wrote (nanosecond precision; the
|
||||
-- collector matches files on it). created_at is an ORDER BY key compared as
|
||||
-- text, so it is normalised to UTC in the layout the repository writes.
|
||||
INSERT OR IGNORE INTO message_artifacts (
|
||||
id, session_id, message_id, position, url, file_name, file_type, file_size,
|
||||
content_hash, source_path, mod_time, created_at
|
||||
)
|
||||
SELECT
|
||||
lower(hex(randomblob(4)) || '-' || hex(randomblob(2)) || '-' || hex(randomblob(2)) || '-' ||
|
||||
hex(randomblob(2)) || '-' || hex(randomblob(6))),
|
||||
m.session_id,
|
||||
m.id,
|
||||
CAST(a.key AS INTEGER),
|
||||
COALESCE(json_extract(a.value, '$.url'), ''),
|
||||
COALESCE(json_extract(a.value, '$.file_name'), ''),
|
||||
substr(COALESCE(json_extract(a.value, '$.file_type'), ''), 1, 32),
|
||||
COALESCE(CAST(json_extract(a.value, '$.file_size') AS INTEGER), 0),
|
||||
substr(COALESCE(json_extract(a.value, '$.content_hash'), ''), 1, 64),
|
||||
COALESCE(json_extract(a.value, '$.source_path'), ''),
|
||||
substr(COALESCE(json_extract(a.value, '$.mod_time'), ''), 1, 64),
|
||||
COALESCE(
|
||||
strftime('%Y-%m-%d %H:%M:%f+00:00', NULLIF(json_extract(a.value, '$.created_at'), '')),
|
||||
strftime('%Y-%m-%d %H:%M:%f+00:00', m.created_at),
|
||||
strftime('%Y-%m-%d %H:%M:%f+00:00', 'now')
|
||||
)
|
||||
FROM messages m, json_each(
|
||||
CASE WHEN json_valid(m.artifacts) AND json_type(m.artifacts) = 'array' THEN m.artifacts ELSE '[]' END
|
||||
) a
|
||||
WHERE a.type = 'object';
|
||||
|
||||
-- Only rows that carried artifacts; '[]' rows are left as they are.
|
||||
UPDATE messages SET artifacts = NULL
|
||||
WHERE artifacts IS NOT NULL AND artifacts <> '[]';
|
||||
@@ -0,0 +1 @@
|
||||
ALTER TABLE messages DROP COLUMN context_checkpoint;
|
||||
@@ -0,0 +1,3 @@
|
||||
-- Mirrors versioned migration 000105_message_context_checkpoint: the agent
|
||||
-- compaction summary persisted on the last turn it covers.
|
||||
ALTER TABLE messages ADD COLUMN context_checkpoint TEXT;
|
||||
@@ -0,0 +1 @@
|
||||
DROP INDEX IF EXISTS idx_messages_session_created_id;
|
||||
@@ -0,0 +1,4 @@
|
||||
-- Mirrors versioned migration 000106_messages_session_created_index: the index
|
||||
-- behind agent history's backwards read and the newest-checkpoint lookup.
|
||||
CREATE INDEX IF NOT EXISTS idx_messages_session_created_id
|
||||
ON messages (session_id, created_at DESC, id DESC);
|
||||
@@ -0,0 +1,4 @@
|
||||
DROP INDEX IF EXISTS idx_message_artifacts_url_live;
|
||||
DROP INDEX IF EXISTS idx_message_artifacts_session_live;
|
||||
|
||||
ALTER TABLE message_artifacts DROP COLUMN deleted_at;
|
||||
@@ -0,0 +1,12 @@
|
||||
-- Mirrors versioned migration 000107_message_artifacts_deleted_at: user-deleted
|
||||
-- artifacts become tombstones so positions stay stable and the collector does
|
||||
-- not re-attach them from the sandbox.
|
||||
ALTER TABLE message_artifacts ADD COLUMN deleted_at DATETIME;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_message_artifacts_session_live
|
||||
ON message_artifacts (session_id, created_at)
|
||||
WHERE deleted_at IS NULL;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_message_artifacts_url_live
|
||||
ON message_artifacts (url)
|
||||
WHERE deleted_at IS NULL;
|
||||
@@ -0,0 +1 @@
|
||||
ALTER TABLE sessions DROP COLUMN sandbox_config_tenant_id;
|
||||
@@ -0,0 +1,8 @@
|
||||
-- Mirrors versioned migration 000108_session_sandbox_config_tenant: the pinned
|
||||
-- sandbox config resolves in exactly one workspace, so the pin records which.
|
||||
--
|
||||
-- No backfill here. Lite has no shared spaces (see docs/LITE.md), so a session
|
||||
-- can never be pinned to another workspace's config; the column exists only so
|
||||
-- the shared Session model maps on both engines. INTEGER on SQLite is 64-bit
|
||||
-- and matches Postgres BIGINT used in 000108.
|
||||
ALTER TABLE sessions ADD COLUMN sandbox_config_tenant_id INTEGER NOT NULL DEFAULT 0;
|
||||
@@ -0,0 +1,15 @@
|
||||
DROP INDEX IF EXISTS idx_user_env_var_config;
|
||||
DROP INDEX IF EXISTS idx_user_env_var_skill;
|
||||
DROP INDEX IF EXISTS uq_user_env_var;
|
||||
DROP TABLE IF EXISTS tenant_user_env_vars;
|
||||
|
||||
DROP INDEX IF EXISTS uq_tenant_skill_catalog_name;
|
||||
DROP TABLE IF EXISTS tenant_skill_catalog;
|
||||
|
||||
DROP INDEX IF EXISTS idx_tenant_skill_snapshots_state;
|
||||
DROP INDEX IF EXISTS idx_tenant_skill_snapshots_config;
|
||||
DROP TABLE IF EXISTS tenant_skill_snapshots;
|
||||
|
||||
DROP INDEX IF EXISTS idx_tenant_skills_catalog;
|
||||
DROP INDEX IF EXISTS uq_tenant_skills_config_name;
|
||||
DROP TABLE IF EXISTS tenant_skills;
|
||||
@@ -0,0 +1,95 @@
|
||||
-- Mirrors versioned 000086–000090 and 000104:
|
||||
-- tenant_skills, snapshot ledger, catalog, and per-principal env vars.
|
||||
-- SQLite never received these tables; Lite shell_exec then failed with
|
||||
-- "no such table: tenant_user_env_vars" when resolving skill credentials.
|
||||
-- New tables are created in their current shape, so ALTER steps are skipped.
|
||||
-- Catalog backfill from existing installs is omitted: this table set is new
|
||||
-- on SQLite, so there are no tenant_skills rows to collapse.
|
||||
|
||||
CREATE TABLE IF NOT EXISTS tenant_skills (
|
||||
id VARCHAR(36) PRIMARY KEY,
|
||||
tenant_id INTEGER NOT NULL,
|
||||
sandbox_config_id VARCHAR(36) NOT NULL,
|
||||
catalog_id VARCHAR(36),
|
||||
name VARCHAR(255) NOT NULL,
|
||||
version VARCHAR(64),
|
||||
description TEXT,
|
||||
instructions TEXT,
|
||||
bundle_ref VARCHAR(1024),
|
||||
bundle_sha256 VARCHAR(64),
|
||||
enabled INTEGER NOT NULL DEFAULT 1,
|
||||
installed_snapshot_id VARCHAR(255),
|
||||
install_session_id VARCHAR(36),
|
||||
install_message_id VARCHAR(36),
|
||||
envs TEXT,
|
||||
served TEXT,
|
||||
status VARCHAR(32) NOT NULL,
|
||||
error TEXT,
|
||||
installing_since DATETIME,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
deleted_at DATETIME
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS uq_tenant_skills_config_name
|
||||
ON tenant_skills (sandbox_config_id, name) WHERE deleted_at IS NULL;
|
||||
CREATE INDEX IF NOT EXISTS idx_tenant_skills_catalog
|
||||
ON tenant_skills (catalog_id);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS tenant_skill_snapshots (
|
||||
id VARCHAR(36) PRIMARY KEY,
|
||||
tenant_id INTEGER NOT NULL,
|
||||
sandbox_config_id VARCHAR(36) NOT NULL,
|
||||
skill_id VARCHAR(36),
|
||||
snapshot_id VARCHAR(255),
|
||||
parent_snapshot_id VARCHAR(255),
|
||||
generation INTEGER NOT NULL DEFAULT 0,
|
||||
planned_name VARCHAR(255),
|
||||
trigger VARCHAR(16) NOT NULL,
|
||||
state VARCHAR(16) NOT NULL,
|
||||
superseded_at DATETIME,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_tenant_skill_snapshots_config
|
||||
ON tenant_skill_snapshots (sandbox_config_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_tenant_skill_snapshots_state
|
||||
ON tenant_skill_snapshots (state);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS tenant_skill_catalog (
|
||||
id VARCHAR(36) PRIMARY KEY,
|
||||
tenant_id INTEGER NOT NULL,
|
||||
name VARCHAR(255) NOT NULL,
|
||||
version VARCHAR(64),
|
||||
description TEXT,
|
||||
instructions TEXT,
|
||||
bundle_ref VARCHAR(1024),
|
||||
bundle_sha256 VARCHAR(64),
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
deleted_at DATETIME
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS uq_tenant_skill_catalog_name
|
||||
ON tenant_skill_catalog (tenant_id, name) WHERE deleted_at IS NULL;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS tenant_user_env_vars (
|
||||
id VARCHAR(36) PRIMARY KEY,
|
||||
tenant_id INTEGER NOT NULL,
|
||||
principal_type VARCHAR(32) NOT NULL,
|
||||
principal_id VARCHAR(512) NOT NULL,
|
||||
sandbox_config_id VARCHAR(36) NOT NULL,
|
||||
skill_id VARCHAR(36) NOT NULL DEFAULT '',
|
||||
name VARCHAR(255) NOT NULL,
|
||||
value TEXT,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS uq_user_env_var
|
||||
ON tenant_user_env_vars (tenant_id, principal_type, principal_id, sandbox_config_id, skill_id, name);
|
||||
CREATE INDEX IF NOT EXISTS idx_user_env_var_skill
|
||||
ON tenant_user_env_vars (tenant_id, skill_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_user_env_var_config
|
||||
ON tenant_user_env_vars (tenant_id, sandbox_config_id);
|
||||
@@ -0,0 +1 @@
|
||||
ALTER TABLE sessions DROP COLUMN host_workspace_dir;
|
||||
@@ -0,0 +1,6 @@
|
||||
-- Mirrors versioned migration 000109_session_host_workspace_dir:
|
||||
-- Lite host-sandbox binding: the user-selected project directory this session
|
||||
-- operates in. NULL/empty means the session gets an auto-allocated workspace.
|
||||
-- Written once at creation and never updated.
|
||||
|
||||
ALTER TABLE sessions ADD COLUMN host_workspace_dir TEXT;
|
||||
@@ -0,0 +1 @@
|
||||
ALTER TABLE im_channels DROP COLUMN locale;
|
||||
@@ -0,0 +1 @@
|
||||
ALTER TABLE im_channels ADD COLUMN locale VARCHAR(16) NOT NULL DEFAULT '';
|
||||
@@ -0,0 +1 @@
|
||||
DROP TABLE IF EXISTS model_catalog_configs;
|
||||
@@ -0,0 +1,11 @@
|
||||
CREATE TABLE model_catalog_configs (
|
||||
id INTEGER PRIMARY KEY,
|
||||
version BIGINT NOT NULL DEFAULT 0,
|
||||
overlay TEXT NOT NULL,
|
||||
history TEXT NOT NULL,
|
||||
updated_by VARCHAR(36) NOT NULL DEFAULT '',
|
||||
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
CHECK (id = 1)
|
||||
);
|
||||
INSERT INTO model_catalog_configs (id, version, overlay, history)
|
||||
VALUES (1, 0, '{"providers":{}}', '[]');
|
||||
@@ -0,0 +1,5 @@
|
||||
DROP TRIGGER IF EXISTS trg_chunk_images_insert;
|
||||
DROP TRIGGER IF EXISTS trg_chunk_images_patch;
|
||||
DROP TRIGGER IF EXISTS trg_chunk_images_update;
|
||||
DROP TRIGGER IF EXISTS trg_chunk_images_delete;
|
||||
DROP TABLE IF EXISTS chunk_images;
|
||||
@@ -0,0 +1,112 @@
|
||||
-- Migration 000032: chunk_images, the image gallery's projection of image_info
|
||||
--
|
||||
-- SQLite twin of versioned migration 000113; see it for the rationale. One row
|
||||
-- per image_info entry with caption, OCR text and observed attributes as
|
||||
-- columns, kept in step with chunks by triggers, so the gallery no longer
|
||||
-- parses every image chunk's JSON on each request. Copies of one image stay
|
||||
-- separate rows; the gallery query picks the copy on the most recently updated
|
||||
-- chunk with an indexed anti-join.
|
||||
|
||||
CREATE TABLE IF NOT EXISTS chunk_images (
|
||||
chunk_id VARCHAR(36) NOT NULL,
|
||||
image_index INTEGER NOT NULL,
|
||||
tenant_id BIGINT NOT NULL,
|
||||
knowledge_base_id VARCHAR(36) NOT NULL,
|
||||
knowledge_id VARCHAR(36) NOT NULL,
|
||||
chunk_type VARCHAR(20) NOT NULL DEFAULT '',
|
||||
image_key TEXT NOT NULL,
|
||||
url TEXT NOT NULL DEFAULT '',
|
||||
original_url TEXT NOT NULL DEFAULT '',
|
||||
caption TEXT NOT NULL DEFAULT '',
|
||||
ocr_text TEXT NOT NULL DEFAULT '',
|
||||
attrs TEXT NOT NULL DEFAULT '{}',
|
||||
is_enabled BOOLEAN NOT NULL DEFAULT 1,
|
||||
status INTEGER NOT NULL DEFAULT 0,
|
||||
created_at DATETIME,
|
||||
updated_at DATETIME,
|
||||
PRIMARY KEY (chunk_id, image_index)
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_chunk_images_listing
|
||||
ON chunk_images(knowledge_base_id, tenant_id, created_at, chunk_id, image_index);
|
||||
CREATE INDEX IF NOT EXISTS idx_chunk_images_copies
|
||||
ON chunk_images(knowledge_base_id, tenant_id, image_key, updated_at, chunk_id, image_index);
|
||||
|
||||
CREATE TRIGGER IF NOT EXISTS trg_chunk_images_insert AFTER INSERT ON chunks
|
||||
WHEN NEW.image_info LIKE '[%'
|
||||
BEGIN
|
||||
INSERT INTO chunk_images (chunk_id, image_index, tenant_id, knowledge_base_id, knowledge_id, chunk_type, image_key, url, original_url, caption, ocr_text, attrs, is_enabled, status, created_at, updated_at)
|
||||
SELECT NEW.id, CAST(e.key AS INTEGER), NEW.tenant_id, NEW.knowledge_base_id, NEW.knowledge_id,
|
||||
COALESCE(NEW.chunk_type, ''),
|
||||
COALESCE(NULLIF(json_extract(e.value, '$.url'), ''), NULLIF(json_extract(e.value, '$.original_url'), ''),
|
||||
NEW.id || '#' || e.key),
|
||||
COALESCE(json_extract(e.value, '$.url'), ''), COALESCE(json_extract(e.value, '$.original_url'), ''),
|
||||
COALESCE(json_extract(e.value, '$.caption'), ''), COALESCE(json_extract(e.value, '$.ocr_text'), ''),
|
||||
CASE WHEN json_type(e.value, '$.attrs.attrs') = 'object'
|
||||
THEN json_extract(e.value, '$.attrs.attrs') ELSE '{}' END,
|
||||
NEW.is_enabled, COALESCE(NEW.status, 0), NEW.created_at, NEW.updated_at
|
||||
FROM json_each(CASE WHEN json_valid(NEW.image_info) AND json_type(NEW.image_info) = 'array' THEN NEW.image_info ELSE '[]' END) AS e
|
||||
WHERE NEW.deleted_at IS NULL AND e.type = 'object';
|
||||
END;
|
||||
|
||||
-- An update that leaves the images alone (status, enabled flag, timestamps)
|
||||
-- patches the rows in place; any other change to a column the projection
|
||||
-- copies replaces the chunk's rows.
|
||||
CREATE TRIGGER IF NOT EXISTS trg_chunk_images_patch AFTER UPDATE ON chunks
|
||||
WHEN NEW.image_info LIKE '[%' AND OLD.deleted_at IS NULL AND NEW.deleted_at IS NULL
|
||||
AND OLD.image_info IS NEW.image_info
|
||||
AND OLD.tenant_id IS NEW.tenant_id
|
||||
AND OLD.knowledge_base_id IS NEW.knowledge_base_id
|
||||
AND OLD.knowledge_id IS NEW.knowledge_id
|
||||
AND OLD.chunk_type IS NEW.chunk_type
|
||||
AND (OLD.is_enabled IS NOT NEW.is_enabled OR OLD.status IS NOT NEW.status
|
||||
OR OLD.created_at IS NOT NEW.created_at OR OLD.updated_at IS NOT NEW.updated_at)
|
||||
BEGIN
|
||||
UPDATE chunk_images
|
||||
SET is_enabled = NEW.is_enabled, status = COALESCE(NEW.status, 0),
|
||||
created_at = NEW.created_at, updated_at = NEW.updated_at
|
||||
WHERE chunk_id = NEW.id;
|
||||
END;
|
||||
|
||||
CREATE TRIGGER IF NOT EXISTS trg_chunk_images_update AFTER UPDATE ON chunks
|
||||
WHEN (OLD.image_info LIKE '[%' OR NEW.image_info LIKE '[%') AND NOT (OLD.deleted_at IS NULL AND NEW.deleted_at IS NULL
|
||||
AND OLD.image_info IS NEW.image_info
|
||||
AND OLD.tenant_id IS NEW.tenant_id
|
||||
AND OLD.knowledge_base_id IS NEW.knowledge_base_id
|
||||
AND OLD.knowledge_id IS NEW.knowledge_id
|
||||
AND OLD.chunk_type IS NEW.chunk_type)
|
||||
BEGIN
|
||||
DELETE FROM chunk_images WHERE chunk_id = OLD.id;
|
||||
INSERT INTO chunk_images (chunk_id, image_index, tenant_id, knowledge_base_id, knowledge_id, chunk_type, image_key, url, original_url, caption, ocr_text, attrs, is_enabled, status, created_at, updated_at)
|
||||
SELECT NEW.id, CAST(e.key AS INTEGER), NEW.tenant_id, NEW.knowledge_base_id, NEW.knowledge_id,
|
||||
COALESCE(NEW.chunk_type, ''),
|
||||
COALESCE(NULLIF(json_extract(e.value, '$.url'), ''), NULLIF(json_extract(e.value, '$.original_url'), ''),
|
||||
NEW.id || '#' || e.key),
|
||||
COALESCE(json_extract(e.value, '$.url'), ''), COALESCE(json_extract(e.value, '$.original_url'), ''),
|
||||
COALESCE(json_extract(e.value, '$.caption'), ''), COALESCE(json_extract(e.value, '$.ocr_text'), ''),
|
||||
CASE WHEN json_type(e.value, '$.attrs.attrs') = 'object'
|
||||
THEN json_extract(e.value, '$.attrs.attrs') ELSE '{}' END,
|
||||
NEW.is_enabled, COALESCE(NEW.status, 0), NEW.created_at, NEW.updated_at
|
||||
FROM json_each(CASE WHEN json_valid(NEW.image_info) AND json_type(NEW.image_info) = 'array' THEN NEW.image_info ELSE '[]' END) AS e
|
||||
WHERE NEW.deleted_at IS NULL AND e.type = 'object';
|
||||
END;
|
||||
|
||||
CREATE TRIGGER IF NOT EXISTS trg_chunk_images_delete AFTER DELETE ON chunks
|
||||
WHEN OLD.image_info LIKE '[%'
|
||||
BEGIN
|
||||
DELETE FROM chunk_images WHERE chunk_id = OLD.id;
|
||||
END;
|
||||
|
||||
-- Backfill every live image chunk.
|
||||
INSERT OR IGNORE INTO chunk_images (chunk_id, image_index, tenant_id, knowledge_base_id, knowledge_id, chunk_type, image_key, url, original_url, caption, ocr_text, attrs, is_enabled, status, created_at, updated_at)
|
||||
SELECT c.id, CAST(e.key AS INTEGER), c.tenant_id, c.knowledge_base_id, c.knowledge_id,
|
||||
COALESCE(c.chunk_type, ''),
|
||||
COALESCE(NULLIF(json_extract(e.value, '$.url'), ''), NULLIF(json_extract(e.value, '$.original_url'), ''),
|
||||
c.id || '#' || e.key),
|
||||
COALESCE(json_extract(e.value, '$.url'), ''), COALESCE(json_extract(e.value, '$.original_url'), ''),
|
||||
COALESCE(json_extract(e.value, '$.caption'), ''), COALESCE(json_extract(e.value, '$.ocr_text'), ''),
|
||||
CASE WHEN json_type(e.value, '$.attrs.attrs') = 'object'
|
||||
THEN json_extract(e.value, '$.attrs.attrs') ELSE '{}' END,
|
||||
c.is_enabled, COALESCE(c.status, 0), c.created_at, c.updated_at
|
||||
FROM chunks c, json_each(CASE WHEN json_valid(c.image_info) AND json_type(c.image_info) = 'array' THEN c.image_info ELSE '[]' END) AS e
|
||||
WHERE c.deleted_at IS NULL AND e.type = 'object' AND c.image_info LIKE '[%';
|
||||
@@ -0,0 +1 @@
|
||||
ALTER TABLE chunks DROP COLUMN source_locators;
|
||||
@@ -0,0 +1,2 @@
|
||||
-- Positions of each chunk in its original file (see versioned/000114).
|
||||
ALTER TABLE chunks ADD COLUMN source_locators TEXT;
|
||||
@@ -0,0 +1,2 @@
|
||||
DROP TABLE IF EXISTS mcp_metadata;
|
||||
ALTER TABLE mcp_services DROP COLUMN usage_instructions;
|
||||
@@ -0,0 +1,15 @@
|
||||
ALTER TABLE mcp_services ADD COLUMN usage_instructions TEXT NOT NULL DEFAULT '';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS mcp_metadata (
|
||||
tenant_id INTEGER NOT NULL,
|
||||
service_id VARCHAR(36) NOT NULL REFERENCES mcp_services(id) ON DELETE CASCADE,
|
||||
principal VARCHAR(255) NOT NULL DEFAULT '',
|
||||
config_fingerprint VARCHAR(64) NOT NULL,
|
||||
tools TEXT NOT NULL,
|
||||
instructions TEXT NOT NULL DEFAULT '',
|
||||
server_name TEXT NOT NULL DEFAULT '',
|
||||
server_version TEXT NOT NULL DEFAULT '',
|
||||
server_description TEXT NOT NULL DEFAULT '',
|
||||
synced_at DATETIME NOT NULL,
|
||||
PRIMARY KEY (tenant_id, service_id, principal)
|
||||
);
|
||||
@@ -0,0 +1,2 @@
|
||||
-- Nothing to revert; see the up migration.
|
||||
SELECT 1;
|
||||
@@ -0,0 +1,13 @@
|
||||
-- Mirrors postgres migration 000116: an empty allowed_tools list now means
|
||||
-- no built-in tools, so smart-reasoning agents that stored one get the
|
||||
-- default tools (DefaultAllowedTools() as of this migration) written in.
|
||||
-- See the postgres migration for how this narrows an "all" knowledge base
|
||||
-- scope to the bases search_knowledge can use.
|
||||
UPDATE custom_agents
|
||||
SET config = json_set(
|
||||
config,
|
||||
'$.allowed_tools',
|
||||
json('["search_knowledge", "read_document", "list_documents", "search_conversations"]'))
|
||||
WHERE json_extract(config, '$.agent_mode') = 'smart-reasoning'
|
||||
AND json_type(config, '$.allowed_tools') = 'array'
|
||||
AND json_array_length(config, '$.allowed_tools') = 0;
|
||||
@@ -0,0 +1 @@
|
||||
DROP INDEX IF EXISTS idx_messages_live_attachments;
|
||||
@@ -0,0 +1,4 @@
|
||||
-- SQLite expands live references once per cleanup query. Limit that scan to
|
||||
-- live user messages and use session_id for the owning tenant/liveness join.
|
||||
CREATE INDEX IF NOT EXISTS idx_messages_live_attachments
|
||||
ON messages (session_id) WHERE role = 'user' AND deleted_at IS NULL;
|
||||
@@ -0,0 +1,10 @@
|
||||
ALTER TABLE messages DROP COLUMN run_state;
|
||||
|
||||
DROP INDEX IF EXISTS idx_agent_run_suspensions_session;
|
||||
DROP TABLE IF EXISTS agent_run_suspensions;
|
||||
|
||||
DROP INDEX IF EXISTS idx_agent_prompts_message;
|
||||
DROP INDEX IF EXISTS idx_agent_prompts_status_expires;
|
||||
DROP INDEX IF EXISTS idx_agent_prompts_status_lease;
|
||||
DROP INDEX IF EXISTS idx_agent_prompts_session_status;
|
||||
DROP TABLE IF EXISTS agent_prompts;
|
||||
@@ -0,0 +1,50 @@
|
||||
-- Mirrors versioned migration 000119_agent_prompts:
|
||||
-- persisted human-in-the-loop prompts and suspended agent run state.
|
||||
|
||||
CREATE TABLE IF NOT EXISTS agent_prompts (
|
||||
id TEXT PRIMARY KEY,
|
||||
tenant_id INTEGER NOT NULL,
|
||||
user_id TEXT NOT NULL DEFAULT '',
|
||||
session_id TEXT NOT NULL,
|
||||
assistant_message_id TEXT NOT NULL DEFAULT '',
|
||||
request_id TEXT NOT NULL DEFAULT '',
|
||||
kind TEXT NOT NULL,
|
||||
tool_call_id TEXT NOT NULL DEFAULT '',
|
||||
suspendable BOOLEAN NOT NULL DEFAULT 0,
|
||||
request TEXT,
|
||||
response TEXT,
|
||||
status TEXT NOT NULL,
|
||||
close_reason TEXT NOT NULL DEFAULT '',
|
||||
resolved_by TEXT NOT NULL DEFAULT '',
|
||||
resolved_at DATETIME,
|
||||
owner_instance TEXT NOT NULL DEFAULT '',
|
||||
lease_until DATETIME,
|
||||
expires_at DATETIME,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_agent_prompts_session_status
|
||||
ON agent_prompts (session_id, status);
|
||||
CREATE INDEX IF NOT EXISTS idx_agent_prompts_status_lease
|
||||
ON agent_prompts (status, lease_until);
|
||||
CREATE INDEX IF NOT EXISTS idx_agent_prompts_status_expires
|
||||
ON agent_prompts (status, expires_at);
|
||||
CREATE INDEX IF NOT EXISTS idx_agent_prompts_message
|
||||
ON agent_prompts (assistant_message_id);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS agent_run_suspensions (
|
||||
assistant_message_id TEXT PRIMARY KEY,
|
||||
tenant_id INTEGER NOT NULL,
|
||||
session_id TEXT NOT NULL,
|
||||
prompt_id TEXT NOT NULL,
|
||||
snapshot_version INTEGER NOT NULL,
|
||||
snapshot TEXT NOT NULL,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_agent_run_suspensions_session
|
||||
ON agent_run_suspensions (session_id);
|
||||
|
||||
ALTER TABLE messages ADD COLUMN run_state TEXT NOT NULL DEFAULT '';
|
||||
@@ -0,0 +1 @@
|
||||
ALTER TABLE tenants DROP COLUMN assistant_config;
|
||||
@@ -0,0 +1 @@
|
||||
ALTER TABLE tenants ADD COLUMN assistant_config TEXT;
|
||||
@@ -0,0 +1,2 @@
|
||||
DROP INDEX IF EXISTS idx_sessions_tenant_kind_user_updated;
|
||||
ALTER TABLE sessions DROP COLUMN kind;
|
||||
@@ -0,0 +1,8 @@
|
||||
ALTER TABLE sessions ADD COLUMN kind VARCHAR(32) NOT NULL DEFAULT '';
|
||||
|
||||
UPDATE sessions SET kind = 'assistant'
|
||||
WHERE CASE WHEN json_valid(agent_config) THEN json_extract(agent_config, '$.agent_id') END = 'builtin-academy-assistant';
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_sessions_tenant_kind_user_updated
|
||||
ON sessions (tenant_id, kind, user_id, updated_at DESC)
|
||||
WHERE deleted_at IS NULL;
|
||||
@@ -0,0 +1,7 @@
|
||||
-- Migration 000040 down: drop the one-shot resync marker.
|
||||
|
||||
UPDATE data_sources
|
||||
SET config = json_remove(config, '$.settings.resync_required')
|
||||
WHERE deleted_at IS NULL
|
||||
AND type IN ('feishu', 'lark', 'feishu_drive', 'lark_drive')
|
||||
AND json_extract(config, '$.settings.resync_required') IS NOT NULL;
|
||||
@@ -0,0 +1,19 @@
|
||||
-- Migration 000040: feishu deep adaptation — one-shot full-resync marker.
|
||||
-- (Postgres twin: versioned/000122_feishu_deep_adaptation_resync.)
|
||||
--
|
||||
-- Legacy feishu/lark data sources created before the deep-adaptation feature
|
||||
-- hold documents ingested through the export path with no knowledge-base
|
||||
-- folder paths. This stamps their Settings with a one-shot resync_required
|
||||
-- marker; the sync entry upgrades the next run (even a scheduled incremental
|
||||
-- one) to a full pass so documents re-ingest with folder paths and
|
||||
-- block-level parsing, then clears the marker.
|
||||
|
||||
UPDATE data_sources
|
||||
SET config = json_set(
|
||||
json_set(config, '$.settings', json(
|
||||
CASE WHEN json_type(config, '$.settings') = 'object'
|
||||
THEN json_extract(config, '$.settings') ELSE '{}' END)),
|
||||
'$.settings.resync_required', json('true'))
|
||||
WHERE deleted_at IS NULL
|
||||
AND type IN ('feishu', 'lark', 'feishu_drive', 'lark_drive')
|
||||
AND json_extract(config, '$.settings.resync_required') IS NULL;
|
||||
@@ -0,0 +1 @@
|
||||
DROP TABLE IF EXISTS agent_collaborations;
|
||||
@@ -0,0 +1,13 @@
|
||||
CREATE TABLE IF NOT EXISTS agent_collaborations (
|
||||
id VARCHAR(36) PRIMARY KEY,
|
||||
tenant_id BIGINT NOT NULL,
|
||||
user_id VARCHAR(64) NOT NULL,
|
||||
session_id VARCHAR(36) NOT NULL,
|
||||
status VARCHAR(32) NOT NULL,
|
||||
version BIGINT NOT NULL,
|
||||
data TEXT NOT NULL,
|
||||
updated_at DATETIME NOT NULL
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS idx_agent_collaborations_status ON agent_collaborations(status, updated_at);
|
||||
CREATE INDEX IF NOT EXISTS idx_agent_collaborations_owner ON agent_collaborations(tenant_id, user_id, session_id);
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS idx_agent_collaborations_active_parent ON agent_collaborations(tenant_id, user_id, session_id) WHERE status IN ('active', 'cancelling');
|
||||
@@ -0,0 +1,2 @@
|
||||
-- Do not resurrect invalid content or later user deletions on downgrade.
|
||||
SELECT 1;
|
||||
@@ -0,0 +1,15 @@
|
||||
-- SQLite counterpart of PostgreSQL migration 000125. The SHA-256 of empty
|
||||
-- input proves these single-image derived chunks never had image bytes.
|
||||
-- Do not infer corruption from caption wording or remove source documents.
|
||||
-- Soft deletion also removes chunk_images through its existing trigger.
|
||||
UPDATE chunks
|
||||
SET deleted_at = CURRENT_TIMESTAMP, updated_at = CURRENT_TIMESTAMP
|
||||
WHERE deleted_at IS NULL
|
||||
AND chunk_type IN ('image_caption', 'image_ocr', 'image_vector')
|
||||
AND CASE WHEN json_valid(image_info) THEN
|
||||
CASE WHEN json_type(image_info) = 'array' THEN
|
||||
json_array_length(image_info) = 1
|
||||
AND json_extract(image_info, '$[0].sha256') =
|
||||
'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
|
||||
ELSE 0 END
|
||||
ELSE 0 END;
|
||||
@@ -0,0 +1,2 @@
|
||||
ALTER TABLE mcp_tool_approvals DROP COLUMN observed_risk;
|
||||
ALTER TABLE mcp_tool_approvals DROP COLUMN risk;
|
||||
@@ -0,0 +1,4 @@
|
||||
-- Per-tool MCP risk: the workspace's explicit setting and the highest risk
|
||||
-- declared through tool annotations. Empty means "not set".
|
||||
ALTER TABLE mcp_tool_approvals ADD COLUMN risk VARCHAR(16) NOT NULL DEFAULT '';
|
||||
ALTER TABLE mcp_tool_approvals ADD COLUMN observed_risk VARCHAR(16) NOT NULL DEFAULT '';
|
||||
@@ -0,0 +1 @@
|
||||
DROP TABLE IF EXISTS agent_grants;
|
||||
@@ -0,0 +1,22 @@
|
||||
-- Remembered agent approvals: "allow for the rest of this conversation" and
|
||||
-- the grants an automation carries between runs.
|
||||
CREATE TABLE IF NOT EXISTS agent_grants (
|
||||
id VARCHAR(36) PRIMARY KEY,
|
||||
tenant_id BIGINT NOT NULL,
|
||||
user_id VARCHAR(128) NOT NULL,
|
||||
scope VARCHAR(16) NOT NULL,
|
||||
scope_id VARCHAR(64) NOT NULL,
|
||||
grant_key VARCHAR(512) NOT NULL,
|
||||
label TEXT,
|
||||
binding_hash VARCHAR(64) NOT NULL DEFAULT '',
|
||||
risk VARCHAR(16) NOT NULL DEFAULT 'write',
|
||||
prompt_id VARCHAR(36),
|
||||
created_at DATETIME NOT NULL,
|
||||
updated_at DATETIME NOT NULL,
|
||||
last_used_at DATETIME,
|
||||
expires_at DATETIME,
|
||||
revoked_at DATETIME
|
||||
);
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS idx_agent_grants_key
|
||||
ON agent_grants(tenant_id, user_id, scope, scope_id, grant_key);
|
||||
CREATE INDEX IF NOT EXISTS idx_agent_grants_scope ON agent_grants(tenant_id, scope, scope_id);
|
||||
@@ -0,0 +1,3 @@
|
||||
DROP TABLE IF EXISTS notifications;
|
||||
DROP TABLE IF EXISTS automation_runs;
|
||||
DROP TABLE IF EXISTS automations;
|
||||
@@ -0,0 +1,77 @@
|
||||
-- Scheduled agent tasks, their runs, and in-app notifications.
|
||||
CREATE TABLE IF NOT EXISTS automations (
|
||||
id VARCHAR(36) PRIMARY KEY,
|
||||
tenant_id BIGINT NOT NULL,
|
||||
owner_user_id VARCHAR(36) NOT NULL,
|
||||
name VARCHAR(255) NOT NULL,
|
||||
description TEXT,
|
||||
enabled BOOLEAN NOT NULL DEFAULT 1,
|
||||
agent_id VARCHAR(64) NOT NULL,
|
||||
instruction TEXT NOT NULL,
|
||||
trigger_config TEXT NOT NULL,
|
||||
session_mode VARCHAR(16) NOT NULL DEFAULT 'per_run',
|
||||
persistent_session_id VARCHAR(36) NOT NULL DEFAULT '',
|
||||
carry_last_result BOOLEAN NOT NULL DEFAULT 0,
|
||||
misfire_policy VARCHAR(16) NOT NULL DEFAULT 'skip',
|
||||
overlap_policy VARCHAR(16) NOT NULL DEFAULT 'skip',
|
||||
access_level VARCHAR(16) NOT NULL DEFAULT 'confirm',
|
||||
approval_timeout_minutes INTEGER NOT NULL DEFAULT 1440,
|
||||
limits TEXT NOT NULL DEFAULT '{}',
|
||||
notify_on_success BOOLEAN NOT NULL DEFAULT 0,
|
||||
next_run_at DATETIME,
|
||||
last_run_at DATETIME,
|
||||
last_success_at DATETIME,
|
||||
last_run_status VARCHAR(32) NOT NULL DEFAULT '',
|
||||
consecutive_failures INTEGER NOT NULL DEFAULT 0,
|
||||
paused_reason TEXT NOT NULL DEFAULT '',
|
||||
version BIGINT NOT NULL DEFAULT 0,
|
||||
created_at DATETIME NOT NULL,
|
||||
updated_at DATETIME NOT NULL,
|
||||
deleted_at DATETIME
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS idx_automations_due ON automations(enabled, next_run_at);
|
||||
CREATE INDEX IF NOT EXISTS idx_automations_owner ON automations(tenant_id, owner_user_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_automations_deleted_at ON automations(deleted_at);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS automation_runs (
|
||||
id VARCHAR(36) PRIMARY KEY,
|
||||
automation_id VARCHAR(36) NOT NULL,
|
||||
tenant_id BIGINT NOT NULL,
|
||||
scheduled_at DATETIME NOT NULL,
|
||||
trigger_kind VARCHAR(16) NOT NULL,
|
||||
status VARCHAR(32) NOT NULL,
|
||||
session_id VARCHAR(36) NOT NULL DEFAULT '',
|
||||
user_message_id VARCHAR(36) NOT NULL DEFAULT '',
|
||||
assistant_message_id VARCHAR(36) NOT NULL DEFAULT '',
|
||||
owner VARCHAR(36) NOT NULL DEFAULT '',
|
||||
lease_until DATETIME,
|
||||
pending_prompt_id VARCHAR(36) NOT NULL DEFAULT '',
|
||||
resume BOOLEAN NOT NULL DEFAULT 0,
|
||||
cancel_requested BOOLEAN NOT NULL DEFAULT 0,
|
||||
answer TEXT NOT NULL DEFAULT '',
|
||||
error TEXT NOT NULL DEFAULT '',
|
||||
usage TEXT,
|
||||
started_at DATETIME,
|
||||
finished_at DATETIME,
|
||||
created_at DATETIME NOT NULL,
|
||||
updated_at DATETIME NOT NULL
|
||||
);
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS idx_automation_runs_slot
|
||||
ON automation_runs(automation_id, scheduled_at, trigger_kind);
|
||||
CREATE INDEX IF NOT EXISTS idx_automation_runs_automation ON automation_runs(automation_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_automation_runs_status ON automation_runs(status);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS notifications (
|
||||
id VARCHAR(36) PRIMARY KEY,
|
||||
tenant_id BIGINT NOT NULL,
|
||||
user_id VARCHAR(36) NOT NULL,
|
||||
kind VARCHAR(64) NOT NULL,
|
||||
title VARCHAR(255) NOT NULL,
|
||||
body TEXT NOT NULL DEFAULT '',
|
||||
link TEXT NOT NULL DEFAULT '',
|
||||
source_type VARCHAR(32) NOT NULL DEFAULT '',
|
||||
source_id VARCHAR(36) NOT NULL DEFAULT '',
|
||||
read_at DATETIME,
|
||||
created_at DATETIME NOT NULL
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS idx_notifications_user ON notifications(tenant_id, user_id, created_at);
|
||||
@@ -0,0 +1 @@
|
||||
ALTER TABLE sessions DROP COLUMN owner_auth_source;
|
||||
@@ -0,0 +1 @@
|
||||
ALTER TABLE sessions ADD COLUMN owner_auth_source VARCHAR(32) NOT NULL DEFAULT '';
|
||||
@@ -0,0 +1,2 @@
|
||||
DROP TABLE IF EXISTS sandbox_user_machines;
|
||||
DROP TABLE IF EXISTS session_sandbox_assignments;
|
||||
@@ -0,0 +1,26 @@
|
||||
CREATE TABLE IF NOT EXISTS session_sandbox_assignments (
|
||||
session_id VARCHAR(36) PRIMARY KEY,
|
||||
config_tenant_id INTEGER NOT NULL DEFAULT 0,
|
||||
config_id VARCHAR(64) NOT NULL DEFAULT '',
|
||||
machine_digest VARCHAR(64) NOT NULL DEFAULT '',
|
||||
released_at DATETIME NULL,
|
||||
cleanup_due_at DATETIME NULL
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS idx_session_sandbox_assignments_live_machine
|
||||
ON session_sandbox_assignments (machine_digest)
|
||||
WHERE released_at IS NULL AND machine_digest <> '';
|
||||
CREATE INDEX IF NOT EXISTS idx_session_sandbox_assignments_cleanup_due
|
||||
ON session_sandbox_assignments (cleanup_due_at)
|
||||
WHERE cleanup_due_at IS NOT NULL;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS sandbox_user_machines (
|
||||
machine_digest VARCHAR(64) PRIMARY KEY,
|
||||
owner_tenant_id INTEGER NOT NULL,
|
||||
owner_id VARCHAR(512) NOT NULL,
|
||||
config_tenant_id INTEGER NOT NULL,
|
||||
config_id VARCHAR(64) NOT NULL,
|
||||
empty_since DATETIME NULL
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS idx_sandbox_user_machines_config ON sandbox_user_machines (config_tenant_id, config_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_sandbox_user_machines_owner ON sandbox_user_machines (owner_id, owner_tenant_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_sandbox_user_machines_empty ON sandbox_user_machines (empty_since) WHERE empty_since IS NOT NULL;
|
||||
@@ -0,0 +1 @@
|
||||
ALTER TABLE automation_runs DROP COLUMN execution_duration_ms;
|
||||
@@ -0,0 +1 @@
|
||||
ALTER TABLE automation_runs ADD COLUMN execution_duration_ms BIGINT NOT NULL DEFAULT 0;
|
||||
@@ -0,0 +1 @@
|
||||
ALTER TABLE automations DROP COLUMN model_id;
|
||||
@@ -0,0 +1 @@
|
||||
ALTER TABLE automations ADD COLUMN model_id TEXT NOT NULL DEFAULT '';
|
||||
Loaded 100 of 5767 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user