/**
 * SQL Schema Definitions for OCR Provenance MCP System
 *
 * Contains all table creation SQL, indexes, and database configuration.
 * These are constants used by the migration system.
 *
 * @module migrations/schema-definitions
 */
/** Current schema version */
export declare const SCHEMA_VERSION = 33;
/**
 * Database configuration pragmas for optimal performance and safety
 */
export declare const DATABASE_PRAGMAS: readonly ["PRAGMA journal_mode = WAL", "PRAGMA foreign_keys = ON", "PRAGMA synchronous = NORMAL", "PRAGMA cache_size = -64000", "PRAGMA wal_autocheckpoint = 1000", "PRAGMA mmap_size = 268435456", "PRAGMA busy_timeout = 30000"];
/**
 * Schema version table - tracks migration state
 */
export declare const CREATE_SCHEMA_VERSION_TABLE = "\nCREATE TABLE IF NOT EXISTS schema_version (\n  id INTEGER PRIMARY KEY CHECK (id = 1),\n  version INTEGER NOT NULL,\n  created_at TEXT NOT NULL,\n  updated_at TEXT NOT NULL\n)\n";
/**
 * Provenance table - central provenance tracking (self-referential FKs)
 * Every data transformation creates a provenance record.
 */
export declare const CREATE_PROVENANCE_TABLE = "\nCREATE TABLE IF NOT EXISTS provenance (\n  id TEXT PRIMARY KEY,\n  type TEXT NOT NULL CHECK (type IN ('DOCUMENT', 'OCR_RESULT', 'CHUNK', 'IMAGE', 'VLM_DESCRIPTION', 'EMBEDDING', 'EXTRACTION', 'FORM_FILL', 'COMPARISON', 'CLUSTERING')),\n  created_at TEXT NOT NULL,\n  processed_at TEXT NOT NULL,\n  source_file_created_at TEXT,\n  source_file_modified_at TEXT,\n  source_type TEXT NOT NULL CHECK (source_type IN ('FILE', 'OCR', 'CHUNKING', 'IMAGE_EXTRACTION', 'VLM', 'VLM_DEDUP', 'EMBEDDING', 'EXTRACTION', 'FORM_FILL', 'COMPARISON', 'CLUSTERING')),\n  source_path TEXT,\n  source_id TEXT,\n  root_document_id TEXT NOT NULL,\n  location TEXT,\n  content_hash TEXT NOT NULL,\n  input_hash TEXT,\n  file_hash TEXT,\n  processor TEXT NOT NULL,\n  processor_version TEXT NOT NULL,\n  processing_params TEXT NOT NULL,\n  processing_duration_ms INTEGER,\n  processing_quality_score REAL,\n  parent_id TEXT,\n  parent_ids TEXT NOT NULL,\n  chain_depth INTEGER NOT NULL,\n  chain_path TEXT,\n  user_id TEXT,\n  agent_id TEXT,\n  agent_metadata_json TEXT,\n  chain_hash TEXT,\n  FOREIGN KEY (source_id) REFERENCES provenance(id),\n  FOREIGN KEY (parent_id) REFERENCES provenance(id)\n)\n";
/**
 * Database metadata table - database info and statistics
 */
export declare const CREATE_DATABASE_METADATA_TABLE = "\nCREATE TABLE IF NOT EXISTS database_metadata (\n  id INTEGER PRIMARY KEY CHECK (id = 1),\n  database_name TEXT NOT NULL,\n  database_version TEXT NOT NULL,\n  created_at TEXT NOT NULL,\n  last_modified_at TEXT NOT NULL,\n  total_documents INTEGER NOT NULL DEFAULT 0,\n  total_ocr_results INTEGER NOT NULL DEFAULT 0,\n  total_chunks INTEGER NOT NULL DEFAULT 0,\n  total_embeddings INTEGER NOT NULL DEFAULT 0\n)\n";
/**
 * Documents table - source files with file hashes
 * Provenance depth: 0 (root of chain)
 */
export declare const CREATE_DOCUMENTS_TABLE = "\nCREATE TABLE IF NOT EXISTS documents (\n  id TEXT PRIMARY KEY,\n  file_path TEXT NOT NULL,\n  file_name TEXT NOT NULL,\n  file_hash TEXT NOT NULL,\n  file_size INTEGER NOT NULL,\n  file_type TEXT NOT NULL,\n  status TEXT NOT NULL CHECK (status IN ('pending', 'processing', 'complete', 'failed')),\n  page_count INTEGER,\n  provenance_id TEXT NOT NULL UNIQUE,\n  created_at TEXT NOT NULL,\n  modified_at TEXT,\n  ocr_completed_at TEXT,\n  error_message TEXT,\n  doc_title TEXT,\n  doc_author TEXT,\n  doc_subject TEXT,\n  datalab_file_id TEXT,\n  FOREIGN KEY (provenance_id) REFERENCES provenance(id)\n)\n";
/**
 * OCR Results table - extracted text from Marker OCR
 * Provenance depth: 1
 */
export declare const CREATE_OCR_RESULTS_TABLE = "\nCREATE TABLE IF NOT EXISTS ocr_results (\n  id TEXT PRIMARY KEY,\n  provenance_id TEXT NOT NULL UNIQUE,\n  document_id TEXT NOT NULL,\n  extracted_text TEXT NOT NULL,\n  text_length INTEGER NOT NULL,\n  datalab_request_id TEXT NOT NULL,\n  datalab_mode TEXT NOT NULL CHECK (datalab_mode IN ('fast', 'balanced', 'accurate')),\n  parse_quality_score REAL,\n  page_count INTEGER NOT NULL,\n  cost_cents REAL,\n  content_hash TEXT NOT NULL,\n  processing_started_at TEXT NOT NULL,\n  processing_completed_at TEXT NOT NULL,\n  processing_duration_ms INTEGER NOT NULL,\n  json_blocks TEXT,\n  extras_json TEXT,\n  FOREIGN KEY (provenance_id) REFERENCES provenance(id),\n  FOREIGN KEY (document_id) REFERENCES documents(id)\n)\n";
/**
 * Chunks table - text segments (2000 chars, 10% overlap)
 * Provenance depth: 2
 */
export declare const CREATE_CHUNKS_TABLE = "\nCREATE TABLE IF NOT EXISTS chunks (\n  id TEXT PRIMARY KEY,\n  document_id TEXT NOT NULL,\n  ocr_result_id TEXT NOT NULL,\n  text TEXT NOT NULL CHECK(length(trim(text)) > 0),\n  text_hash TEXT NOT NULL,\n  chunk_index INTEGER NOT NULL,\n  character_start INTEGER NOT NULL,\n  character_end INTEGER NOT NULL,\n  page_number INTEGER,\n  page_range TEXT,\n  overlap_previous INTEGER NOT NULL,\n  overlap_next INTEGER NOT NULL,\n  provenance_id TEXT NOT NULL UNIQUE,\n  created_at TEXT NOT NULL,\n  embedding_status TEXT NOT NULL CHECK (embedding_status IN ('pending', 'complete', 'failed')),\n  embedded_at TEXT,\n  ocr_quality_score REAL,\n  heading_context TEXT,\n  heading_level INTEGER,\n  section_path TEXT,\n  content_types TEXT,\n  is_atomic INTEGER NOT NULL DEFAULT 0,\n  chunking_strategy TEXT NOT NULL DEFAULT 'hybrid_section',\n  FOREIGN KEY (document_id) REFERENCES documents(id),\n  FOREIGN KEY (ocr_result_id) REFERENCES ocr_results(id),\n  FOREIGN KEY (provenance_id) REFERENCES provenance(id)\n)\n";
/**
 * Embeddings table - vectors WITH original_text (denormalized)
 * Provenance depth: 3
 *
 * CRITICAL: This table is denormalized to include original_text
 * and source file info. Search results are self-contained per CP-002.
 */
export declare const CREATE_EMBEDDINGS_TABLE = "\nCREATE TABLE IF NOT EXISTS embeddings (\n  id TEXT PRIMARY KEY,\n  chunk_id TEXT,\n  image_id TEXT,\n  extraction_id TEXT,\n  document_id TEXT NOT NULL,\n  original_text TEXT NOT NULL,\n  original_text_length INTEGER NOT NULL,\n  source_file_path TEXT NOT NULL,\n  source_file_name TEXT NOT NULL,\n  source_file_hash TEXT NOT NULL,\n  page_number INTEGER,\n  page_range TEXT,\n  character_start INTEGER NOT NULL,\n  character_end INTEGER NOT NULL,\n  chunk_index INTEGER NOT NULL,\n  total_chunks INTEGER NOT NULL,\n  model_name TEXT NOT NULL,\n  model_version TEXT NOT NULL,\n  task_type TEXT NOT NULL CHECK (task_type IN ('search_document', 'search_query')),\n  inference_mode TEXT NOT NULL CHECK (inference_mode = 'local'),\n  gpu_device TEXT,\n  provenance_id TEXT NOT NULL UNIQUE,\n  content_hash TEXT NOT NULL,\n  created_at TEXT NOT NULL,\n  generation_duration_ms INTEGER,\n  FOREIGN KEY (chunk_id) REFERENCES chunks(id),\n  FOREIGN KEY (image_id) REFERENCES images(id),\n  FOREIGN KEY (extraction_id) REFERENCES extractions(id),\n  FOREIGN KEY (document_id) REFERENCES documents(id),\n  FOREIGN KEY (provenance_id) REFERENCES provenance(id),\n  CHECK (chunk_id IS NOT NULL OR image_id IS NOT NULL OR extraction_id IS NOT NULL)\n)\n";
/**
 * Vector embeddings virtual table using sqlite-vec
 * 768-dimensional float32 vectors for nomic-embed-text-v1.5
 */
export declare const CREATE_VEC_EMBEDDINGS_TABLE = "\nCREATE VIRTUAL TABLE IF NOT EXISTS vec_embeddings USING vec0(\n  embedding_id TEXT PRIMARY KEY,\n  vector FLOAT[768]\n)\n";
/**
 * FTS5 full-text search index over chunks
 * Uses external content mode - no data duplication
 * Tokenizer: porter stemmer + unicode support
 */
export declare const CREATE_CHUNKS_FTS_TABLE = "\nCREATE VIRTUAL TABLE IF NOT EXISTS chunks_fts USING fts5(\n  text,\n  content='chunks',\n  content_rowid='rowid',\n  tokenize='porter unicode61'\n)\n";
/**
 * Triggers to keep FTS5 in sync with chunks table
 * CRITICAL: These must be created in v4 migration
 */
export declare const CREATE_FTS_TRIGGERS: readonly ["CREATE TRIGGER IF NOT EXISTS chunks_fts_ai AFTER INSERT ON chunks BEGIN\n    INSERT INTO chunks_fts(rowid, text) VALUES (new.rowid, new.text);\n  END", "CREATE TRIGGER IF NOT EXISTS chunks_fts_ad AFTER DELETE ON chunks BEGIN\n    INSERT INTO chunks_fts(chunks_fts, rowid, text) VALUES('delete', old.rowid, old.text);\n  END", "CREATE TRIGGER IF NOT EXISTS chunks_fts_au AFTER UPDATE OF text ON chunks BEGIN\n    INSERT INTO chunks_fts(chunks_fts, rowid, text) VALUES('delete', old.rowid, old.text);\n    INSERT INTO chunks_fts(rowid, text) VALUES (new.rowid, new.text);\n  END"];
/**
 * FTS5 index metadata for audit trail
 * Note: v6 removes CHECK (id = 1) to allow id=2 row for VLM FTS metadata
 */
export declare const CREATE_FTS_INDEX_METADATA = "\nCREATE TABLE IF NOT EXISTS fts_index_metadata (\n  id INTEGER PRIMARY KEY,\n  last_rebuild_at TEXT,\n  chunks_indexed INTEGER NOT NULL DEFAULT 0,\n  tokenizer TEXT NOT NULL DEFAULT 'porter unicode61',\n  schema_version INTEGER NOT NULL DEFAULT 8,\n  content_hash TEXT\n)\n";
/**
 * FTS5 full-text search index over VLM description embeddings
 * Uses external content mode - reads original_text from embeddings table
 * Only indexes embeddings where image_id IS NOT NULL (VLM descriptions)
 * Tokenizer: porter stemmer + unicode support
 */
export declare const CREATE_VLM_FTS_TABLE = "\nCREATE VIRTUAL TABLE IF NOT EXISTS vlm_fts USING fts5(\n  original_text,\n  content='embeddings',\n  content_rowid='rowid',\n  tokenize='porter unicode61'\n)\n";
/**
 * Triggers to keep VLM FTS5 in sync with embeddings table
 * Only fire for embeddings with image_id IS NOT NULL (VLM description embeddings)
 *
 * NOTE (L-3): The UPDATE trigger only fires on original_text changes when
 * new.image_id IS NOT NULL. If image_id were set from non-null to null, the
 * stale FTS entry would remain. In practice image_id is immutable after INSERT,
 * so this is a theoretical gap only. The DELETE trigger covers row removal.
 */
export declare const CREATE_VLM_FTS_TRIGGERS: readonly ["CREATE TRIGGER IF NOT EXISTS vlm_fts_ai AFTER INSERT ON embeddings\n   WHEN new.image_id IS NOT NULL BEGIN\n    INSERT INTO vlm_fts(rowid, original_text) VALUES (new.rowid, new.original_text);\n  END", "CREATE TRIGGER IF NOT EXISTS vlm_fts_ad AFTER DELETE ON embeddings\n   WHEN old.image_id IS NOT NULL BEGIN\n    INSERT INTO vlm_fts(vlm_fts, rowid, original_text) VALUES('delete', old.rowid, old.original_text);\n  END", "CREATE TRIGGER IF NOT EXISTS vlm_fts_au AFTER UPDATE OF original_text ON embeddings\n   WHEN new.image_id IS NOT NULL BEGIN\n    INSERT INTO vlm_fts(vlm_fts, rowid, original_text) VALUES('delete', old.rowid, old.original_text);\n    INSERT INTO vlm_fts(rowid, original_text) VALUES (new.rowid, new.original_text);\n  END"];
/**
 * Images table - extracted images from documents for VLM analysis
 * Provenance depth: 2 (after OCR extraction)
 */
export declare const CREATE_IMAGES_TABLE = "\nCREATE TABLE IF NOT EXISTS images (\n  id TEXT PRIMARY KEY,\n  document_id TEXT NOT NULL,\n  ocr_result_id TEXT NOT NULL,\n  page_number INTEGER NOT NULL,\n  bbox_x REAL NOT NULL,\n  bbox_y REAL NOT NULL,\n  bbox_width REAL NOT NULL,\n  bbox_height REAL NOT NULL,\n  image_index INTEGER NOT NULL,\n  format TEXT NOT NULL,\n  width INTEGER NOT NULL,\n  height INTEGER NOT NULL,\n  extracted_path TEXT,\n  file_size INTEGER,\n  vlm_status TEXT NOT NULL DEFAULT 'pending' CHECK (vlm_status IN ('pending', 'processing', 'complete', 'failed')),\n  vlm_description TEXT,\n  vlm_structured_data TEXT,\n  vlm_embedding_id TEXT,\n  vlm_model TEXT,\n  vlm_confidence REAL,\n  vlm_processed_at TEXT,\n  vlm_tokens_used INTEGER,\n  context_text TEXT,\n  provenance_id TEXT,\n  created_at TEXT NOT NULL,\n  error_message TEXT,\n  block_type TEXT,\n  is_header_footer INTEGER NOT NULL DEFAULT 0,\n  content_hash TEXT,\n  page_width REAL,\n  page_height REAL,\n  FOREIGN KEY (document_id) REFERENCES documents(id) ON DELETE CASCADE,\n  FOREIGN KEY (ocr_result_id) REFERENCES ocr_results(id) ON DELETE CASCADE,\n  FOREIGN KEY (vlm_embedding_id) REFERENCES embeddings(id),\n  FOREIGN KEY (provenance_id) REFERENCES provenance(id)\n)\n";
/**
 * Extractions table - structured data extracted via page_schema
 * Provenance depth: 2 (after OCR_RESULT)
 */
export declare const CREATE_EXTRACTIONS_TABLE = "\nCREATE TABLE IF NOT EXISTS extractions (\n  id TEXT PRIMARY KEY NOT NULL,\n  document_id TEXT NOT NULL REFERENCES documents(id) ON DELETE CASCADE,\n  ocr_result_id TEXT NOT NULL REFERENCES ocr_results(id) ON DELETE CASCADE,\n  schema_json TEXT NOT NULL,\n  extraction_json TEXT NOT NULL,\n  content_hash TEXT NOT NULL,\n  provenance_id TEXT NOT NULL REFERENCES provenance(id),\n  created_at TEXT NOT NULL DEFAULT (datetime('now'))\n)\n";
/**
 * Form fills table - results from form fill processing
 * Provenance depth: 1 (directly from DOCUMENT)
 */
export declare const CREATE_FORM_FILLS_TABLE = "\nCREATE TABLE IF NOT EXISTS form_fills (\n  id TEXT PRIMARY KEY NOT NULL,\n  source_file_path TEXT NOT NULL,\n  source_file_hash TEXT NOT NULL,\n  field_data_json TEXT NOT NULL,\n  context TEXT,\n  confidence_threshold REAL NOT NULL DEFAULT 0.5,\n  output_file_path TEXT,\n  output_base64 TEXT,\n  fields_filled TEXT NOT NULL DEFAULT '[]',\n  fields_not_found TEXT NOT NULL DEFAULT '[]',\n  page_count INTEGER,\n  cost_cents REAL,\n  status TEXT NOT NULL CHECK(status IN ('pending', 'processing', 'complete', 'failed')),\n  error_message TEXT,\n  provenance_id TEXT NOT NULL REFERENCES provenance(id),\n  created_at TEXT NOT NULL DEFAULT (datetime('now'))\n)\n";
/**
 * FTS5 full-text search index over extraction JSON content
 * Uses external content mode - reads extraction_json from extractions table
 * Tokenizer: porter stemmer + unicode support
 */
export declare const CREATE_EXTRACTIONS_FTS_TABLE = "\nCREATE VIRTUAL TABLE IF NOT EXISTS extractions_fts USING fts5(\n  extraction_json,\n  content='extractions',\n  content_rowid='rowid',\n  tokenize='porter unicode61'\n)\n";
/**
 * Triggers to keep extractions FTS5 in sync with extractions table
 */
export declare const CREATE_EXTRACTIONS_FTS_TRIGGERS: readonly ["CREATE TRIGGER IF NOT EXISTS extractions_fts_ai AFTER INSERT ON extractions BEGIN\n    INSERT INTO extractions_fts(rowid, extraction_json) VALUES (new.rowid, new.extraction_json);\n  END", "CREATE TRIGGER IF NOT EXISTS extractions_fts_ad AFTER DELETE ON extractions BEGIN\n    INSERT INTO extractions_fts(extractions_fts, rowid, extraction_json) VALUES('delete', old.rowid, old.extraction_json);\n  END", "CREATE TRIGGER IF NOT EXISTS extractions_fts_au AFTER UPDATE OF extraction_json ON extractions BEGIN\n    INSERT INTO extractions_fts(extractions_fts, rowid, extraction_json) VALUES('delete', old.rowid, old.extraction_json);\n    INSERT INTO extractions_fts(rowid, extraction_json) VALUES (new.rowid, new.extraction_json);\n  END"];
/**
 * Uploaded files table - legacy cloud file upload tracking
 * Tracks upload lifecycle: pending -> uploading -> confirming -> complete/failed
 */
export declare const CREATE_UPLOADED_FILES_TABLE = "\nCREATE TABLE IF NOT EXISTS uploaded_files (\n  id TEXT PRIMARY KEY NOT NULL,\n  local_path TEXT NOT NULL,\n  file_name TEXT NOT NULL,\n  file_hash TEXT NOT NULL,\n  file_size INTEGER NOT NULL,\n  content_type TEXT NOT NULL,\n  datalab_file_id TEXT,\n  datalab_reference TEXT,\n  upload_status TEXT NOT NULL DEFAULT 'pending'\n    CHECK (upload_status IN ('pending', 'uploading', 'confirming', 'complete', 'failed')),\n  error_message TEXT,\n  created_at TEXT NOT NULL DEFAULT (datetime('now')),\n  completed_at TEXT,\n  provenance_id TEXT NOT NULL REFERENCES provenance(id)\n)";
/**
 * Comparisons table - document comparison results
 * Provenance depth: 2 (parallel to CHUNK, after OCR_RESULT)
 */
export declare const CREATE_COMPARISONS_TABLE = "\nCREATE TABLE IF NOT EXISTS comparisons (\n  id TEXT PRIMARY KEY NOT NULL,\n  document_id_1 TEXT NOT NULL REFERENCES documents(id),\n  document_id_2 TEXT NOT NULL REFERENCES documents(id),\n  similarity_ratio REAL NOT NULL,\n  text_diff_json TEXT NOT NULL,\n  structural_diff_json TEXT NOT NULL,\n  summary TEXT NOT NULL,\n  content_hash TEXT NOT NULL,\n  provenance_id TEXT NOT NULL REFERENCES provenance(id),\n  created_at TEXT NOT NULL DEFAULT (datetime('now')),\n  processing_duration_ms INTEGER\n)";
/**
 * Clusters table - groups of semantically similar documents
 * Provenance depth: 2 (parallel to CHUNK, after OCR_RESULT)
 */
export declare const CREATE_CLUSTERS_TABLE = "\nCREATE TABLE IF NOT EXISTS clusters (\n  id TEXT PRIMARY KEY NOT NULL,\n  run_id TEXT NOT NULL,\n  cluster_index INTEGER NOT NULL,\n  label TEXT,\n  description TEXT,\n  classification_tag TEXT,\n  document_count INTEGER NOT NULL DEFAULT 0,\n  centroid_json TEXT,\n  top_terms_json TEXT,\n  coherence_score REAL,\n  algorithm TEXT NOT NULL,\n  algorithm_params_json TEXT NOT NULL,\n  silhouette_score REAL,\n  content_hash TEXT NOT NULL,\n  provenance_id TEXT NOT NULL UNIQUE REFERENCES provenance(id),\n  created_at TEXT NOT NULL,\n  processing_duration_ms INTEGER\n)";
/**
 * Document-cluster assignments - links documents to clusters within a run
 * UNIQUE(document_id, run_id) ensures one assignment per document per run
 * cluster_id is nullable for noise documents (HDBSCAN -1 labels)
 */
export declare const CREATE_DOCUMENT_CLUSTERS_TABLE = "\nCREATE TABLE IF NOT EXISTS document_clusters (\n  id TEXT PRIMARY KEY NOT NULL,\n  document_id TEXT NOT NULL REFERENCES documents(id),\n  cluster_id TEXT REFERENCES clusters(id),\n  run_id TEXT NOT NULL,\n  similarity_to_centroid REAL NOT NULL,\n  membership_probability REAL NOT NULL DEFAULT 1.0,\n  is_noise INTEGER NOT NULL DEFAULT 0,\n  assigned_at TEXT NOT NULL,\n  UNIQUE(document_id, run_id)\n)";
/**
 * Saved searches table - persisted search results for revisiting
 * v28 addition, v30 adds last_executed_at and execution_count
 */
export declare const CREATE_SAVED_SEARCHES_TABLE = "\nCREATE TABLE IF NOT EXISTS saved_searches (\n  id TEXT PRIMARY KEY,\n  name TEXT NOT NULL,\n  query TEXT NOT NULL,\n  search_type TEXT NOT NULL CHECK (search_type IN ('bm25', 'semantic', 'hybrid')),\n  search_params TEXT NOT NULL DEFAULT '{}',\n  result_count INTEGER NOT NULL,\n  result_ids TEXT NOT NULL DEFAULT '[]',\n  created_at TEXT NOT NULL DEFAULT (datetime('now')),\n  notes TEXT,\n  last_executed_at TEXT,\n  execution_count INTEGER DEFAULT 0,\n  user_id TEXT,\n  is_shared INTEGER DEFAULT 0,\n  alert_enabled INTEGER DEFAULT 0,\n  last_alert_at TEXT\n)\n";
/**
 * FTS5 full-text search index over document metadata
 * Indexes doc_title, doc_author, doc_subject for metadata search
 * Uses external content mode - reads from documents table
 * v30 addition
 */
export declare const CREATE_DOCUMENTS_FTS_TABLE = "\nCREATE VIRTUAL TABLE IF NOT EXISTS documents_fts USING fts5(\n  doc_title,\n  doc_author,\n  doc_subject,\n  content='documents',\n  content_rowid='rowid',\n  tokenize='porter unicode61'\n)\n";
/**
 * Triggers to keep documents FTS5 in sync with documents table
 * v30 addition
 */
export declare const CREATE_DOCUMENTS_FTS_TRIGGERS: readonly ["CREATE TRIGGER IF NOT EXISTS documents_fts_ai AFTER INSERT ON documents BEGIN\n    INSERT INTO documents_fts(rowid, doc_title, doc_author, doc_subject)\n    VALUES (new.rowid, COALESCE(new.doc_title, ''), COALESCE(new.doc_author, ''), COALESCE(new.doc_subject, ''));\n  END", "CREATE TRIGGER IF NOT EXISTS documents_fts_ad AFTER DELETE ON documents BEGIN\n    INSERT INTO documents_fts(documents_fts, rowid, doc_title, doc_author, doc_subject)\n    VALUES('delete', old.rowid, COALESCE(old.doc_title, ''), COALESCE(old.doc_author, ''), COALESCE(old.doc_subject, ''));\n  END", "CREATE TRIGGER IF NOT EXISTS documents_fts_au AFTER UPDATE OF doc_title, doc_author, doc_subject ON documents BEGIN\n    INSERT INTO documents_fts(documents_fts, rowid, doc_title, doc_author, doc_subject)\n    VALUES('delete', old.rowid, COALESCE(old.doc_title, ''), COALESCE(old.doc_author, ''), COALESCE(old.doc_subject, ''));\n    INSERT INTO documents_fts(rowid, doc_title, doc_author, doc_subject)\n    VALUES (new.rowid, COALESCE(new.doc_title, ''), COALESCE(new.doc_author, ''), COALESCE(new.doc_subject, ''));\n  END"];
/**
 * Tags table - user-defined annotations for cross-entity tagging
 * v29 addition
 */
export declare const CREATE_TAGS_TABLE = "\nCREATE TABLE IF NOT EXISTS tags (\n  id TEXT PRIMARY KEY NOT NULL,\n  name TEXT NOT NULL UNIQUE,\n  description TEXT,\n  color TEXT,\n  created_at TEXT NOT NULL DEFAULT (datetime('now'))\n)";
/**
 * Entity tags table - many-to-many relationship between tags and entities
 * v29 addition
 */
export declare const CREATE_ENTITY_TAGS_TABLE = "\nCREATE TABLE IF NOT EXISTS entity_tags (\n  id TEXT PRIMARY KEY NOT NULL,\n  tag_id TEXT NOT NULL REFERENCES tags(id) ON DELETE CASCADE,\n  entity_id TEXT NOT NULL,\n  entity_type TEXT NOT NULL CHECK(entity_type IN ('document', 'chunk', 'image', 'extraction', 'cluster')),\n  created_at TEXT NOT NULL DEFAULT (datetime('now')),\n  UNIQUE(tag_id, entity_id, entity_type)\n)";
/**
 * Users table - user identity and roles for multi-user support
 * v32 addition
 */
export declare const CREATE_USERS_TABLE = "\nCREATE TABLE IF NOT EXISTS users (\n  id TEXT PRIMARY KEY DEFAULT (lower(hex(randomblob(16)))),\n  external_id TEXT UNIQUE,\n  display_name TEXT NOT NULL,\n  email TEXT,\n  role TEXT NOT NULL DEFAULT 'viewer' CHECK(role IN ('viewer','reviewer','editor','admin')),\n  created_at TEXT NOT NULL DEFAULT (datetime('now')),\n  last_active_at TEXT,\n  metadata_json TEXT DEFAULT '{}'\n)\n";
/**
 * Audit log table - user action tracking for compliance
 * v32 addition
 */
export declare const CREATE_AUDIT_LOG_TABLE = "\nCREATE TABLE IF NOT EXISTS audit_log (\n  id INTEGER PRIMARY KEY AUTOINCREMENT,\n  user_id TEXT,\n  session_id TEXT,\n  action TEXT NOT NULL,\n  entity_type TEXT,\n  entity_id TEXT,\n  details_json TEXT DEFAULT '{}',\n  ip_address TEXT,\n  created_at TEXT NOT NULL DEFAULT (datetime('now')),\n  FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL\n)\n";
/**
 * Annotations table - document/chunk annotations and comments
 * v32 addition
 */
export declare const CREATE_ANNOTATIONS_TABLE = "\nCREATE TABLE IF NOT EXISTS annotations (\n  id TEXT PRIMARY KEY DEFAULT (lower(hex(randomblob(16)))),\n  document_id TEXT NOT NULL,\n  user_id TEXT,\n  chunk_id TEXT,\n  page_number INTEGER,\n  annotation_type TEXT NOT NULL CHECK(annotation_type IN ('comment', 'correction', 'question', 'highlight', 'flag', 'approval')),\n  content TEXT NOT NULL,\n  status TEXT NOT NULL DEFAULT 'open' CHECK(status IN ('open', 'resolved', 'dismissed')),\n  parent_id TEXT,\n  created_at TEXT NOT NULL DEFAULT (datetime('now')),\n  updated_at TEXT NOT NULL DEFAULT (datetime('now')),\n  FOREIGN KEY (document_id) REFERENCES documents(id) ON DELETE CASCADE,\n  FOREIGN KEY (chunk_id) REFERENCES chunks(id) ON DELETE SET NULL,\n  FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL,\n  FOREIGN KEY (parent_id) REFERENCES annotations(id) ON DELETE CASCADE\n)\n";
/**
 * Document locks table - concurrent edit prevention
 * v32 addition
 */
export declare const CREATE_DOCUMENT_LOCKS_TABLE = "\nCREATE TABLE IF NOT EXISTS document_locks (\n  document_id TEXT PRIMARY KEY,\n  user_id TEXT NOT NULL,\n  session_id TEXT NOT NULL,\n  lock_type TEXT NOT NULL CHECK(lock_type IN ('exclusive', 'shared')),\n  reason TEXT,\n  acquired_at TEXT NOT NULL DEFAULT (datetime('now')),\n  expires_at TEXT NOT NULL,\n  FOREIGN KEY (document_id) REFERENCES documents(id) ON DELETE CASCADE,\n  FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE\n)\n";
/**
 * Workflow states table - state machine workflow for document review
 * v32 addition
 */
export declare const CREATE_WORKFLOW_STATES_TABLE = "\nCREATE TABLE IF NOT EXISTS workflow_states (\n  id TEXT PRIMARY KEY DEFAULT (lower(hex(randomblob(16)))),\n  document_id TEXT NOT NULL,\n  state TEXT NOT NULL CHECK(state IN ('draft', 'submitted', 'in_review', 'changes_requested', 'approved', 'rejected', 'executed', 'expired', 'archived')),\n  assigned_to TEXT,\n  assigned_by TEXT,\n  reason TEXT,\n  due_date TEXT,\n  completed_at TEXT,\n  created_at TEXT NOT NULL DEFAULT (datetime('now')),\n  metadata_json TEXT DEFAULT '{}',\n  FOREIGN KEY (document_id) REFERENCES documents(id) ON DELETE CASCADE,\n  FOREIGN KEY (assigned_to) REFERENCES users(id) ON DELETE SET NULL,\n  FOREIGN KEY (assigned_by) REFERENCES users(id) ON DELETE SET NULL\n)\n";
/**
 * Approval chains table - reusable approval chain definitions
 * v32 addition
 */
export declare const CREATE_APPROVAL_CHAINS_TABLE = "\nCREATE TABLE IF NOT EXISTS approval_chains (\n  id TEXT PRIMARY KEY DEFAULT (lower(hex(randomblob(16)))),\n  name TEXT NOT NULL,\n  description TEXT,\n  steps_json TEXT NOT NULL,\n  created_at TEXT NOT NULL DEFAULT (datetime('now')),\n  created_by TEXT,\n  FOREIGN KEY (created_by) REFERENCES users(id) ON DELETE SET NULL\n)\n";
/**
 * Approval steps table - per-document approval progress
 * v32 addition
 */
export declare const CREATE_APPROVAL_STEPS_TABLE = "\nCREATE TABLE IF NOT EXISTS approval_steps (\n  id TEXT PRIMARY KEY DEFAULT (lower(hex(randomblob(16)))),\n  document_id TEXT NOT NULL,\n  chain_id TEXT NOT NULL,\n  step_order INTEGER NOT NULL,\n  required_role TEXT NOT NULL,\n  status TEXT NOT NULL DEFAULT 'pending' CHECK(status IN ('pending','approved','rejected','skipped')),\n  decided_by TEXT,\n  decided_at TEXT,\n  reason TEXT,\n  FOREIGN KEY (document_id) REFERENCES documents(id) ON DELETE CASCADE,\n  FOREIGN KEY (chain_id) REFERENCES approval_chains(id) ON DELETE CASCADE,\n  FOREIGN KEY (decided_by) REFERENCES users(id) ON DELETE SET NULL\n)\n";
/**
 * Obligations table - contract obligation tracking
 * v32 addition
 */
export declare const CREATE_OBLIGATIONS_TABLE = "\nCREATE TABLE IF NOT EXISTS obligations (\n  id TEXT PRIMARY KEY DEFAULT (lower(hex(randomblob(16)))),\n  document_id TEXT NOT NULL,\n  extraction_id TEXT,\n  obligation_type TEXT NOT NULL CHECK(obligation_type IN ('payment', 'delivery', 'notification', 'renewal', 'termination', 'compliance', 'reporting', 'approval', 'other')),\n  description TEXT NOT NULL,\n  responsible_party TEXT,\n  due_date TEXT,\n  recurring TEXT,\n  status TEXT NOT NULL DEFAULT 'active' CHECK(status IN ('active','fulfilled','overdue','waived','expired')),\n  source_chunk_id TEXT,\n  source_page INTEGER,\n  confidence REAL DEFAULT 1.0,\n  created_at TEXT NOT NULL DEFAULT (datetime('now')),\n  metadata_json TEXT DEFAULT '{}',\n  FOREIGN KEY (document_id) REFERENCES documents(id) ON DELETE CASCADE,\n  FOREIGN KEY (extraction_id) REFERENCES extractions(id) ON DELETE SET NULL,\n  FOREIGN KEY (source_chunk_id) REFERENCES chunks(id) ON DELETE SET NULL\n)\n";
/**
 * Playbooks table - preferred terms for deviation detection
 * v32 addition
 */
export declare const CREATE_PLAYBOOKS_TABLE = "\nCREATE TABLE IF NOT EXISTS playbooks (\n  id TEXT PRIMARY KEY DEFAULT (lower(hex(randomblob(16)))),\n  name TEXT NOT NULL,\n  description TEXT,\n  clauses_json TEXT NOT NULL,\n  created_at TEXT NOT NULL DEFAULT (datetime('now')),\n  updated_at TEXT NOT NULL DEFAULT (datetime('now')),\n  created_by TEXT,\n  FOREIGN KEY (created_by) REFERENCES users(id) ON DELETE SET NULL\n)\n";
/**
 * Webhooks table - outbound event notifications
 * v32 addition
 */
export declare const CREATE_WEBHOOKS_TABLE = "\nCREATE TABLE IF NOT EXISTS webhooks (\n  id TEXT PRIMARY KEY DEFAULT (lower(hex(randomblob(16)))),\n  url TEXT NOT NULL,\n  events TEXT NOT NULL,\n  secret TEXT,\n  is_active INTEGER NOT NULL DEFAULT 1,\n  created_by TEXT,\n  created_at TEXT NOT NULL DEFAULT (datetime('now')),\n  last_triggered_at TEXT,\n  failure_count INTEGER DEFAULT 0,\n  FOREIGN KEY (created_by) REFERENCES users(id) ON DELETE SET NULL\n)\n";
/**
 * All required indexes for query performance
 */
export declare const CREATE_INDEXES: readonly ["CREATE INDEX IF NOT EXISTS idx_documents_file_path ON documents(file_path)", "CREATE INDEX IF NOT EXISTS idx_documents_file_hash ON documents(file_hash)", "CREATE INDEX IF NOT EXISTS idx_documents_status ON documents(status)", "CREATE INDEX IF NOT EXISTS idx_ocr_results_document_id ON ocr_results(document_id)", "CREATE INDEX IF NOT EXISTS idx_chunks_document_id ON chunks(document_id)", "CREATE INDEX IF NOT EXISTS idx_chunks_ocr_result_id ON chunks(ocr_result_id)", "CREATE INDEX IF NOT EXISTS idx_chunks_embedding_status ON chunks(embedding_status)", "CREATE INDEX IF NOT EXISTS idx_embeddings_chunk_id ON embeddings(chunk_id)", "CREATE INDEX IF NOT EXISTS idx_embeddings_image_id ON embeddings(image_id)", "CREATE INDEX IF NOT EXISTS idx_embeddings_document_id ON embeddings(document_id)", "CREATE INDEX IF NOT EXISTS idx_embeddings_source_file ON embeddings(source_file_path)", "CREATE INDEX IF NOT EXISTS idx_embeddings_page ON embeddings(page_number)", "CREATE INDEX IF NOT EXISTS idx_embeddings_extraction_id ON embeddings(extraction_id)", "CREATE INDEX IF NOT EXISTS idx_images_document_id ON images(document_id)", "CREATE INDEX IF NOT EXISTS idx_images_ocr_result_id ON images(ocr_result_id)", "CREATE INDEX IF NOT EXISTS idx_images_page ON images(document_id, page_number)", "CREATE INDEX IF NOT EXISTS idx_images_vlm_status ON images(vlm_status)", "CREATE INDEX IF NOT EXISTS idx_images_content_hash ON images(content_hash)", "CREATE INDEX IF NOT EXISTS idx_images_pending ON images(vlm_status) WHERE vlm_status = 'pending'", "CREATE INDEX IF NOT EXISTS idx_images_provenance_id ON images(provenance_id)", "CREATE INDEX IF NOT EXISTS idx_extractions_document_id ON extractions(document_id)", "CREATE INDEX IF NOT EXISTS idx_form_fills_status ON form_fills(status)", "CREATE INDEX IF NOT EXISTS idx_documents_doc_title ON documents(doc_title)", "CREATE INDEX IF NOT EXISTS idx_documents_doc_author ON documents(doc_author)", "CREATE INDEX IF NOT EXISTS idx_documents_doc_subject ON documents(doc_subject)", "CREATE INDEX IF NOT EXISTS idx_provenance_source_id ON provenance(source_id)", "CREATE INDEX IF NOT EXISTS idx_provenance_type ON provenance(type)", "CREATE INDEX IF NOT EXISTS idx_provenance_root_document_id ON provenance(root_document_id)", "CREATE INDEX IF NOT EXISTS idx_provenance_parent_id ON provenance(parent_id)", "CREATE INDEX IF NOT EXISTS idx_uploaded_files_file_hash ON uploaded_files(file_hash)", "CREATE INDEX IF NOT EXISTS idx_uploaded_files_status ON uploaded_files(upload_status)", "CREATE INDEX IF NOT EXISTS idx_uploaded_files_datalab_file_id ON uploaded_files(datalab_file_id)", "CREATE INDEX IF NOT EXISTS idx_comparisons_doc1 ON comparisons(document_id_1)", "CREATE INDEX IF NOT EXISTS idx_comparisons_doc2 ON comparisons(document_id_2)", "CREATE INDEX IF NOT EXISTS idx_comparisons_created ON comparisons(created_at)", "CREATE INDEX IF NOT EXISTS idx_clusters_run_id ON clusters(run_id)", "CREATE INDEX IF NOT EXISTS idx_clusters_tag ON clusters(classification_tag)", "CREATE INDEX IF NOT EXISTS idx_clusters_created ON clusters(created_at DESC)", "CREATE INDEX IF NOT EXISTS idx_doc_clusters_document ON document_clusters(document_id)", "CREATE INDEX IF NOT EXISTS idx_doc_clusters_cluster ON document_clusters(cluster_id)", "CREATE INDEX IF NOT EXISTS idx_doc_clusters_run ON document_clusters(run_id)", "CREATE INDEX IF NOT EXISTS idx_saved_searches_name ON saved_searches(name)", "CREATE INDEX IF NOT EXISTS idx_saved_searches_search_type ON saved_searches(search_type)", "CREATE INDEX IF NOT EXISTS idx_saved_searches_created ON saved_searches(created_at DESC)", "CREATE INDEX IF NOT EXISTS idx_entity_tags_entity ON entity_tags(entity_id, entity_type)", "CREATE INDEX IF NOT EXISTS idx_entity_tags_tag ON entity_tags(tag_id)", "CREATE INDEX IF NOT EXISTS idx_chunks_section_path ON chunks(section_path)", "CREATE INDEX IF NOT EXISTS idx_chunks_heading_level ON chunks(heading_level)", "CREATE INDEX IF NOT EXISTS idx_users_external_id ON users(external_id)", "CREATE INDEX IF NOT EXISTS idx_users_role ON users(role)", "CREATE INDEX IF NOT EXISTS idx_audit_log_user ON audit_log(user_id)", "CREATE INDEX IF NOT EXISTS idx_audit_log_action ON audit_log(action)", "CREATE INDEX IF NOT EXISTS idx_audit_log_entity ON audit_log(entity_type, entity_id)", "CREATE INDEX IF NOT EXISTS idx_audit_log_created ON audit_log(created_at)", "CREATE INDEX IF NOT EXISTS idx_annotations_document ON annotations(document_id)", "CREATE INDEX IF NOT EXISTS idx_annotations_chunk ON annotations(chunk_id)", "CREATE INDEX IF NOT EXISTS idx_annotations_user ON annotations(user_id)", "CREATE INDEX IF NOT EXISTS idx_annotations_type ON annotations(annotation_type)", "CREATE INDEX IF NOT EXISTS idx_annotations_status ON annotations(status)", "CREATE INDEX IF NOT EXISTS idx_workflow_document ON workflow_states(document_id)", "CREATE INDEX IF NOT EXISTS idx_workflow_state ON workflow_states(state)", "CREATE INDEX IF NOT EXISTS idx_workflow_assigned ON workflow_states(assigned_to)", "CREATE INDEX IF NOT EXISTS idx_workflow_due ON workflow_states(due_date)", "CREATE INDEX IF NOT EXISTS idx_approval_steps_doc ON approval_steps(document_id)", "CREATE INDEX IF NOT EXISTS idx_approval_steps_status ON approval_steps(status)", "CREATE INDEX IF NOT EXISTS idx_obligations_document ON obligations(document_id)", "CREATE INDEX IF NOT EXISTS idx_obligations_type ON obligations(obligation_type)", "CREATE INDEX IF NOT EXISTS idx_obligations_due ON obligations(due_date)", "CREATE INDEX IF NOT EXISTS idx_obligations_status ON obligations(status)"];
/**
 * Table definitions for creating tables in dependency order
 */
export declare const TABLE_DEFINITIONS: readonly [{
    readonly name: "provenance";
    readonly sql: "\nCREATE TABLE IF NOT EXISTS provenance (\n  id TEXT PRIMARY KEY,\n  type TEXT NOT NULL CHECK (type IN ('DOCUMENT', 'OCR_RESULT', 'CHUNK', 'IMAGE', 'VLM_DESCRIPTION', 'EMBEDDING', 'EXTRACTION', 'FORM_FILL', 'COMPARISON', 'CLUSTERING')),\n  created_at TEXT NOT NULL,\n  processed_at TEXT NOT NULL,\n  source_file_created_at TEXT,\n  source_file_modified_at TEXT,\n  source_type TEXT NOT NULL CHECK (source_type IN ('FILE', 'OCR', 'CHUNKING', 'IMAGE_EXTRACTION', 'VLM', 'VLM_DEDUP', 'EMBEDDING', 'EXTRACTION', 'FORM_FILL', 'COMPARISON', 'CLUSTERING')),\n  source_path TEXT,\n  source_id TEXT,\n  root_document_id TEXT NOT NULL,\n  location TEXT,\n  content_hash TEXT NOT NULL,\n  input_hash TEXT,\n  file_hash TEXT,\n  processor TEXT NOT NULL,\n  processor_version TEXT NOT NULL,\n  processing_params TEXT NOT NULL,\n  processing_duration_ms INTEGER,\n  processing_quality_score REAL,\n  parent_id TEXT,\n  parent_ids TEXT NOT NULL,\n  chain_depth INTEGER NOT NULL,\n  chain_path TEXT,\n  user_id TEXT,\n  agent_id TEXT,\n  agent_metadata_json TEXT,\n  chain_hash TEXT,\n  FOREIGN KEY (source_id) REFERENCES provenance(id),\n  FOREIGN KEY (parent_id) REFERENCES provenance(id)\n)\n";
}, {
    readonly name: "database_metadata";
    readonly sql: "\nCREATE TABLE IF NOT EXISTS database_metadata (\n  id INTEGER PRIMARY KEY CHECK (id = 1),\n  database_name TEXT NOT NULL,\n  database_version TEXT NOT NULL,\n  created_at TEXT NOT NULL,\n  last_modified_at TEXT NOT NULL,\n  total_documents INTEGER NOT NULL DEFAULT 0,\n  total_ocr_results INTEGER NOT NULL DEFAULT 0,\n  total_chunks INTEGER NOT NULL DEFAULT 0,\n  total_embeddings INTEGER NOT NULL DEFAULT 0\n)\n";
}, {
    readonly name: "documents";
    readonly sql: "\nCREATE TABLE IF NOT EXISTS documents (\n  id TEXT PRIMARY KEY,\n  file_path TEXT NOT NULL,\n  file_name TEXT NOT NULL,\n  file_hash TEXT NOT NULL,\n  file_size INTEGER NOT NULL,\n  file_type TEXT NOT NULL,\n  status TEXT NOT NULL CHECK (status IN ('pending', 'processing', 'complete', 'failed')),\n  page_count INTEGER,\n  provenance_id TEXT NOT NULL UNIQUE,\n  created_at TEXT NOT NULL,\n  modified_at TEXT,\n  ocr_completed_at TEXT,\n  error_message TEXT,\n  doc_title TEXT,\n  doc_author TEXT,\n  doc_subject TEXT,\n  datalab_file_id TEXT,\n  FOREIGN KEY (provenance_id) REFERENCES provenance(id)\n)\n";
}, {
    readonly name: "ocr_results";
    readonly sql: "\nCREATE TABLE IF NOT EXISTS ocr_results (\n  id TEXT PRIMARY KEY,\n  provenance_id TEXT NOT NULL UNIQUE,\n  document_id TEXT NOT NULL,\n  extracted_text TEXT NOT NULL,\n  text_length INTEGER NOT NULL,\n  datalab_request_id TEXT NOT NULL,\n  datalab_mode TEXT NOT NULL CHECK (datalab_mode IN ('fast', 'balanced', 'accurate')),\n  parse_quality_score REAL,\n  page_count INTEGER NOT NULL,\n  cost_cents REAL,\n  content_hash TEXT NOT NULL,\n  processing_started_at TEXT NOT NULL,\n  processing_completed_at TEXT NOT NULL,\n  processing_duration_ms INTEGER NOT NULL,\n  json_blocks TEXT,\n  extras_json TEXT,\n  FOREIGN KEY (provenance_id) REFERENCES provenance(id),\n  FOREIGN KEY (document_id) REFERENCES documents(id)\n)\n";
}, {
    readonly name: "chunks";
    readonly sql: "\nCREATE TABLE IF NOT EXISTS chunks (\n  id TEXT PRIMARY KEY,\n  document_id TEXT NOT NULL,\n  ocr_result_id TEXT NOT NULL,\n  text TEXT NOT NULL CHECK(length(trim(text)) > 0),\n  text_hash TEXT NOT NULL,\n  chunk_index INTEGER NOT NULL,\n  character_start INTEGER NOT NULL,\n  character_end INTEGER NOT NULL,\n  page_number INTEGER,\n  page_range TEXT,\n  overlap_previous INTEGER NOT NULL,\n  overlap_next INTEGER NOT NULL,\n  provenance_id TEXT NOT NULL UNIQUE,\n  created_at TEXT NOT NULL,\n  embedding_status TEXT NOT NULL CHECK (embedding_status IN ('pending', 'complete', 'failed')),\n  embedded_at TEXT,\n  ocr_quality_score REAL,\n  heading_context TEXT,\n  heading_level INTEGER,\n  section_path TEXT,\n  content_types TEXT,\n  is_atomic INTEGER NOT NULL DEFAULT 0,\n  chunking_strategy TEXT NOT NULL DEFAULT 'hybrid_section',\n  FOREIGN KEY (document_id) REFERENCES documents(id),\n  FOREIGN KEY (ocr_result_id) REFERENCES ocr_results(id),\n  FOREIGN KEY (provenance_id) REFERENCES provenance(id)\n)\n";
}, {
    readonly name: "embeddings";
    readonly sql: "\nCREATE TABLE IF NOT EXISTS embeddings (\n  id TEXT PRIMARY KEY,\n  chunk_id TEXT,\n  image_id TEXT,\n  extraction_id TEXT,\n  document_id TEXT NOT NULL,\n  original_text TEXT NOT NULL,\n  original_text_length INTEGER NOT NULL,\n  source_file_path TEXT NOT NULL,\n  source_file_name TEXT NOT NULL,\n  source_file_hash TEXT NOT NULL,\n  page_number INTEGER,\n  page_range TEXT,\n  character_start INTEGER NOT NULL,\n  character_end INTEGER NOT NULL,\n  chunk_index INTEGER NOT NULL,\n  total_chunks INTEGER NOT NULL,\n  model_name TEXT NOT NULL,\n  model_version TEXT NOT NULL,\n  task_type TEXT NOT NULL CHECK (task_type IN ('search_document', 'search_query')),\n  inference_mode TEXT NOT NULL CHECK (inference_mode = 'local'),\n  gpu_device TEXT,\n  provenance_id TEXT NOT NULL UNIQUE,\n  content_hash TEXT NOT NULL,\n  created_at TEXT NOT NULL,\n  generation_duration_ms INTEGER,\n  FOREIGN KEY (chunk_id) REFERENCES chunks(id),\n  FOREIGN KEY (image_id) REFERENCES images(id),\n  FOREIGN KEY (extraction_id) REFERENCES extractions(id),\n  FOREIGN KEY (document_id) REFERENCES documents(id),\n  FOREIGN KEY (provenance_id) REFERENCES provenance(id),\n  CHECK (chunk_id IS NOT NULL OR image_id IS NOT NULL OR extraction_id IS NOT NULL)\n)\n";
}, {
    readonly name: "images";
    readonly sql: "\nCREATE TABLE IF NOT EXISTS images (\n  id TEXT PRIMARY KEY,\n  document_id TEXT NOT NULL,\n  ocr_result_id TEXT NOT NULL,\n  page_number INTEGER NOT NULL,\n  bbox_x REAL NOT NULL,\n  bbox_y REAL NOT NULL,\n  bbox_width REAL NOT NULL,\n  bbox_height REAL NOT NULL,\n  image_index INTEGER NOT NULL,\n  format TEXT NOT NULL,\n  width INTEGER NOT NULL,\n  height INTEGER NOT NULL,\n  extracted_path TEXT,\n  file_size INTEGER,\n  vlm_status TEXT NOT NULL DEFAULT 'pending' CHECK (vlm_status IN ('pending', 'processing', 'complete', 'failed')),\n  vlm_description TEXT,\n  vlm_structured_data TEXT,\n  vlm_embedding_id TEXT,\n  vlm_model TEXT,\n  vlm_confidence REAL,\n  vlm_processed_at TEXT,\n  vlm_tokens_used INTEGER,\n  context_text TEXT,\n  provenance_id TEXT,\n  created_at TEXT NOT NULL,\n  error_message TEXT,\n  block_type TEXT,\n  is_header_footer INTEGER NOT NULL DEFAULT 0,\n  content_hash TEXT,\n  page_width REAL,\n  page_height REAL,\n  FOREIGN KEY (document_id) REFERENCES documents(id) ON DELETE CASCADE,\n  FOREIGN KEY (ocr_result_id) REFERENCES ocr_results(id) ON DELETE CASCADE,\n  FOREIGN KEY (vlm_embedding_id) REFERENCES embeddings(id),\n  FOREIGN KEY (provenance_id) REFERENCES provenance(id)\n)\n";
}, {
    readonly name: "extractions";
    readonly sql: "\nCREATE TABLE IF NOT EXISTS extractions (\n  id TEXT PRIMARY KEY NOT NULL,\n  document_id TEXT NOT NULL REFERENCES documents(id) ON DELETE CASCADE,\n  ocr_result_id TEXT NOT NULL REFERENCES ocr_results(id) ON DELETE CASCADE,\n  schema_json TEXT NOT NULL,\n  extraction_json TEXT NOT NULL,\n  content_hash TEXT NOT NULL,\n  provenance_id TEXT NOT NULL REFERENCES provenance(id),\n  created_at TEXT NOT NULL DEFAULT (datetime('now'))\n)\n";
}, {
    readonly name: "form_fills";
    readonly sql: "\nCREATE TABLE IF NOT EXISTS form_fills (\n  id TEXT PRIMARY KEY NOT NULL,\n  source_file_path TEXT NOT NULL,\n  source_file_hash TEXT NOT NULL,\n  field_data_json TEXT NOT NULL,\n  context TEXT,\n  confidence_threshold REAL NOT NULL DEFAULT 0.5,\n  output_file_path TEXT,\n  output_base64 TEXT,\n  fields_filled TEXT NOT NULL DEFAULT '[]',\n  fields_not_found TEXT NOT NULL DEFAULT '[]',\n  page_count INTEGER,\n  cost_cents REAL,\n  status TEXT NOT NULL CHECK(status IN ('pending', 'processing', 'complete', 'failed')),\n  error_message TEXT,\n  provenance_id TEXT NOT NULL REFERENCES provenance(id),\n  created_at TEXT NOT NULL DEFAULT (datetime('now'))\n)\n";
}, {
    readonly name: "uploaded_files";
    readonly sql: "\nCREATE TABLE IF NOT EXISTS uploaded_files (\n  id TEXT PRIMARY KEY NOT NULL,\n  local_path TEXT NOT NULL,\n  file_name TEXT NOT NULL,\n  file_hash TEXT NOT NULL,\n  file_size INTEGER NOT NULL,\n  content_type TEXT NOT NULL,\n  datalab_file_id TEXT,\n  datalab_reference TEXT,\n  upload_status TEXT NOT NULL DEFAULT 'pending'\n    CHECK (upload_status IN ('pending', 'uploading', 'confirming', 'complete', 'failed')),\n  error_message TEXT,\n  created_at TEXT NOT NULL DEFAULT (datetime('now')),\n  completed_at TEXT,\n  provenance_id TEXT NOT NULL REFERENCES provenance(id)\n)";
}, {
    readonly name: "comparisons";
    readonly sql: "\nCREATE TABLE IF NOT EXISTS comparisons (\n  id TEXT PRIMARY KEY NOT NULL,\n  document_id_1 TEXT NOT NULL REFERENCES documents(id),\n  document_id_2 TEXT NOT NULL REFERENCES documents(id),\n  similarity_ratio REAL NOT NULL,\n  text_diff_json TEXT NOT NULL,\n  structural_diff_json TEXT NOT NULL,\n  summary TEXT NOT NULL,\n  content_hash TEXT NOT NULL,\n  provenance_id TEXT NOT NULL REFERENCES provenance(id),\n  created_at TEXT NOT NULL DEFAULT (datetime('now')),\n  processing_duration_ms INTEGER\n)";
}, {
    readonly name: "clusters";
    readonly sql: "\nCREATE TABLE IF NOT EXISTS clusters (\n  id TEXT PRIMARY KEY NOT NULL,\n  run_id TEXT NOT NULL,\n  cluster_index INTEGER NOT NULL,\n  label TEXT,\n  description TEXT,\n  classification_tag TEXT,\n  document_count INTEGER NOT NULL DEFAULT 0,\n  centroid_json TEXT,\n  top_terms_json TEXT,\n  coherence_score REAL,\n  algorithm TEXT NOT NULL,\n  algorithm_params_json TEXT NOT NULL,\n  silhouette_score REAL,\n  content_hash TEXT NOT NULL,\n  provenance_id TEXT NOT NULL UNIQUE REFERENCES provenance(id),\n  created_at TEXT NOT NULL,\n  processing_duration_ms INTEGER\n)";
}, {
    readonly name: "document_clusters";
    readonly sql: "\nCREATE TABLE IF NOT EXISTS document_clusters (\n  id TEXT PRIMARY KEY NOT NULL,\n  document_id TEXT NOT NULL REFERENCES documents(id),\n  cluster_id TEXT REFERENCES clusters(id),\n  run_id TEXT NOT NULL,\n  similarity_to_centroid REAL NOT NULL,\n  membership_probability REAL NOT NULL DEFAULT 1.0,\n  is_noise INTEGER NOT NULL DEFAULT 0,\n  assigned_at TEXT NOT NULL,\n  UNIQUE(document_id, run_id)\n)";
}, {
    readonly name: "saved_searches";
    readonly sql: "\nCREATE TABLE IF NOT EXISTS saved_searches (\n  id TEXT PRIMARY KEY,\n  name TEXT NOT NULL,\n  query TEXT NOT NULL,\n  search_type TEXT NOT NULL CHECK (search_type IN ('bm25', 'semantic', 'hybrid')),\n  search_params TEXT NOT NULL DEFAULT '{}',\n  result_count INTEGER NOT NULL,\n  result_ids TEXT NOT NULL DEFAULT '[]',\n  created_at TEXT NOT NULL DEFAULT (datetime('now')),\n  notes TEXT,\n  last_executed_at TEXT,\n  execution_count INTEGER DEFAULT 0,\n  user_id TEXT,\n  is_shared INTEGER DEFAULT 0,\n  alert_enabled INTEGER DEFAULT 0,\n  last_alert_at TEXT\n)\n";
}, {
    readonly name: "tags";
    readonly sql: "\nCREATE TABLE IF NOT EXISTS tags (\n  id TEXT PRIMARY KEY NOT NULL,\n  name TEXT NOT NULL UNIQUE,\n  description TEXT,\n  color TEXT,\n  created_at TEXT NOT NULL DEFAULT (datetime('now'))\n)";
}, {
    readonly name: "entity_tags";
    readonly sql: "\nCREATE TABLE IF NOT EXISTS entity_tags (\n  id TEXT PRIMARY KEY NOT NULL,\n  tag_id TEXT NOT NULL REFERENCES tags(id) ON DELETE CASCADE,\n  entity_id TEXT NOT NULL,\n  entity_type TEXT NOT NULL CHECK(entity_type IN ('document', 'chunk', 'image', 'extraction', 'cluster')),\n  created_at TEXT NOT NULL DEFAULT (datetime('now')),\n  UNIQUE(tag_id, entity_id, entity_type)\n)";
}, {
    readonly name: "users";
    readonly sql: "\nCREATE TABLE IF NOT EXISTS users (\n  id TEXT PRIMARY KEY DEFAULT (lower(hex(randomblob(16)))),\n  external_id TEXT UNIQUE,\n  display_name TEXT NOT NULL,\n  email TEXT,\n  role TEXT NOT NULL DEFAULT 'viewer' CHECK(role IN ('viewer','reviewer','editor','admin')),\n  created_at TEXT NOT NULL DEFAULT (datetime('now')),\n  last_active_at TEXT,\n  metadata_json TEXT DEFAULT '{}'\n)\n";
}, {
    readonly name: "audit_log";
    readonly sql: "\nCREATE TABLE IF NOT EXISTS audit_log (\n  id INTEGER PRIMARY KEY AUTOINCREMENT,\n  user_id TEXT,\n  session_id TEXT,\n  action TEXT NOT NULL,\n  entity_type TEXT,\n  entity_id TEXT,\n  details_json TEXT DEFAULT '{}',\n  ip_address TEXT,\n  created_at TEXT NOT NULL DEFAULT (datetime('now')),\n  FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL\n)\n";
}, {
    readonly name: "annotations";
    readonly sql: "\nCREATE TABLE IF NOT EXISTS annotations (\n  id TEXT PRIMARY KEY DEFAULT (lower(hex(randomblob(16)))),\n  document_id TEXT NOT NULL,\n  user_id TEXT,\n  chunk_id TEXT,\n  page_number INTEGER,\n  annotation_type TEXT NOT NULL CHECK(annotation_type IN ('comment', 'correction', 'question', 'highlight', 'flag', 'approval')),\n  content TEXT NOT NULL,\n  status TEXT NOT NULL DEFAULT 'open' CHECK(status IN ('open', 'resolved', 'dismissed')),\n  parent_id TEXT,\n  created_at TEXT NOT NULL DEFAULT (datetime('now')),\n  updated_at TEXT NOT NULL DEFAULT (datetime('now')),\n  FOREIGN KEY (document_id) REFERENCES documents(id) ON DELETE CASCADE,\n  FOREIGN KEY (chunk_id) REFERENCES chunks(id) ON DELETE SET NULL,\n  FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL,\n  FOREIGN KEY (parent_id) REFERENCES annotations(id) ON DELETE CASCADE\n)\n";
}, {
    readonly name: "document_locks";
    readonly sql: "\nCREATE TABLE IF NOT EXISTS document_locks (\n  document_id TEXT PRIMARY KEY,\n  user_id TEXT NOT NULL,\n  session_id TEXT NOT NULL,\n  lock_type TEXT NOT NULL CHECK(lock_type IN ('exclusive', 'shared')),\n  reason TEXT,\n  acquired_at TEXT NOT NULL DEFAULT (datetime('now')),\n  expires_at TEXT NOT NULL,\n  FOREIGN KEY (document_id) REFERENCES documents(id) ON DELETE CASCADE,\n  FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE\n)\n";
}, {
    readonly name: "workflow_states";
    readonly sql: "\nCREATE TABLE IF NOT EXISTS workflow_states (\n  id TEXT PRIMARY KEY DEFAULT (lower(hex(randomblob(16)))),\n  document_id TEXT NOT NULL,\n  state TEXT NOT NULL CHECK(state IN ('draft', 'submitted', 'in_review', 'changes_requested', 'approved', 'rejected', 'executed', 'expired', 'archived')),\n  assigned_to TEXT,\n  assigned_by TEXT,\n  reason TEXT,\n  due_date TEXT,\n  completed_at TEXT,\n  created_at TEXT NOT NULL DEFAULT (datetime('now')),\n  metadata_json TEXT DEFAULT '{}',\n  FOREIGN KEY (document_id) REFERENCES documents(id) ON DELETE CASCADE,\n  FOREIGN KEY (assigned_to) REFERENCES users(id) ON DELETE SET NULL,\n  FOREIGN KEY (assigned_by) REFERENCES users(id) ON DELETE SET NULL\n)\n";
}, {
    readonly name: "approval_chains";
    readonly sql: "\nCREATE TABLE IF NOT EXISTS approval_chains (\n  id TEXT PRIMARY KEY DEFAULT (lower(hex(randomblob(16)))),\n  name TEXT NOT NULL,\n  description TEXT,\n  steps_json TEXT NOT NULL,\n  created_at TEXT NOT NULL DEFAULT (datetime('now')),\n  created_by TEXT,\n  FOREIGN KEY (created_by) REFERENCES users(id) ON DELETE SET NULL\n)\n";
}, {
    readonly name: "approval_steps";
    readonly sql: "\nCREATE TABLE IF NOT EXISTS approval_steps (\n  id TEXT PRIMARY KEY DEFAULT (lower(hex(randomblob(16)))),\n  document_id TEXT NOT NULL,\n  chain_id TEXT NOT NULL,\n  step_order INTEGER NOT NULL,\n  required_role TEXT NOT NULL,\n  status TEXT NOT NULL DEFAULT 'pending' CHECK(status IN ('pending','approved','rejected','skipped')),\n  decided_by TEXT,\n  decided_at TEXT,\n  reason TEXT,\n  FOREIGN KEY (document_id) REFERENCES documents(id) ON DELETE CASCADE,\n  FOREIGN KEY (chain_id) REFERENCES approval_chains(id) ON DELETE CASCADE,\n  FOREIGN KEY (decided_by) REFERENCES users(id) ON DELETE SET NULL\n)\n";
}, {
    readonly name: "obligations";
    readonly sql: "\nCREATE TABLE IF NOT EXISTS obligations (\n  id TEXT PRIMARY KEY DEFAULT (lower(hex(randomblob(16)))),\n  document_id TEXT NOT NULL,\n  extraction_id TEXT,\n  obligation_type TEXT NOT NULL CHECK(obligation_type IN ('payment', 'delivery', 'notification', 'renewal', 'termination', 'compliance', 'reporting', 'approval', 'other')),\n  description TEXT NOT NULL,\n  responsible_party TEXT,\n  due_date TEXT,\n  recurring TEXT,\n  status TEXT NOT NULL DEFAULT 'active' CHECK(status IN ('active','fulfilled','overdue','waived','expired')),\n  source_chunk_id TEXT,\n  source_page INTEGER,\n  confidence REAL DEFAULT 1.0,\n  created_at TEXT NOT NULL DEFAULT (datetime('now')),\n  metadata_json TEXT DEFAULT '{}',\n  FOREIGN KEY (document_id) REFERENCES documents(id) ON DELETE CASCADE,\n  FOREIGN KEY (extraction_id) REFERENCES extractions(id) ON DELETE SET NULL,\n  FOREIGN KEY (source_chunk_id) REFERENCES chunks(id) ON DELETE SET NULL\n)\n";
}, {
    readonly name: "playbooks";
    readonly sql: "\nCREATE TABLE IF NOT EXISTS playbooks (\n  id TEXT PRIMARY KEY DEFAULT (lower(hex(randomblob(16)))),\n  name TEXT NOT NULL,\n  description TEXT,\n  clauses_json TEXT NOT NULL,\n  created_at TEXT NOT NULL DEFAULT (datetime('now')),\n  updated_at TEXT NOT NULL DEFAULT (datetime('now')),\n  created_by TEXT,\n  FOREIGN KEY (created_by) REFERENCES users(id) ON DELETE SET NULL\n)\n";
}, {
    readonly name: "webhooks";
    readonly sql: "\nCREATE TABLE IF NOT EXISTS webhooks (\n  id TEXT PRIMARY KEY DEFAULT (lower(hex(randomblob(16)))),\n  url TEXT NOT NULL,\n  events TEXT NOT NULL,\n  secret TEXT,\n  is_active INTEGER NOT NULL DEFAULT 1,\n  created_by TEXT,\n  created_at TEXT NOT NULL DEFAULT (datetime('now')),\n  last_triggered_at TEXT,\n  failure_count INTEGER DEFAULT 0,\n  FOREIGN KEY (created_by) REFERENCES users(id) ON DELETE SET NULL\n)\n";
}];
/**
 * Required tables for schema verification
 */
export declare const REQUIRED_TABLES: readonly ["schema_version", "provenance", "database_metadata", "documents", "ocr_results", "chunks", "embeddings", "vec_embeddings", "images", "chunks_fts", "fts_index_metadata", "vlm_fts", "extractions", "form_fills", "extractions_fts", "uploaded_files", "comparisons", "clusters", "document_clusters", "saved_searches", "tags", "entity_tags", "documents_fts", "users", "audit_log", "annotations", "document_locks", "workflow_states", "approval_chains", "approval_steps", "obligations", "playbooks", "webhooks"];
/**
 * Required indexes for schema verification
 */
export declare const REQUIRED_INDEXES: readonly ["idx_documents_file_path", "idx_documents_file_hash", "idx_documents_status", "idx_ocr_results_document_id", "idx_chunks_document_id", "idx_chunks_ocr_result_id", "idx_chunks_embedding_status", "idx_embeddings_chunk_id", "idx_embeddings_image_id", "idx_embeddings_document_id", "idx_embeddings_source_file", "idx_embeddings_page", "idx_embeddings_extraction_id", "idx_images_document_id", "idx_images_ocr_result_id", "idx_images_page", "idx_images_vlm_status", "idx_images_pending", "idx_images_provenance_id", "idx_images_content_hash", "idx_provenance_source_id", "idx_provenance_type", "idx_provenance_root_document_id", "idx_provenance_parent_id", "idx_extractions_document_id", "idx_form_fills_status", "idx_documents_doc_title", "idx_documents_doc_author", "idx_documents_doc_subject", "idx_uploaded_files_file_hash", "idx_uploaded_files_status", "idx_uploaded_files_datalab_file_id", "idx_comparisons_doc1", "idx_comparisons_doc2", "idx_comparisons_created", "idx_clusters_run_id", "idx_clusters_tag", "idx_clusters_created", "idx_doc_clusters_document", "idx_doc_clusters_cluster", "idx_doc_clusters_run", "idx_saved_searches_name", "idx_saved_searches_search_type", "idx_saved_searches_created", "idx_entity_tags_entity", "idx_entity_tags_tag", "idx_chunks_section_path", "idx_chunks_heading_level", "idx_users_external_id", "idx_users_role", "idx_audit_log_user", "idx_audit_log_action", "idx_audit_log_entity", "idx_audit_log_created", "idx_annotations_document", "idx_annotations_chunk", "idx_annotations_user", "idx_annotations_type", "idx_annotations_status", "idx_workflow_document", "idx_workflow_state", "idx_workflow_assigned", "idx_workflow_due", "idx_approval_steps_doc", "idx_approval_steps_status", "idx_obligations_document", "idx_obligations_type", "idx_obligations_due", "idx_obligations_status"];
//# sourceMappingURL=schema-definitions.d.ts.map