Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
add [properties-be] - project metadata (#614)
Daniel Kweon1c2993616132
diff --git a/rust/cloud-storage/models_properties/src/service/mod.rs b/rust/cloud-storage/models_properties/src/service/mod.rsindex 74f3c504b1..0eab763237 100644--- a/rust/cloud-storage/models_properties/src/service/mod.rs+++ b/rust/cloud-storage/models_properties/src/service/mod.rs@@ -6,6 +6,7 @@pub mod document_metadata;pub mod entity_property;pub mod entity_property_with_definition;+pub mod project_metadata;pub mod property_definition;pub mod property_definition_with_options;pub mod property_option;diff --git a/rust/cloud-storage/models_properties/src/service/project_metadata.rs b/rust/cloud-storage/models_properties/src/service/project_metadata.rsnew file mode 100644index 0000000000..f1cbf5ff54--- /dev/null+++ b/rust/cloud-storage/models_properties/src/service/project_metadata.rs@@ -0,0 +1,14 @@+//! Project metadata model for properties service++use sqlx::FromRow;++/// Project metadata from the Project table+#[derive(Debug, Clone, FromRow)]+pub struct ProjectMetadata {+ pub id: String,+ pub name: String,+ pub owner: String,+ pub created_at: chrono::DateTime<chrono::Utc>,+ pub updated_at: chrono::DateTime<chrono::Utc>,+ pub parent_id: Option<String>,+}diff --git a/rust/cloud-storage/properties_db_client/.sqlx/query-3e259ea5cbdcfae4334cb0125de6423fa95a0c127fbeba0a59d7096b0177c072.json b/rust/cloud-storage/properties_db_client/.sqlx/query-3e259ea5cbdcfae4334cb0125de6423fa95a0c127fbeba0a59d7096b0177c072.jsonnew file mode 100644index 0000000000..8ee9d7919b--- /dev/null+++ b/rust/cloud-storage/properties_db_client/.sqlx/query-3e259ea5cbdcfae4334cb0125de6423fa95a0c127fbeba0a59d7096b0177c072.json@@ -0,0 +1,52 @@+{+ "db_name": "PostgreSQL",+ "query": "\n SELECT\n p.id,\n p.name,\n p.\"userId\" as \"owner\",\n p.\"parentId\" as \"parent_id\",\n p.\"createdAt\"::timestamptz as \"created_at!\",\n p.\"updatedAt\"::timestamptz as \"updated_at!\"\n FROM\n \"Project\" p\n WHERE\n p.id = $1 AND p.\"deletedAt\" IS NULL\n ",+ "describe": {+ "columns": [+ {+ "ordinal": 0,+ "name": "id",+ "type_info": "Text"+ },+ {+ "ordinal": 1,+ "name": "name",+ "type_info": "Text"+ },+ {+ "ordinal": 2,+ "name": "owner",+ "type_info": "Text"+ },+ {+ "ordinal": 3,+ "name": "parent_id",+ "type_info": "Text"+ },+ {+ "ordinal": 4,+ "name": "created_at!",+ "type_info": "Timestamptz"+ },+ {+ "ordinal": 5,+ "name": "updated_at!",+ "type_info": "Timestamptz"+ }+ ],+ "parameters": {+ "Left": [+ "Text"+ ]+ },+ "nullable": [+ false,+ false,+ false,+ true,+ null,+ null+ ]+ },+ "hash": "3e259ea5cbdcfae4334cb0125de6423fa95a0c127fbeba0a59d7096b0177c072"+}diff --git a/rust/cloud-storage/properties_db_client/src/lib.rs b/rust/cloud-storage/properties_db_client/src/lib.rsindex aebafbf502..425ab61e0b 100644--- a/rust/cloud-storage/properties_db_client/src/lib.rs+++ b/rust/cloud-storage/properties_db_client/src/lib.rs@@ -6,6 +6,7 @@pub mod document_metadata;pub mod entity_properties;pub mod error;+pub mod project_metadata;pub mod property_definitions;pub mod property_options;pub mod thread_metadata;diff --git a/rust/cloud-storage/properties_db_client/src/project_metadata/get.rs b/rust/cloud-storage/properties_db_client/src/project_metadata/get.rsnew file mode 100644index 0000000000..471b6db615--- /dev/null+++ b/rust/cloud-storage/properties_db_client/src/project_metadata/get.rs@@ -0,0 +1,35 @@+//! Get project metadata from macrodb.++use crate::error::PropertiesDatabaseError;+use models_properties::service::project_metadata::ProjectMetadata;+use sqlx::{Pool, Postgres};++type Result<T> = std::result::Result<T, PropertiesDatabaseError>;++/// Get project metadata by project ID from macrodb+#[tracing::instrument(skip(db), err)]+pub async fn get_project_metadata(+ db: &Pool<Postgres>,+ project_id: &str,+) -> Result<Option<ProjectMetadata>> {+ sqlx::query_as!(+ ProjectMetadata,+ r#"+ SELECT+ p.id,+ p.name,+ p."userId" as "owner",+ p."parentId" as "parent_id",+ p."createdAt"::timestamptz as "created_at!",+ p."updatedAt"::timestamptz as "updated_at!"+ FROM+ "Project" p+ WHERE+ p.id = $1 AND p."deletedAt" IS NULL+ "#,+ project_id+ )+ .fetch_optional(db)+ .await+ .map_err(PropertiesDatabaseError::Query)+}diff --git a/rust/cloud-storage/properties_db_client/src/project_metadata/mod.rs b/rust/cloud-storage/properties_db_client/src/project_metadata/mod.rsnew file mode 100644index 0000000000..3432b80980--- /dev/null+++ b/rust/cloud-storage/properties_db_client/src/project_metadata/mod.rs@@ -0,0 +1,3 @@+//! Project metadata queries for properties service++pub mod get;diff --git a/rust/cloud-storage/properties_service/src/api/properties/entities/get.rs b/rust/cloud-storage/properties_service/src/api/properties/entities/get.rsindex e97614eec3..d1f91a59eb 100644--- a/rust/cloud-storage/properties_service/src/api/properties/entities/get.rs+++ b/rust/cloud-storage/properties_service/src/api/properties/entities/get.rs@@ -118,6 +118,13 @@ pub async fn get_entity_properties().await}+ EntityType::Project => {+ super::super::metadata::get_project_metadata_properties(+ &context.db,+ &entity_id,+ )+ .await+ }_ => {tracing::debug!(entity_type = ?entity_type,diff --git a/rust/cloud-storage/properties_service/src/api/properties/metadata.rs b/rust/cloud-storage/properties_service/src/api/properties/metadata.rsindex c10d3e5c79..5b0632fbe4 100644--- a/rust/cloud-storage/properties_service/src/api/properties/metadata.rs+++ b/rust/cloud-storage/properties_service/src/api/properties/metadata.rs@@ -46,7 +46,7 @@ pub async fn get_document_metadata_properties(let owner = (!document_metadata.owner.is_empty()).then(|| EntityReference::new(document_metadata.owner, EntityType::User));metadata_properties.push(create_metadata_property_entity_ref(- metadata::DOCUMENT_OWNER,+ metadata::OWNER,models_properties::DataType::Entity,owner,entity_type,@@ -55,7 +55,7 @@ pub async fn get_document_metadata_properties(// 3. Created time propertymetadata_properties.push(create_metadata_property_date(- metadata::DOCUMENT_CREATED_AT,+ metadata::CREATED_AT,models_properties::DataType::Date,Some(document_metadata.created_at),entity_type,@@ -63,7 +63,7 @@ pub async fn get_document_metadata_properties(// 4. Last updated time propertymetadata_properties.push(create_metadata_property_date(- metadata::DOCUMENT_LAST_UPDATED,+ metadata::LAST_UPDATED,models_properties::DataType::Date,Some(document_metadata.updated_at),entity_type,@@ -138,6 +138,71 @@ pub async fn get_thread_metadata_properties(Ok(metadata_properties)}+/// Get project metadata properties from macrodb+#[tracing::instrument(skip(db), err)]+pub async fn get_project_metadata_properties(+ db: &Pool<Postgres>,+ project_id: &str,+) -> Result<Vec<EntityPropertyWithDefinition>, MetadataError> {+ let project_metadata =+ properties_db_client::project_metadata::get::get_project_metadata(db, project_id)+ .await?+ .ok_or(MetadataError::NotFound)?;++ let entity_type = EntityType::Project;++ // 1. Project name property+ let name = (!project_metadata.name.is_empty()).then_some(project_metadata.name);++ // 2. Owner property+ let owner = (!project_metadata.owner.is_empty())+ .then(|| EntityReference::new(project_metadata.owner, EntityType::User));++ // 5. Parent project property+ let parent = project_metadata+ .parent_id+ .map(|id| EntityReference::new(id, EntityType::Project));++ let metadata_properties = vec![+ create_metadata_property_str(+ metadata::PROJECT_NAME,+ models_properties::DataType::String,+ name,+ entity_type,+ ),+ create_metadata_property_entity_ref(+ metadata::OWNER,+ models_properties::DataType::Entity,+ owner,+ entity_type,+ Some(EntityType::User),+ ),+ // 3. Created time property+ create_metadata_property_date(+ metadata::CREATED_AT,+ models_properties::DataType::Date,+ Some(project_metadata.created_at),+ entity_type,+ ),+ // 4. Last updated time property+ create_metadata_property_date(+ metadata::LAST_UPDATED,+ models_properties::DataType::Date,+ Some(project_metadata.updated_at),+ entity_type,+ ),+ create_metadata_property_entity_ref(+ metadata::PROJECT_PARENT,+ models_properties::DataType::Entity,+ parent,+ entity_type,+ Some(EntityType::Project),+ ),+ ];++ Ok(metadata_properties)+}+// ===== Metadata Property Helpers =====//// These helpers create read-only metadata properties that are computed on-the-flydiff --git a/rust/cloud-storage/properties_service/src/constants.rs b/rust/cloud-storage/properties_service/src/constants.rsindex dcbad75bd8..bce44313d0 100644--- a/rust/cloud-storage/properties_service/src/constants.rs+++ b/rust/cloud-storage/properties_service/src/constants.rs@@ -2,11 +2,13 @@ use uuid::Uuid;/// Metadata property display namespub mod metadata {+ // Common (shared across entity types)+ pub const OWNER: &str = "Owner";+ pub const CREATED_AT: &str = "Created At";+ pub const LAST_UPDATED: &str = "Last Updated";+// Document metadatapub const DOCUMENT_NAME: &str = "Document Name";- pub const DOCUMENT_OWNER: &str = "Owner";- pub const DOCUMENT_CREATED_AT: &str = "Created At";- pub const DOCUMENT_LAST_UPDATED: &str = "Last Updated";pub const DOCUMENT_PROJECT: &str = "Project";// Thread metadata@@ -15,6 +17,10 @@ pub mod metadata {pub const THREAD_LAST_RECEIVED: &str = "Last Received";pub const THREAD_LAST_SENT: &str = "Last Sent";pub const THREAD_MESSAGES: &str = "Messages";++ // Project metadata+ pub const PROJECT_NAME: &str = "Project Name";+ pub const PROJECT_PARENT: &str = "Parent Project";}/// Special UUID used for system-generated metadata properties.