diff --git a/common/build.rs b/common/build.rs index 16a8c4aa..33791b95 100644 --- a/common/build.rs +++ b/common/build.rs @@ -19,6 +19,10 @@ fn main() -> Result<(), Box> { .type_attribute(".komp_ac.search", serde) .type_attribute(".komp_ac.search2", serde) .type_attribute(".komp_ac.table_definition", serde) + .type_attribute( + ".komp_ac.table_definition.ColumnDefinition", + "#[serde(default)]", + ) .type_attribute(".komp_ac.table_script", serde) .type_attribute(".komp_ac.table_structure", serde) .type_attribute(".komp_ac.table_validation", serde) diff --git a/common/proto/table_definition.proto b/common/proto/table_definition.proto index 64d93d15..3e1281e2 100644 --- a/common/proto/table_definition.proto +++ b/common/proto/table_definition.proto @@ -121,9 +121,9 @@ message PostTableDefinitionRequest { // allowed. string table_name = 1; - // The table's columns, including its links and stored linked projections. - // A projection uses field_type FROM(link_column.source_column); its physical - // type and money metadata are inferred from the linked source column. + // The table's columns, including its links and stored linked values. + // A linked value uses ColumnDefinition.linked_value; its physical type and + // money metadata are inferred from the linked source column. repeated ColumnDefinition columns = 3; // Column names to index, matching names declared above. System columns @@ -276,7 +276,7 @@ message AddTableColumnsRequest { string table_name = 2; // New user-defined columns only. Existing columns cannot be changed here. - // Stored linked projections use field_type FROM(link_column.source_column). + // Stored linked values use ColumnDefinition.linked_value. repeated ColumnDefinition columns = 3; // Optional indexes for the new columns only. @@ -359,9 +359,6 @@ message ColumnDefinition { // LINK(table) → BIGINT referencing that table in the same profile, indexed // automatically. A table may hold several links to the same // target as long as the columns are named differently. - // FROM(link.source) → stored, read-only copy of an atomic column reached - // through another column in this definition whose type is - // LINK(...). SQL type and money metadata are inferred. string field_type = 2; // MONEY rounding applied before a value is stored. @@ -381,6 +378,19 @@ message ColumnDefinition { // Enables a Boolean ledger on Boolean columns. ANY means // one true contribution wins; ALL means one false contribution wins. BooleanLedgerOperator boolean_ledger = 7; + + // Defines this named column as a stored, read-only value copied through an + // existing LINK column. field_type and money metadata are inferred from the + // source column and must not be supplied by the caller. + optional LinkedValueDefinition linked_value = 8; +} + +message LinkedValueDefinition { + // Exact display name of a LINK column in the table being defined. + string link_column = 1; + + // Exact display name of an atomic column in the linked table. + string source_column = 2; } enum BooleanLedgerOperator { diff --git a/common/src/proto/descriptor.bin b/common/src/proto/descriptor.bin index bd7a59ab..30145289 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 1770d8c6..cde3e16f 100644 --- a/common/src/proto/komp_ac.table_definition.rs +++ b/common/src/proto/komp_ac.table_definition.rs @@ -25,9 +25,9 @@ pub struct PostTableDefinitionRequest { /// allowed. #[prost(string, tag = "1")] pub table_name: ::prost::alloc::string::String, - /// The table's columns, including its links and stored linked projections. - /// A projection uses field_type FROM(link_column.source_column); its physical - /// type and money metadata are inferred from the linked source column. + /// The table's columns, including its links and stored linked values. + /// A linked value uses ColumnDefinition.linked_value; its physical type and + /// money metadata are inferred from the linked source column. #[prost(message, repeated, tag = "3")] pub columns: ::prost::alloc::vec::Vec, /// Column names to index, matching names declared above. System columns @@ -201,7 +201,7 @@ pub struct AddTableColumnsRequest { #[prost(string, tag = "2")] pub table_name: ::prost::alloc::string::String, /// New user-defined columns only. Existing columns cannot be changed here. - /// Stored linked projections use field_type FROM(link_column.source_column). + /// Stored linked values use ColumnDefinition.linked_value. #[prost(message, repeated, tag = "3")] pub columns: ::prost::alloc::vec::Vec, /// Optional indexes for the new columns only. @@ -255,6 +255,7 @@ pub struct PutTableDefinitionResponse { } /// Describes one user-defined column for a table. #[derive(serde::Serialize, serde::Deserialize)] +#[serde(default)] #[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)] pub struct ColumnDefinition { /// Public display name for this column; the physical column uses a stable @@ -292,9 +293,6 @@ pub struct ColumnDefinition { /// LINK(table) → BIGINT referencing that table in the same profile, indexed /// automatically. A table may hold several links to the same /// target as long as the columns are named differently. - /// FROM(link.source) → stored, read-only copy of an atomic column reached - /// through another column in this definition whose type is - /// LINK(...). SQL type and money metadata are inferred. #[prost(string, tag = "2")] pub field_type: ::prost::alloc::string::String, /// MONEY rounding applied before a value is stored. @@ -316,6 +314,21 @@ pub struct ColumnDefinition { #[prost(enumeration = "BooleanLedgerOperator", tag = "7")] #[serde(default, alias = "boolean_ledger_operator")] pub boolean_ledger: i32, + /// Defines this named column as a stored, read-only value copied through an + /// existing LINK column. field_type and money metadata are inferred from the + /// source column and must not be supplied by the caller. + #[prost(message, optional, tag = "8")] + pub linked_value: ::core::option::Option, +} +#[derive(serde::Serialize, serde::Deserialize)] +#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)] +pub struct LinkedValueDefinition { + /// Exact display name of a LINK column in the table being defined. + #[prost(string, tag = "1")] + pub link_column: ::prost::alloc::string::String, + /// Exact display name of an atomic column in the linked table. + #[prost(string, tag = "2")] + pub source_column: ::prost::alloc::string::String, } /// Response after table creation (success + DDL preview). #[derive(serde::Serialize, serde::Deserialize)] diff --git a/web/src/schema/mod.rs b/web/src/schema/mod.rs index 17498bd2..b81fba26 100644 --- a/web/src/schema/mod.rs +++ b/web/src/schema/mod.rs @@ -1273,6 +1273,7 @@ pub(crate) fn proto_columns(columns: &[ColumnDefinition]) -> Vec