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
feat(comms-service): Add width and height columns for message attachments (#562)
Evan Hutnik4b1097201143
diff --git a/rust/cloud-storage/comms_db_client/.sqlx/query-32cdd5c07081705c34a75e8eecf359cc3637aa316bd6874304b2086e7ca49642.json b/rust/cloud-storage/comms_db_client/.sqlx/query-32cdd5c07081705c34a75e8eecf359cc3637aa316bd6874304b2086e7ca49642.jsondeleted file mode 100644index c9077e0be2..0000000000--- a/rust/cloud-storage/comms_db_client/.sqlx/query-32cdd5c07081705c34a75e8eecf359cc3637aa316bd6874304b2086e7ca49642.json+++ /dev/null@@ -1,56 +0,0 @@-{- "db_name": "PostgreSQL",- "query": "\n INSERT INTO comms_attachments (id, message_id, channel_id, entity_type, entity_id)\n VALUES ($1, $2, $3, $4, $5)\n RETURNING\n id,\n message_id,\n channel_id,\n entity_type,\n entity_id,\n created_at\n ",- "describe": {- "columns": [- {- "ordinal": 0,- "name": "id",- "type_info": "Uuid"- },- {- "ordinal": 1,- "name": "message_id",- "type_info": "Uuid"- },- {- "ordinal": 2,- "name": "channel_id",- "type_info": "Uuid"- },- {- "ordinal": 3,- "name": "entity_type",- "type_info": "Varchar"- },- {- "ordinal": 4,- "name": "entity_id",- "type_info": "Varchar"- },- {- "ordinal": 5,- "name": "created_at",- "type_info": "Timestamptz"- }- ],- "parameters": {- "Left": [- "Uuid",- "Uuid",- "Uuid",- "Varchar",- "Varchar"- ]- },- "nullable": [- false,- false,- false,- false,- false,- false- ]- },- "hash": "32cdd5c07081705c34a75e8eecf359cc3637aa316bd6874304b2086e7ca49642"-}diff --git a/rust/cloud-storage/comms_db_client/.sqlx/query-0a798d764d3ec3bf03b32bb8f68d8d84a992b81a40399628fee524488537fe01.json b/rust/cloud-storage/comms_db_client/.sqlx/query-52cc02c4d43669d3a1c8f350e3af7c261071298ef899917c3380d56d4873e0d2.jsonsimilarity index 71%rename from rust/cloud-storage/comms_db_client/.sqlx/query-0a798d764d3ec3bf03b32bb8f68d8d84a992b81a40399628fee524488537fe01.jsonrename to rust/cloud-storage/comms_db_client/.sqlx/query-52cc02c4d43669d3a1c8f350e3af7c261071298ef899917c3380d56d4873e0d2.jsonindex b2f0c4f007..08b2dd3e86 100644--- a/rust/cloud-storage/comms_db_client/.sqlx/query-0a798d764d3ec3bf03b32bb8f68d8d84a992b81a40399628fee524488537fe01.json+++ b/rust/cloud-storage/comms_db_client/.sqlx/query-52cc02c4d43669d3a1c8f350e3af7c261071298ef899917c3380d56d4873e0d2.json@@ -1,6 +1,6 @@{"db_name": "PostgreSQL",- "query": "\n SELECT\n id,\n message_id as \"message_id: Uuid\",\n channel_id as \"channel_id: Uuid\",\n entity_type,\n entity_id,\n created_at\n FROM comms_attachments\n WHERE message_id = $1",+ "query": "\n SELECT\n id,\n message_id as \"message_id: Uuid\",\n channel_id as \"channel_id: Uuid\",\n entity_type,\n entity_id,\n width,\n height,\n created_at\n FROM comms_attachments\n WHERE message_id = $1","describe": {"columns": [{@@ -30,6 +30,16 @@},{"ordinal": 5,+ "name": "width",+ "type_info": "Int4"+ },+ {+ "ordinal": 6,+ "name": "height",+ "type_info": "Int4"+ },+ {+ "ordinal": 7,"name": "created_at","type_info": "Timestamptz"}@@ -45,8 +55,10 @@false,false,false,+ true,+ true,false]},- "hash": "0a798d764d3ec3bf03b32bb8f68d8d84a992b81a40399628fee524488537fe01"+ "hash": "52cc02c4d43669d3a1c8f350e3af7c261071298ef899917c3380d56d4873e0d2"}diff --git a/rust/cloud-storage/comms_db_client/.sqlx/query-94f9fda1f244d002e67e4a84dd89200665019931bb78ceb57f82abf403445b7b.json b/rust/cloud-storage/comms_db_client/.sqlx/query-cbe989d8428852cbc096f4f28398b5c5352f1fc2369890ab77d90fb643b8d4c4.jsonsimilarity index 69%rename from rust/cloud-storage/comms_db_client/.sqlx/query-94f9fda1f244d002e67e4a84dd89200665019931bb78ceb57f82abf403445b7b.jsonrename to rust/cloud-storage/comms_db_client/.sqlx/query-cbe989d8428852cbc096f4f28398b5c5352f1fc2369890ab77d90fb643b8d4c4.jsonindex e9f7e2231d..8ab1279285 100644--- a/rust/cloud-storage/comms_db_client/.sqlx/query-94f9fda1f244d002e67e4a84dd89200665019931bb78ceb57f82abf403445b7b.json+++ b/rust/cloud-storage/comms_db_client/.sqlx/query-cbe989d8428852cbc096f4f28398b5c5352f1fc2369890ab77d90fb643b8d4c4.json@@ -1,6 +1,6 @@{"db_name": "PostgreSQL",- "query": "\n SELECT\n id,\n message_id as \"message_id: Uuid\",\n channel_id as \"channel_id: Uuid\",\n entity_type,\n entity_id,\n created_at\n FROM comms_attachments\n WHERE channel_id = $1\n ORDER BY created_at ASC\n ",+ "query": "\n SELECT\n id,\n message_id as \"message_id: Uuid\",\n channel_id as \"channel_id: Uuid\",\n entity_type,\n entity_id,\n width,\n height,\n created_at\n FROM comms_attachments\n WHERE channel_id = $1\n ORDER BY created_at ASC\n ","describe": {"columns": [{@@ -30,6 +30,16 @@},{"ordinal": 5,+ "name": "width",+ "type_info": "Int4"+ },+ {+ "ordinal": 6,+ "name": "height",+ "type_info": "Int4"+ },+ {+ "ordinal": 7,"name": "created_at","type_info": "Timestamptz"}@@ -45,8 +55,10 @@false,false,false,+ true,+ true,false]},- "hash": "94f9fda1f244d002e67e4a84dd89200665019931bb78ceb57f82abf403445b7b"+ "hash": "cbe989d8428852cbc096f4f28398b5c5352f1fc2369890ab77d90fb643b8d4c4"}diff --git a/rust/cloud-storage/comms_db_client/.sqlx/query-e58e7758d9e066abfb5c6d0e5d14ccd7925ff91159a77cc1bf4c94f8e910f2b1.json b/rust/cloud-storage/comms_db_client/.sqlx/query-e58e7758d9e066abfb5c6d0e5d14ccd7925ff91159a77cc1bf4c94f8e910f2b1.jsonnew file mode 100644index 0000000000..1da6bbfcbe--- /dev/null+++ b/rust/cloud-storage/comms_db_client/.sqlx/query-e58e7758d9e066abfb5c6d0e5d14ccd7925ff91159a77cc1bf4c94f8e910f2b1.json@@ -0,0 +1,70 @@+{+ "db_name": "PostgreSQL",+ "query": "\n INSERT INTO comms_attachments (id, message_id, channel_id, entity_type, entity_id, width, height)\n SELECT * FROM UNNEST($1::uuid[], $2::uuid[], $3::uuid[], $4::varchar[], $5::varchar[], $6::int[], $7::int[])\n RETURNING\n id,\n message_id,\n channel_id,\n entity_type,\n entity_id,\n width,\n height,\n created_at\n ",+ "describe": {+ "columns": [+ {+ "ordinal": 0,+ "name": "id",+ "type_info": "Uuid"+ },+ {+ "ordinal": 1,+ "name": "message_id",+ "type_info": "Uuid"+ },+ {+ "ordinal": 2,+ "name": "channel_id",+ "type_info": "Uuid"+ },+ {+ "ordinal": 3,+ "name": "entity_type",+ "type_info": "Varchar"+ },+ {+ "ordinal": 4,+ "name": "entity_id",+ "type_info": "Varchar"+ },+ {+ "ordinal": 5,+ "name": "width",+ "type_info": "Int4"+ },+ {+ "ordinal": 6,+ "name": "height",+ "type_info": "Int4"+ },+ {+ "ordinal": 7,+ "name": "created_at",+ "type_info": "Timestamptz"+ }+ ],+ "parameters": {+ "Left": [+ "UuidArray",+ "UuidArray",+ "UuidArray",+ "VarcharArray",+ "VarcharArray",+ "Int4Array",+ "Int4Array"+ ]+ },+ "nullable": [+ false,+ false,+ false,+ false,+ false,+ true,+ true,+ false+ ]+ },+ "hash": "e58e7758d9e066abfb5c6d0e5d14ccd7925ff91159a77cc1bf4c94f8e910f2b1"+}diff --git a/rust/cloud-storage/comms_db_client/src/attachments/get_attachments.rs b/rust/cloud-storage/comms_db_client/src/attachments/get_attachments.rsindex 6416464139..cf706c3f4e 100644--- a/rust/cloud-storage/comms_db_client/src/attachments/get_attachments.rs+++ b/rust/cloud-storage/comms_db_client/src/attachments/get_attachments.rs@@ -14,6 +14,8 @@ pub async fn get_attachments(db: &Pool<Postgres>, channel_id: &Uuid) -> Result<Vchannel_id as "channel_id: Uuid",entity_type,entity_id,+ width,+ height,created_atFROM comms_attachmentsWHERE channel_id = $1@@ -42,6 +44,8 @@ pub async fn get_attachments_by_message_id(channel_id as "channel_id: Uuid",entity_type,entity_id,+ width,+ height,created_atFROM comms_attachmentsWHERE message_id = $1"#,diff --git a/rust/cloud-storage/comms_db_client/src/messages/add_attachments.rs b/rust/cloud-storage/comms_db_client/src/messages/add_attachments.rsindex 230f7384f8..0685a36970 100644--- a/rust/cloud-storage/comms_db_client/src/messages/add_attachments.rs+++ b/rust/cloud-storage/comms_db_client/src/messages/add_attachments.rs@@ -1,4 +1,4 @@-use anyhow::{Context, Result};+use anyhow::Result;use sqlx::{Pool, Postgres};use uuid::Uuid;@@ -11,35 +11,45 @@ pub async fn add_attachments_to_message(channel_id: &Uuid,attachments: Vec<NewAttachment>,) -> Result<Vec<Attachment>> {- let mut created_attachments: Vec<Attachment> = vec![];+ if attachments.is_empty() {+ return Ok(vec![]);+ }++ let ids: Vec<Uuid> = attachments+ .iter()+ .map(|_| macro_uuid::generate_uuid_v7())+ .collect();++ let entity_types: Vec<String> = attachments.iter().map(|a| a.entity_type.clone()).collect();+ let entity_ids: Vec<String> = attachments.iter().map(|a| a.entity_id.clone()).collect();+ let widths: Vec<Option<i32>> = attachments.iter().map(|a| a.width).collect();+ let heights: Vec<Option<i32>> = attachments.iter().map(|a| a.height).collect();- for attachment in attachments {- let attachment_id = macro_uuid::generate_uuid_v7();- let new_attachment = sqlx::query_as!(- Attachment,- r#"- INSERT INTO comms_attachments (id, message_id, channel_id, entity_type, entity_id)- VALUES ($1, $2, $3, $4, $5)- RETURNING- id,- message_id,- channel_id,- entity_type,- entity_id,- created_at- "#,- attachment_id,+ let created_attachments = sqlx::query_as!(+ Attachment,+ r#"+ INSERT INTO comms_attachments (id, message_id, channel_id, entity_type, entity_id, width, height)+ SELECT * FROM UNNEST($1::uuid[], $2::uuid[], $3::uuid[], $4::varchar[], $5::varchar[], $6::int[], $7::int[])+ RETURNING+ id,message_id,channel_id,- attachment.entity_type,- attachment.entity_id,- )- .fetch_one(db)- .await- .context("unable to create attachment")?;-- created_attachments.push(new_attachment);- }+ entity_type,+ entity_id,+ width,+ height,+ created_at+ "#,+ &ids as &[Uuid],+ &vec![*message_id; attachments.len()] as &[Uuid],+ &vec![*channel_id; attachments.len()] as &[Uuid],+ &entity_types as &[String],+ &entity_ids as &[String],+ &widths as &[Option<i32>],+ &heights as &[Option<i32>]+ )+ .fetch_all(db)+ .await?;Ok(created_attachments)}diff --git a/rust/cloud-storage/comms_db_client/src/model/mod.rs b/rust/cloud-storage/comms_db_client/src/model/mod.rsindex 78e8e87b1f..88ab4a5a98 100644--- a/rust/cloud-storage/comms_db_client/src/model/mod.rs+++ b/rust/cloud-storage/comms_db_client/src/model/mod.rs@@ -36,6 +36,9 @@ pub struct Attachment {pub message_id: Uuid,pub entity_type: String,pub entity_id: String,+ /// dimensions of image/video+ pub width: Option<i32>,+ pub height: Option<i32>,pub created_at: chrono::DateTime<chrono::Utc>,}@@ -43,6 +46,9 @@ pub struct Attachment {pub struct NewAttachment {pub entity_type: String,pub entity_id: String,+ /// dimensions of image/video+ pub height: Option<i32>,+ pub width: Option<i32>,}#[derive(Debug, Clone, Serialize, Deserialize, ToSchema, PartialEq)]diff --git a/rust/cloud-storage/macro_db_client/migrations/20251211161224_comms_attachment_dimensions.sql b/rust/cloud-storage/macro_db_client/migrations/20251211161224_comms_attachment_dimensions.sqlnew file mode 100644index 0000000000..f0b98cbfd0--- /dev/null+++ b/rust/cloud-storage/macro_db_client/migrations/20251211161224_comms_attachment_dimensions.sql@@ -0,0 +1,4 @@+-- Add migration script here+ALTER TABLE public.comms_attachments+ ADD COLUMN width integer,+ADD COLUMN height integer;\ No newline at end of file