2e2b0b45fa
Rebuild the dashboard as a Drive-style document management system on top of the existing CaveauAI hybrid RAG pipeline. Backend: - 5 migrations (versions, trash soft-delete, saved searches, categories, audit) - DMS helpers (folder ACL walker, disk storage, audit, version snapshot, XLSX/PPTX/HTML/CSV/MD extractors) - New APIs: folders, document-versions, trash, bulk, preview, saved-searches, categories, diagnostics - Extended APIs: documents (folder_id, soft-delete, ACL filter, sort), upload (9 file types, version-collision detection with replace/new/keep-both, disk persistence), chat-stream (folder scoping + graph related-documents) - 30-day trash purge cron with Qdrant + disk + graph cleanup Frontend: - Drive-style two-pane browser with folder tree, drag-drop, bulk-action bar, right-click context menu, multi-select - New pages: folders (tree + per-folder ACL editor), trash (restore/purge) - Extended pages: upload (folder picker, version-collision modal, 9 file type chips), document (Preview/Versions/Permissions tabs with PDF.js + mammoth.js + audio), index (DMS KPIs + activity feed), settings (live diagnostics ping MariaDB/Qdrant/LiteLLM/FalkorDB/disk), chat (folder scope chips + related-authorities chips) - New CSS (dms.css) + JS bundle (dms.js) exposing window.DBN_DMS - Sidebar nav adds Folders + Trash items All routes return HTTP 200 in local smoke test; all 32 files lint clean. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
50 lines
2.1 KiB
SQL
50 lines
2.1 KiB
SQL
-- DBN DMS migration 001 — document versioning
|
|
-- Adds client_document_versions table + current_version/storage_path columns on client_documents.
|
|
-- Safe to re-run: uses IF NOT EXISTS / INFORMATION_SCHEMA guards.
|
|
|
|
CREATE TABLE IF NOT EXISTS client_document_versions (
|
|
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
|
document_id INT UNSIGNED NOT NULL,
|
|
client_id INT UNSIGNED NOT NULL,
|
|
version_number INT UNSIGNED NOT NULL,
|
|
title VARCHAR(500) NOT NULL,
|
|
content LONGTEXT NOT NULL,
|
|
file_size_bytes INT UNSIGNED DEFAULT 0,
|
|
original_filename VARCHAR(255) NULL,
|
|
storage_path VARCHAR(500) NULL,
|
|
word_count INT UNSIGNED DEFAULT 0,
|
|
uploaded_by INT UNSIGNED NULL,
|
|
notes VARCHAR(500) NULL,
|
|
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
UNIQUE KEY uq_doc_ver (document_id, version_number),
|
|
KEY idx_client (client_id),
|
|
KEY idx_uploaded_by (uploaded_by),
|
|
CONSTRAINT fk_cdv_doc FOREIGN KEY (document_id) REFERENCES client_documents(id) ON DELETE CASCADE,
|
|
CONSTRAINT fk_cdv_client FOREIGN KEY (client_id) REFERENCES clients(id) ON DELETE CASCADE
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
|
|
COMMENT='Per-document version history. Latest = client_documents.current_version.';
|
|
|
|
-- current_version column (guarded against re-run)
|
|
SET @col_exists := (
|
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
|
WHERE TABLE_SCHEMA = DATABASE()
|
|
AND TABLE_NAME = 'client_documents'
|
|
AND COLUMN_NAME = 'current_version'
|
|
);
|
|
SET @sql := IF(@col_exists = 0,
|
|
'ALTER TABLE client_documents ADD COLUMN current_version INT UNSIGNED NOT NULL DEFAULT 1 AFTER chunk_count',
|
|
'SELECT 1');
|
|
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
|
|
|
-- storage_path column (guarded)
|
|
SET @col_exists := (
|
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
|
WHERE TABLE_SCHEMA = DATABASE()
|
|
AND TABLE_NAME = 'client_documents'
|
|
AND COLUMN_NAME = 'storage_path'
|
|
);
|
|
SET @sql := IF(@col_exists = 0,
|
|
'ALTER TABLE client_documents ADD COLUMN storage_path VARCHAR(500) NULL AFTER original_filename',
|
|
'SELECT 1');
|
|
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|