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::connection::{ManagedConnection, Result, SQLiteError};
19use uqa_storage::backend::{StorageBackendError, StorageBackendResult};
20use uqa_storage::catalog::{
21    CatalogFacade, CatalogIndexRow, ColumnStatsInput, ColumnStatsRow, EdgeRow, ForeignTableRow,
22    GraphSnapshot, RelationIdentity, RelationKind, SchemaRow, SequenceOptions,
23    SequenceReservationResult, SequenceRow, TableAclEntry, TableSchema, VectorFieldSchema, ViewRow,
24};
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 = 48;
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}
42
43mod analyzers;
44mod cache_revisions;
45mod facade;
46mod foreign_indexes;
47mod graph;
48mod graph_access;
49mod migration;
50mod models_scoring;
51mod path_index_data;
52mod schema_tables;
53mod sequences_views;
54mod stats;
55
56use migration::{decode_catalog_id, encode_catalog_id, migration_relation};
57
58#[cfg(test)]
59mod tests;