Skip to main content

uqa_storage/sqlite/
catalog.rs

1//
2// Unified Query Algebra
3//
4// Copyright (c) 2023-2026 Cognica, Inc.
5//
6
7//! Catalog: schema versioning, migrations, and persisted table metadata.
8//!
9//! The catalog owns a single `_metadata` table that records the schema version
10//! plus a `_tables` table holding per-table analyzer config and the lists
11//! of FTS / vector fields registered on each table. Concrete data tables
12//! (`_documents`, `_document_blobs`, `_posting_clusters`,
13//! `_posting_documents`, `_vectors`, ...) are created by catalog migrations
14//! before their respective stores are exposed.
15
16use rusqlite::{params, OptionalExtension};
17
18use crate::backend::{StorageBackendError, StorageBackendResult};
19use crate::catalog::{
20    CatalogFacade, CatalogIndexRow, ColumnStatsInput, ColumnStatsRow, EdgeRow, ForeignTableRow,
21    GraphSnapshot, RelationIdentity, RelationKind, SchemaRow, SequenceOptions,
22    SequenceReservationResult, SequenceRow, TableAclEntry, TableSchema, VectorFieldSchema, ViewRow,
23};
24use crate::sqlite::connection::{ManagedConnection, Result, SQLiteError};
25
26use super::catalog_lifecycle::{
27    columns_json_references, delete_table_rows_if_exists, drop_fts_aux_tables_for_field,
28    drop_fts_aux_tables_for_table, quote_sql_identifier, rename_btree_field_rows_or_keep_existing,
29    rename_field_rows_or_keep_existing, rename_fts_aux_tables_for_field, renamed_columns_json,
30    table_exists, update_btree_table_name_rows_if_exists, update_table_name_rows_if_exists,
31};
32
33/// Bump this every time a migration is added.
34pub const CURRENT_SCHEMA_VERSION: u32 = 46;
35
36const LEGACY_VIEWS_METADATA_KEY: &str = "sql_views_json";
37const LEGACY_SEQUENCES_METADATA_KEY: &str = "sql_sequences_json";
38
39pub struct Catalog {
40    conn: ManagedConnection,
41    fts_storage_was_reset: bool,
42}
43
44mod analyzers;
45mod cache_revisions;
46mod facade;
47mod foreign_indexes;
48mod graph;
49mod graph_access;
50mod migration;
51mod models_scoring;
52mod path_index_data;
53mod schema_tables;
54mod sequences_views;
55mod stats;
56
57use migration::{decode_catalog_id, encode_catalog_id, migration_relation};
58
59#[cfg(test)]
60mod tests;