diff --git a/client b/client index e40a195..2465eb9 160000 --- a/client +++ b/client @@ -1 +1 @@ -Subproject commit e40a1955819d131c8c2915a62ade3e817095598f +Subproject commit 2465eb9ca99946aab8e2b435d0e73907a989c163 diff --git a/common/proto/table_definition.proto b/common/proto/table_definition.proto index dbb3551..0136ef0 100644 --- a/common/proto/table_definition.proto +++ b/common/proto/table_definition.proto @@ -171,6 +171,9 @@ message ProfileTreeResponse { // Column whose value is used as the human-readable row label. string row_display_column = 4; + + // "dynamic" for user-defined tables, "system" for backend-managed tables. + string table_kind = 5; } // Profile (schema) entry. @@ -247,6 +250,7 @@ message TableDetail { string base_currency = 5; string row_display_column = 6; map column_behaviors = 7; + string table_kind = 8; } // Server-owned behavior for one logical column returned in table details. diff --git a/common/src/proto/descriptor.bin b/common/src/proto/descriptor.bin index f4e6650..172bac1 100644 Binary files a/common/src/proto/descriptor.bin and b/common/src/proto/descriptor.bin differ diff --git a/common/src/proto/komp_ac.table_definition.rs b/common/src/proto/komp_ac.table_definition.rs index eeab0a0..71dc7a9 100644 --- a/common/src/proto/komp_ac.table_definition.rs +++ b/common/src/proto/komp_ac.table_definition.rs @@ -143,6 +143,9 @@ pub mod profile_tree_response { /// Column whose value is used as the human-readable row label. #[prost(string, tag = "4")] pub row_display_column: ::prost::alloc::string::String, + /// "dynamic" for user-defined tables, "system" for backend-managed tables. + #[prost(string, tag = "5")] + pub table_kind: ::prost::alloc::string::String, } /// Profile (schema) entry. #[derive(Clone, PartialEq, ::prost::Message)] @@ -252,6 +255,8 @@ pub struct TableDetail { ::prost::alloc::string::String, ColumnBehavior, >, + #[prost(string, tag = "8")] + pub table_kind: ::prost::alloc::string::String, } /// Server-owned behavior for one logical column returned in table details. #[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)] diff --git a/common/src/search.rs b/common/src/search.rs index 8342a2a..b973142 100644 --- a/common/src/search.rs +++ b/common/src/search.rs @@ -17,7 +17,7 @@ pub const F_ALL_TEXT: &str = "all_text"; pub const F_DATA_WORD: &str = "data_word"; pub const F_DATA_NGRAM: &str = "data_ngram"; pub const F_DATA_EXACT: &str = "data_exact"; -pub const JOURNAL_SEARCH_TABLE_NAME: &str = "journal_entries"; +pub const JOURNAL_TABLE_NAME: &str = "journal_entries"; pub const TOK_WORD: &str = "kw_word"; pub const TOK_NGRAM: &str = "kw_ngram"; diff --git a/search/src/lib.rs b/search/src/lib.rs index 696ce69..fde5b71 100644 --- a/search/src/lib.rs +++ b/search/src/lib.rs @@ -9,9 +9,7 @@ pub use common::proto::komp_ac::search::searcher_server::SearcherServer; use common::proto::komp_ac::search::{ SearchOrderDirection, SearchRequest, SearchResponse, search_response::Hit, }; -use common::search::{ - JOURNAL_SEARCH_TABLE_NAME, SchemaFields, register_tokenizers, search_index_path, -}; +use common::search::{SchemaFields, register_tokenizers, search_index_path}; use query_builder::{ ConstraintMode, SearchConstraint, SearchConstraintTarget, build_master_query, }; @@ -273,10 +271,6 @@ async fn profile_exists(pool: &PgPool, profile_name: &str) -> Result Result { - if table_name == JOURNAL_SEARCH_TABLE_NAME { - return profile_exists(pool, profile_name).await; - } - let exists = sqlx::query_scalar::<_, bool>( r#" SELECT EXISTS( @@ -481,10 +475,6 @@ async fn table_physical_to_display_map( profile_name: &str, table_name: &str, ) -> Result, Status> { - if table_name == JOURNAL_SEARCH_TABLE_NAME { - return Ok(HashMap::new()); - } - let rows = sqlx::query( r#" SELECT tdc.physical_name, tdc.display_name @@ -519,10 +509,6 @@ async fn table_row_display_column( profile_name: &str, table_name: &str, ) -> Result { - if table_name == JOURNAL_SEARCH_TABLE_NAME { - return Ok("journal_name".to_string()); - } - sqlx::query_scalar( r#" SELECT td.row_display_column @@ -674,15 +660,6 @@ async fn fetch_ordered_rows( limit: usize, offset: usize, ) -> Result, Status> { - if table_name == JOURNAL_SEARCH_TABLE_NAME { - if order.is_some() { - return Err(Status::invalid_argument( - "Explicit ordering is not supported for journal search", - )); - } - return fetch_journal_rows(pool, profile_name, limit, offset).await; - } - let physical_to_display = table_physical_to_display_map(pool, profile_name, table_name).await?; let display_column = table_row_display_column(pool, profile_name, table_name).await?; let (resolved_order, direction) = match order { @@ -731,53 +708,6 @@ async fn fetch_ordered_rows( .collect()) } -async fn fetch_journal_rows( - pool: &PgPool, - profile_name: &str, - limit: usize, - offset: usize, -) -> Result, Status> { - let rows = sqlx::query( - r#"WITH positioned AS ( - SELECT journal.*, - ROW_NUMBER() OVER (ORDER BY journal.id) AS picker_position - FROM journal_entries journal - JOIN schemas schema_meta ON schema_meta.id = journal.schema_id - WHERE schema_meta.name = $1 - ) - SELECT id, - to_jsonb(positioned) - 'schema_id' - 'picker_position' AS data, - picker_position - FROM positioned - ORDER BY picker_position DESC - LIMIT $2 OFFSET $3"#, - ) - .bind(profile_name) - .bind(limit as i64) - .bind(offset as i64) - .fetch_all(pool) - .await - .map_err(|error| Status::internal(format!("Journal list query failed: {}", error)))?; - - Ok(rows - .into_iter() - .map(|row| { - let id: i64 = row.try_get("id").unwrap_or_default(); - let json_data: serde_json::Value = row.try_get("data").unwrap_or_default(); - let position: i64 = row.try_get("picker_position").unwrap_or_default(); - Hit { - id, - score: 0.0, - row_display_value: row_display_value(&json_data, "journal_name"), - content_json: json_data.to_string(), - table_name: JOURNAL_SEARCH_TABLE_NAME.to_string(), - row_display_column: "journal_name".to_string(), - position: u64::try_from(position).ok(), - } - }) - .collect()) -} - async fn run_search( pool: &PgPool, profile: &ProfileIndex, @@ -860,11 +790,6 @@ async fn run_search( if let Some(order) = order { let table_name = table_filter.expect("ordered searches require a normalized table filter"); - if table_name == JOURNAL_SEARCH_TABLE_NAME { - return Err(Status::invalid_argument( - "Explicit ordering is not supported for journal search", - )); - } return fetch_ordered_candidate_rows( pool, profile_name, @@ -891,27 +816,14 @@ async fn run_search( let physical_to_display = table_physical_to_display_map(pool, profile_name, &table_name).await?; let display_column = table_row_display_column(pool, profile_name, &table_name).await?; - let rows = if table_name == JOURNAL_SEARCH_TABLE_NAME { - sqlx::query( - r#"SELECT journal.id, to_jsonb(journal) - 'schema_id' AS data - FROM journal_entries journal - JOIN schemas schema_meta ON schema_meta.id = journal.schema_id - WHERE schema_meta.name = $1 AND journal.id = ANY($2)"#, - ) - .bind(profile_name) + let sql = format!( + "SELECT id, to_jsonb(t) AS data FROM {} t WHERE deleted = FALSE AND id = ANY($1)", + qualify_profile_table(profile_name, &table_name) + ); + let rows = sqlx::query(AssertSqlSafe(sql)) .bind(&pg_ids) .fetch_all(pool) .await - } else { - let sql = format!( - "SELECT id, to_jsonb(t) AS data FROM {} t WHERE deleted = FALSE AND id = ANY($1)", - qualify_profile_table(profile_name, &table_name) - ); - sqlx::query(AssertSqlSafe(sql)) - .bind(&pg_ids) - .fetch_all(pool) - .await - } .map_err(|e| Status::internal(format!("Database query failed: {}", e)))?; for row in rows { diff --git a/server b/server index 9e7a186..9fa5673 160000 --- a/server +++ b/server @@ -1 +1 @@ -Subproject commit 9e7a186a0ab247582511598b720c3987443cef3e +Subproject commit 9fa56738c557e46c297b7fd740beacb1d8664681 diff --git a/tui-canvas b/tui-canvas index 8e14380..2a1849f 160000 --- a/tui-canvas +++ b/tui-canvas @@ -1 +1 @@ -Subproject commit 8e143805fdea77dea932ad17e9ec423c1d1c596f +Subproject commit 2a1849fb95d9c942fac4eecf7a260b46a92d3020 diff --git a/tui-pages b/tui-pages index cfce2e5..76e6d56 160000 --- a/tui-pages +++ b/tui-pages @@ -1 +1 @@ -Subproject commit cfce2e590b2277e0defcc0efbc3b227c0060d141 +Subproject commit 76e6d5688fd43a81b72557013d2a0410e240ff23