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(seed) cli seed commands (#1538)
Will Hutchinson0c3b6a5fbc75
diff --git a/rust/cloud-storage/comms_db_client/.sqlx/query-0d8ce94d378705522f09670658378808a603fd92d5415206114636d493a8a5b3.json b/rust/cloud-storage/comms_db_client/.sqlx/query-0d8ce94d378705522f09670658378808a603fd92d5415206114636d493a8a5b3.jsondeleted file mode 100644index afa9457989..0000000000--- a/rust/cloud-storage/comms_db_client/.sqlx/query-0d8ce94d378705522f09670658378808a603fd92d5415206114636d493a8a5b3.json+++ /dev/null@@ -1,22 +0,0 @@-{- "db_name": "PostgreSQL",- "query": "\n SELECT COUNT(*) as \"count!\"\n FROM comms_entity_mentions\n WHERE source_entity_type = 'message'\n AND source_entity_id = $1\n AND entity_type = 'document'\n AND entity_id = 'doc123'\n ",- "describe": {- "columns": [- {- "ordinal": 0,- "name": "count!",- "type_info": "Int8"- }- ],- "parameters": {- "Left": [- "Text"- ]- },- "nullable": [- null- ]- },- "hash": "0d8ce94d378705522f09670658378808a603fd92d5415206114636d493a8a5b3"-}diff --git a/rust/cloud-storage/comms_db_client/.sqlx/query-2556c2cf7833c3f764cc6f34f482370e1e16f1024fe838445befdb0d4a9183ba.json b/rust/cloud-storage/comms_db_client/.sqlx/query-2556c2cf7833c3f764cc6f34f482370e1e16f1024fe838445befdb0d4a9183ba.jsondeleted file mode 100644index 6166cbdea1..0000000000--- a/rust/cloud-storage/comms_db_client/.sqlx/query-2556c2cf7833c3f764cc6f34f482370e1e16f1024fe838445befdb0d4a9183ba.json+++ /dev/null@@ -1,14 +0,0 @@-{- "db_name": "PostgreSQL",- "query": "INSERT INTO comms_entity_mentions (id, source_entity_type, source_entity_id, entity_type, entity_id, user_id) VALUES (gen_random_uuid(), 'message', $1, 'doc', 'doc1', NULL)",- "describe": {- "columns": [],- "parameters": {- "Left": [- "Varchar"- ]- },- "nullable": []- },- "hash": "2556c2cf7833c3f764cc6f34f482370e1e16f1024fe838445befdb0d4a9183ba"-}diff --git a/rust/cloud-storage/comms_db_client/.sqlx/query-3d0e27d34fbe55dfd6f96147d768cd70022c79223e41060fb79d61fe8e1c1971.json b/rust/cloud-storage/comms_db_client/.sqlx/query-3d0e27d34fbe55dfd6f96147d768cd70022c79223e41060fb79d61fe8e1c1971.jsondeleted file mode 100644index 8298ecae86..0000000000--- a/rust/cloud-storage/comms_db_client/.sqlx/query-3d0e27d34fbe55dfd6f96147d768cd70022c79223e41060fb79d61fe8e1c1971.json+++ /dev/null@@ -1,22 +0,0 @@-{- "db_name": "PostgreSQL",- "query": "\n SELECT COUNT(*) as \"count!\"\n FROM comms_entity_mentions\n WHERE source_entity_type = 'message'\n AND source_entity_id = $1\n AND entity_type = 'document'\n AND entity_id = 'doc456'\n ",- "describe": {- "columns": [- {- "ordinal": 0,- "name": "count!",- "type_info": "Int8"- }- ],- "parameters": {- "Left": [- "Text"- ]- },- "nullable": [- null- ]- },- "hash": "3d0e27d34fbe55dfd6f96147d768cd70022c79223e41060fb79d61fe8e1c1971"-}diff --git a/rust/cloud-storage/comms_db_client/.sqlx/query-61246005cb69889a67ac46d2032f4fe9c1da7b19594f1b7dc59f2ed0a613dec1.json b/rust/cloud-storage/comms_db_client/.sqlx/query-61246005cb69889a67ac46d2032f4fe9c1da7b19594f1b7dc59f2ed0a613dec1.jsonnew file mode 100644index 0000000000..ccd0aadea5--- /dev/null+++ b/rust/cloud-storage/comms_db_client/.sqlx/query-61246005cb69889a67ac46d2032f4fe9c1da7b19594f1b7dc59f2ed0a613dec1.json@@ -0,0 +1,74 @@+{+ "db_name": "PostgreSQL",+ "query": "\n INSERT INTO comms_messages (id, channel_id, sender_id, content, thread_id)\n VALUES ($1, $2, $3, $4, $5)\n RETURNING\n id,\n channel_id,\n sender_id,\n content,\n created_at,\n updated_at,\n thread_id,\n edited_at as \"edited_at: chrono::DateTime<chrono::Utc>\",\n deleted_at as \"deleted_at: chrono::DateTime<chrono::Utc>\"\n ",+ "describe": {+ "columns": [+ {+ "ordinal": 0,+ "name": "id",+ "type_info": "Uuid"+ },+ {+ "ordinal": 1,+ "name": "channel_id",+ "type_info": "Uuid"+ },+ {+ "ordinal": 2,+ "name": "sender_id",+ "type_info": "Text"+ },+ {+ "ordinal": 3,+ "name": "content",+ "type_info": "Text"+ },+ {+ "ordinal": 4,+ "name": "created_at",+ "type_info": "Timestamptz"+ },+ {+ "ordinal": 5,+ "name": "updated_at",+ "type_info": "Timestamptz"+ },+ {+ "ordinal": 6,+ "name": "thread_id",+ "type_info": "Uuid"+ },+ {+ "ordinal": 7,+ "name": "edited_at: chrono::DateTime<chrono::Utc>",+ "type_info": "Timestamp"+ },+ {+ "ordinal": 8,+ "name": "deleted_at: chrono::DateTime<chrono::Utc>",+ "type_info": "Timestamp"+ }+ ],+ "parameters": {+ "Left": [+ "Uuid",+ "Uuid",+ "Text",+ "Text",+ "Uuid"+ ]+ },+ "nullable": [+ false,+ false,+ false,+ false,+ false,+ false,+ true,+ true,+ true+ ]+ },+ "hash": "61246005cb69889a67ac46d2032f4fe9c1da7b19594f1b7dc59f2ed0a613dec1"+}diff --git a/rust/cloud-storage/comms_db_client/.sqlx/query-67809c28827bd163e23a02284f0e90f4649aa8d50d5fb4d088e01cfd25b59738.json b/rust/cloud-storage/comms_db_client/.sqlx/query-67809c28827bd163e23a02284f0e90f4649aa8d50d5fb4d088e01cfd25b59738.jsondeleted file mode 100644index 42dc2bb6f2..0000000000--- a/rust/cloud-storage/comms_db_client/.sqlx/query-67809c28827bd163e23a02284f0e90f4649aa8d50d5fb4d088e01cfd25b59738.json+++ /dev/null@@ -1,28 +0,0 @@-{- "db_name": "PostgreSQL",- "query": "\n SELECT m.entity_id, m.entity_type\n FROM comms_entity_mentions m\n WHERE m.source_entity_type = 'message' AND m.source_entity_id = $1\n ",- "describe": {- "columns": [- {- "ordinal": 0,- "name": "entity_id",- "type_info": "Varchar"- },- {- "ordinal": 1,- "name": "entity_type",- "type_info": "Varchar"- }- ],- "parameters": {- "Left": [- "Text"- ]- },- "nullable": [- false,- false- ]- },- "hash": "67809c28827bd163e23a02284f0e90f4649aa8d50d5fb4d088e01cfd25b59738"-}diff --git a/rust/cloud-storage/comms_db_client/.sqlx/query-6afd9b2962faea63afc99a8d075fab233f34c6165c59a22c10804d3141b2c5cf.json b/rust/cloud-storage/comms_db_client/.sqlx/query-6afd9b2962faea63afc99a8d075fab233f34c6165c59a22c10804d3141b2c5cf.jsondeleted file mode 100644index e61e9fa094..0000000000--- a/rust/cloud-storage/comms_db_client/.sqlx/query-6afd9b2962faea63afc99a8d075fab233f34c6165c59a22c10804d3141b2c5cf.json+++ /dev/null@@ -1,20 +0,0 @@-{- "db_name": "PostgreSQL",- "query": "\n SELECT COUNT(*) as \"count!\"\n FROM comms_entity_mentions\n WHERE entity_id = 'user1' AND source_entity_id = 'different_doc'\n ",- "describe": {- "columns": [- {- "ordinal": 0,- "name": "count!",- "type_info": "Int8"- }- ],- "parameters": {- "Left": []- },- "nullable": [- null- ]- },- "hash": "6afd9b2962faea63afc99a8d075fab233f34c6165c59a22c10804d3141b2c5cf"-}diff --git a/rust/cloud-storage/comms_db_client/.sqlx/query-736b4d3f1ba6d173672bbac8e54b472b9f086d9a5a4784b71cc18c20098dd07c.json b/rust/cloud-storage/comms_db_client/.sqlx/query-736b4d3f1ba6d173672bbac8e54b472b9f086d9a5a4784b71cc18c20098dd07c.jsondeleted file mode 100644index ad5b83ae8e..0000000000--- a/rust/cloud-storage/comms_db_client/.sqlx/query-736b4d3f1ba6d173672bbac8e54b472b9f086d9a5a4784b71cc18c20098dd07c.json+++ /dev/null@@ -1,22 +0,0 @@-{- "db_name": "PostgreSQL",- "query": "\n SELECT COUNT(*) as \"count!\"\n FROM comms_entity_mentions\n WHERE id = $1\n ",- "describe": {- "columns": [- {- "ordinal": 0,- "name": "count!",- "type_info": "Int8"- }- ],- "parameters": {- "Left": [- "Uuid"- ]- },- "nullable": [- null- ]- },- "hash": "736b4d3f1ba6d173672bbac8e54b472b9f086d9a5a4784b71cc18c20098dd07c"-}diff --git a/rust/cloud-storage/comms_db_client/.sqlx/query-a07f0622de5a2491d3561e87eff3e856f48779041f64fee910a5dade485c25a8.json b/rust/cloud-storage/comms_db_client/.sqlx/query-a07f0622de5a2491d3561e87eff3e856f48779041f64fee910a5dade485c25a8.jsondeleted file mode 100644index a70ed472ac..0000000000--- a/rust/cloud-storage/comms_db_client/.sqlx/query-a07f0622de5a2491d3561e87eff3e856f48779041f64fee910a5dade485c25a8.json+++ /dev/null@@ -1,12 +0,0 @@-{- "db_name": "PostgreSQL",- "query": "INSERT INTO comms_entity_mentions (id, source_entity_type, source_entity_id, entity_type, entity_id, user_id) VALUES (gen_random_uuid(), 'doc', 'doc_source_mixed', 'doc', 'doc1', NULL)",- "describe": {- "columns": [],- "parameters": {- "Left": []- },- "nullable": []- },- "hash": "a07f0622de5a2491d3561e87eff3e856f48779041f64fee910a5dade485c25a8"-}diff --git a/rust/cloud-storage/comms_db_client/.sqlx/query-b128fe71ad8427cc37e6d0073c78ada6b4eb8c4866551479910c84e0003276e8.json b/rust/cloud-storage/comms_db_client/.sqlx/query-b128fe71ad8427cc37e6d0073c78ada6b4eb8c4866551479910c84e0003276e8.jsondeleted file mode 100644index 8408741d05..0000000000--- a/rust/cloud-storage/comms_db_client/.sqlx/query-b128fe71ad8427cc37e6d0073c78ada6b4eb8c4866551479910c84e0003276e8.json+++ /dev/null@@ -1,22 +0,0 @@-{- "db_name": "PostgreSQL",- "query": "\n SELECT COUNT(*) as \"count!\"\n FROM comms_entity_mentions\n WHERE entity_id IN ('user1', 'user2') AND source_entity_id = $1\n ",- "describe": {- "columns": [- {- "ordinal": 0,- "name": "count!",- "type_info": "Int8"- }- ],- "parameters": {- "Left": [- "Text"- ]- },- "nullable": [- null- ]- },- "hash": "b128fe71ad8427cc37e6d0073c78ada6b4eb8c4866551479910c84e0003276e8"-}diff --git a/rust/cloud-storage/comms_db_client/.sqlx/query-fbb7a67d2d807967ca1427760f257d85558674e7006c9421729aba9d6507cbfe.json b/rust/cloud-storage/comms_db_client/.sqlx/query-fbb7a67d2d807967ca1427760f257d85558674e7006c9421729aba9d6507cbfe.jsondeleted file mode 100644index 0096892f8e..0000000000--- a/rust/cloud-storage/comms_db_client/.sqlx/query-fbb7a67d2d807967ca1427760f257d85558674e7006c9421729aba9d6507cbfe.json+++ /dev/null@@ -1,22 +0,0 @@-{- "db_name": "PostgreSQL",- "query": "\n SELECT COUNT(*) as \"count!\"\n FROM comms_entity_mentions\n WHERE entity_id = 'user3' AND source_entity_id = $1\n ",- "describe": {- "columns": [- {- "ordinal": 0,- "name": "count!",- "type_info": "Int8"- }- ],- "parameters": {- "Left": [- "Text"- ]- },- "nullable": [- null- ]- },- "hash": "fbb7a67d2d807967ca1427760f257d85558674e7006c9421729aba9d6507cbfe"-}diff --git a/rust/cloud-storage/comms_db_client/src/channels/mod.rs b/rust/cloud-storage/comms_db_client/src/channels/mod.rsindex b61384f69c..3ac07e556a 100644--- a/rust/cloud-storage/comms_db_client/src/channels/mod.rs+++ b/rust/cloud-storage/comms_db_client/src/channels/mod.rs@@ -7,4 +7,5 @@ pub mod get_dm;pub mod get_mentions_for_channel;pub mod get_private;pub mod patch_channel;+pub mod seed_channel;pub mod updated_at;diff --git a/rust/cloud-storage/comms_db_client/src/channels/seed_channel.rs b/rust/cloud-storage/comms_db_client/src/channels/seed_channel.rsnew file mode 100644index 0000000000..abd75eef17--- /dev/null+++ b/rust/cloud-storage/comms_db_client/src/channels/seed_channel.rs@@ -0,0 +1,99 @@+use crate::activity;+use anyhow::{Context, Result};+#[allow(unused_imports)]+use model::comms::{ChannelType, ParticipantRole};+use sqlx::{Pool, Postgres};+use uuid::Uuid;++/// Options for seeding a channel with a pre-defined UUID.+#[derive(Debug)]+pub struct SeedChannelOptions {+ /// The pre-defined channel UUID.+ pub channel_id: Uuid,+ /// Optional channel name.+ pub name: Option<String>,+ /// The user ID of the channel owner.+ pub owner_id: String,+ /// Optional organization ID.+ pub org_id: Option<i64>,+ /// The type of channel.+ pub channel_type: ChannelType,+ /// List of participant user IDs (excluding the owner, who is added automatically).+ pub participants: Vec<String>,+}++/// Seed a channel with a pre-defined UUID.+///+/// Identical to `create_channel` but uses the provided `channel_id` instead of+/// auto-generating one.+pub async fn seed_channel(db: &Pool<Postgres>, options: SeedChannelOptions) -> Result<Uuid> {+ let mut transaction = db.begin().await?;++ // create the channel+ let channel = sqlx::query!(+ r#"+ INSERT INTO comms_channels (id, name, owner_id, org_id, channel_type)+ VALUES ($1, $2, $3, $4, $5)+ RETURNING id+ "#,+ options.channel_id,+ options.name,+ options.owner_id,+ options.org_id,+ options.channel_type as ChannelType+ )+ .fetch_one(&mut *transaction)+ .await+ .context("unable to create channel")?;++ // insert channel owner+ sqlx::query!(+ r#"+ INSERT INTO comms_channel_participants (channel_id, role, user_id)+ VALUES ($1, $2, $3)+ "#,+ channel.id,+ ParticipantRole::Owner as ParticipantRole,+ options.owner_id+ )+ .execute(&mut *transaction)+ .await+ .context("unable to create channel participant for owner")?;++ // Filter out the owner from the participants list+ let participants_without_owner: Vec<String> = options+ .participants+ .into_iter()+ .filter(|p| p != options.owner_id.as_str())+ .collect::<Vec<_>>();++ if !participants_without_owner.is_empty() {+ // insert channel participants+ for participant in participants_without_owner {+ sqlx::query!(+ r#"+ INSERT INTO comms_channel_participants (channel_id, role, user_id)+ VALUES ($1, $2, $3)+ "#,+ channel.id,+ ParticipantRole::Member as ParticipantRole,+ participant+ )+ .execute(&mut *transaction)+ .await+ .context("unable to create channel participant")?;+ }+ }++ // create activity for channel+ activity::create_activity::create_activity(&mut *transaction, &channel.id, &options.owner_id)+ .await+ .context("unable to create activity for channel")?;++ transaction+ .commit()+ .await+ .context("unable to commit transaction")?;++ Ok(channel.id)+}diff --git a/rust/cloud-storage/comms_db_client/src/messages/mod.rs b/rust/cloud-storage/comms_db_client/src/messages/mod.rsindex c85405052a..a14c665f08 100644--- a/rust/cloud-storage/comms_db_client/src/messages/mod.rs+++ b/rust/cloud-storage/comms_db_client/src/messages/mod.rs@@ -8,3 +8,4 @@ pub mod get_message_owner;pub mod get_messages;pub mod patch_message;pub mod read_message_with_context;+pub mod seed_message;diff --git a/rust/cloud-storage/comms_db_client/src/messages/seed_message.rs b/rust/cloud-storage/comms_db_client/src/messages/seed_message.rsnew file mode 100644index 0000000000..be3eaded4d--- /dev/null+++ b/rust/cloud-storage/comms_db_client/src/messages/seed_message.rs@@ -0,0 +1,72 @@+use crate::model::Message;+use anyhow::{Context, Result};+use macro_user_id::{cowlike::CowLike, user_id::MacroUserIdStr};+use sqlx::{Executor, Postgres};+use uuid::Uuid;++/// Options for seeding a message with a pre-defined UUID.+#[derive(Debug)]+pub struct SeedMessageOptions {+ /// The pre-defined message UUID.+ pub message_id: Uuid,+ /// The channel to post the message to.+ pub channel_id: Uuid,+ /// The user ID of the message sender.+ pub sender_id: String,+ /// The message content.+ pub content: String,+ /// Optional thread ID if this is a reply.+ pub thread_id: Option<Uuid>,+}++/// Seed a message with a pre-defined UUID.+///+/// Identical to `create_message` but uses the provided `message_id` instead of+/// auto-generating one.+#[tracing::instrument(skip(executor))]+pub async fn seed_message<'e, E>(executor: E, options: SeedMessageOptions) -> Result<Message>+where+ E: Executor<'e, Database = Postgres>,+{+ let message = sqlx::query!(+ r#"+ INSERT INTO comms_messages (id, channel_id, sender_id, content, thread_id)+ VALUES ($1, $2, $3, $4, $5)+ RETURNING+ id,+ channel_id,+ sender_id,+ content,+ created_at,+ updated_at,+ thread_id,+ edited_at as "edited_at: chrono::DateTime<chrono::Utc>",+ deleted_at as "deleted_at: chrono::DateTime<chrono::Utc>"+ "#,+ options.message_id,+ options.channel_id,+ options.sender_id,+ options.content,+ options.thread_id+ )+ .try_map(|row| {+ Ok(Message {+ id: row.id,+ channel_id: row.channel_id,+ thread_id: row.thread_id,+ sender_id: MacroUserIdStr::parse_from_str(&row.sender_id)+ .map_err(|e| sqlx::Error::Decode(Box::new(e)))?+ .into_owned(),+ content: row.content,+ created_at: row.created_at,+ updated_at: row.updated_at,+ edited_at: row.edited_at,+ deleted_at: row.deleted_at,+ })+ })+ .fetch_one(executor)+ .await+ .context("unable to create message")?;++ Ok(message)+}diff --git a/rust/cloud-storage/seed_cli/.gitignore b/rust/cloud-storage/seed_cli/.gitignoreindex afed0735dc..e69de29bb2 100644--- a/rust/cloud-storage/seed_cli/.gitignore+++ b/rust/cloud-storage/seed_cli/.gitignore@@ -1 +0,0 @@-*.csvdiff --git a/rust/cloud-storage/seed_cli/seed/channel_messages.csv b/rust/cloud-storage/seed_cli/seed/channel_messages.csvnew file mode 100644index 0000000000..f4cc25addc--- /dev/null+++ b/rust/cloud-storage/seed_cli/seed/channel_messages.csv@@ -0,0 +1,22 @@+message_id,channel_id,sender_id,content,thread_id+00000000-0000-0000-0001-000000000001,00000000-0000-0000-0000-000000000001,macro|[email protected],Welcome to the general channel everyone!,+00000000-0000-0000-0001-000000000002,00000000-0000-0000-0000-000000000001,macro|[email protected],Thanks Bob! Glad to be here.,+00000000-0000-0000-0001-000000000003,00000000-0000-0000-0000-000000000001,macro|[email protected],Hey all - quick question about the onboarding doc?,+00000000-0000-0000-0001-000000000004,00000000-0000-0000-0000-000000000001,macro|[email protected],Sure thing - I can walk you through it.,00000000-0000-0000-0001-000000000003+00000000-0000-0000-0001-000000000005,00000000-0000-0000-0000-000000000002,macro|[email protected],Reminder: all-hands meeting tomorrow at 10am.,+00000000-0000-0000-0001-000000000006,00000000-0000-0000-0000-000000000002,macro|[email protected],Will there be a recording for those who can't attend?,00000000-0000-0000-0001-000000000005+00000000-0000-0000-0001-000000000007,00000000-0000-0000-0000-000000000003,macro|[email protected],Anyone tried that new coffee place on 5th?,+00000000-0000-0000-0001-000000000008,00000000-0000-0000-0000-000000000003,macro|[email protected],Yes! The cold brew is amazing.,00000000-0000-0000-0001-000000000007+00000000-0000-0000-0001-000000000009,00000000-0000-0000-0000-000000000003,macro|[email protected],Adding it to my list for this week.,00000000-0000-0000-0001-000000000007+00000000-0000-0000-0001-00000000000a,00000000-0000-0000-0000-000000000004,macro|[email protected],Q3 roadmap draft is ready for review.,+00000000-0000-0000-0001-00000000000b,00000000-0000-0000-0000-000000000004,macro|[email protected],Looks good - left a few comments on the doc.,00000000-0000-0000-0001-00000000000a+00000000-0000-0000-0001-00000000000c,00000000-0000-0000-0000-000000000005,macro|[email protected],Sprint retro notes have been uploaded.,+00000000-0000-0000-0001-00000000000d,00000000-0000-0000-0000-000000000005,macro|[email protected],Can we discuss the velocity drop next standup?,00000000-0000-0000-0001-00000000000c+00000000-0000-0000-0001-00000000000e,00000000-0000-0000-0000-000000000005,macro|[email protected],Agreed - I think the new estimation process might be a factor.,00000000-0000-0000-0001-00000000000c+00000000-0000-0000-0001-00000000000f,00000000-0000-0000-0000-000000000006,macro|[email protected],Should we move this conversation to a named channel?,+00000000-0000-0000-0001-000000000010,00000000-0000-0000-0000-000000000006,macro|[email protected],Good idea - let me set one up.,00000000-0000-0000-0001-00000000000f+00000000-0000-0000-0001-000000000011,00000000-0000-0000-0000-000000000007,macro|[email protected],Can you review my PR when you get a chance?,+00000000-0000-0000-0001-000000000012,00000000-0000-0000-0000-000000000007,macro|[email protected],On it - will have feedback by EOD.,00000000-0000-0000-0001-000000000011+00000000-0000-0000-0001-000000000013,00000000-0000-0000-0000-000000000008,macro|[email protected],Hey - are you free for a quick sync?,+00000000-0000-0000-0001-000000000014,00000000-0000-0000-0000-000000000009,macro|[email protected],Sent you the updated design files.,+00000000-0000-0000-0001-000000000015,00000000-0000-0000-0000-00000000000a,macro|[email protected],Thanks for the help earlier!,diff --git a/rust/cloud-storage/seed_cli/seed/channels.csv b/rust/cloud-storage/seed_cli/seed/channels.csvnew file mode 100644index 0000000000..709708b7ce--- /dev/null+++ b/rust/cloud-storage/seed_cli/seed/channels.csv@@ -0,0 +1,11 @@+channel_id,channel_name,channel_type,participants+00000000-0000-0000-0000-000000000001,general,public,macro|[email protected];macro|[email protected];macro|[email protected]+00000000-0000-0000-0000-000000000002,announcements,public,macro|[email protected];macro|[email protected]+00000000-0000-0000-0000-000000000003,random,public,macro|[email protected];macro|[email protected];macro|[email protected]+00000000-0000-0000-0000-000000000004,leadership,private,macro|[email protected];macro|[email protected]+00000000-0000-0000-0000-000000000005,project-alpha,private,macro|[email protected];macro|[email protected];macro|[email protected]+00000000-0000-0000-0000-000000000006,,private,macro|[email protected];macro|[email protected];macro|[email protected]+00000000-0000-0000-0000-000000000007,,private,macro|[email protected];macro|[email protected]+00000000-0000-0000-0000-000000000008,,direct_message,macro|[email protected]+00000000-0000-0000-0000-000000000009,,direct_message,macro|[email protected]+00000000-0000-0000-0000-00000000000a,,direct_message,macro|[email protected]diff --git a/rust/cloud-storage/seed_cli/src/entity/channel/mod.rs b/rust/cloud-storage/seed_cli/src/entity/channel/mod.rsindex 607bec2a1e..1f475a16e4 100644--- a/rust/cloud-storage/seed_cli/src/entity/channel/mod.rs+++ b/rust/cloud-storage/seed_cli/src/entity/channel/mod.rs@@ -8,8 +8,10 @@ use std::path::Path;use anyhow::Context;use clap::{Args, Subcommand, ValueEnum};use comms_db_client::channels::create_channel::CreateChannelOptions;+use comms_db_client::channels::seed_channel::SeedChannelOptions;use model::comms::ChannelType;use serde::Deserialize;+use uuid::Uuid;use crate::config::SeedCliContext;@@ -28,6 +30,30 @@ pub enum ChannelCommand {Create(CreateArgs),/// Bulk create multiple channelsBulkCreate(BulkCreateArgs),+ /// Seed channels from a fixed CSV file with pre-defined UUIDs+ Seed(SeedArgs),+}++/// Arguments for seeding channels from a fixed CSV file.+#[derive(Debug, Args)]+pub struct SeedArgs {+ /// The user ID to set as channel owner and append to participants+ #[arg(long)]+ pub user_id: String,+}++/// A row in the seed CSV file.+#[derive(Debug, Deserialize)]+struct CsvSeedChannelRow {+ /// Pre-defined channel UUID.+ channel_id: Uuid,+ /// Channel name (optional).+ channel_name: Option<String>,+ /// Channel type.+ channel_type: ChannelType,+ /// Semicolon-separated list of participant user IDs.+ #[serde(default, deserialize_with = "deserialize_semicolon_list")]+ participants: Vec<String>,}/// CLI-friendly channel type enum with kebab-case values.@@ -115,6 +141,7 @@ impl ChannelArgs {match self.command {ChannelCommand::Create(args) => create(args, ctx).await,ChannelCommand::BulkCreate(args) => bulk_create(args, ctx).await,+ ChannelCommand::Seed(args) => seed(args, ctx).await,}}}@@ -190,3 +217,67 @@ async fn bulk_create(args: BulkCreateArgs, ctx: SeedCliContext) -> anyhow::ResulOk(())}++#[tracing::instrument(skip(ctx), err)]+async fn seed(args: SeedArgs, ctx: SeedCliContext) -> anyhow::Result<()> {+ seed_from_file(args, ctx, Path::new("seed/channels.csv")).await+}++async fn seed_from_file(args: SeedArgs, ctx: SeedCliContext, path: &Path) -> anyhow::Result<()> {+ tracing::info!("seeding channels");++ let content = std::fs::read_to_string(path)+ .with_context(|| format!("failed to read csv file: {}", path.display()))?;++ let mut reader = csv::Reader::from_reader(content.as_bytes());+ let rows: Vec<CsvSeedChannelRow> = reader+ .deserialize()+ .collect::<Result<Vec<_>, _>>()+ .context("failed to parse csv")?;++ if rows.is_empty() {+ anyhow::bail!("no channels found in csv file");+ }++ println!("Found {} channels to seed", rows.len());++ let mut created = 0;+ let mut failed = 0;++ for row in rows {+ let channel_label = row+ .channel_name+ .as_deref()+ .map_or_else(|| format!("{:?}", row.channel_type), str::to_string);++ let mut participants = row.participants;+ if !participants.contains(&args.user_id) {+ participants.push(args.user_id.clone());+ }++ let options = SeedChannelOptions {+ channel_id: row.channel_id,+ name: row.channel_name,+ owner_id: args.user_id.clone(),+ channel_type: row.channel_type,+ org_id: None,+ participants,+ };++ match ctx.db.seed_channel(options).await {+ Ok(channel_id) => {+ println!("Seeded channel {channel_label} with id {channel_id}");+ created += 1;+ }+ Err(e) => {+ tracing::error!(error=?e, channel = channel_label, "failed to seed channel");+ println!("Failed to seed channel {channel_label}: {e}");+ failed += 1;+ }+ }+ }++ println!("\nSeed complete: {created} created, {failed} failed");++ Ok(())+}diff --git a/rust/cloud-storage/seed_cli/src/entity/channel/test.rs b/rust/cloud-storage/seed_cli/src/entity/channel/test.rsindex 09a6c9d4c5..1103d08f16 100644--- a/rust/cloud-storage/seed_cli/src/entity/channel/test.rs+++ b/rust/cloud-storage/seed_cli/src/entity/channel/test.rs@@ -155,6 +155,34 @@ fn parse_channel_bulk_create() {}}+#[test]+fn parse_channel_seed() {+ let cli = Cli::try_parse_from([+ "seed_cli",+ "channel",+ "seed",+ "--user-id",+ "macro|[email protected]",+ ])+ .unwrap();++ match cli.command {+ crate::entity::EntityCommand::Channel(args) => match args.command {+ ChannelCommand::Seed(seed) => {+ assert_eq!(seed.user_id, "macro|[email protected]");+ }+ other => panic!("expected Seed, got {other:?}"),+ },+ other => panic!("expected Channel, got {other:?}"),+ }+}++#[test]+fn parse_channel_seed_missing_user_id_fails() {+ let result = Cli::try_parse_from(["seed_cli", "channel", "seed"]);+ assert!(result.is_err());+}+// ── Helpers ────────────────────────────────────────────────fn mock_ctx(db: Db) -> SeedCliContext {@@ -381,3 +409,138 @@ async fn bulk_create_invalid_csv_fails() {let result = args.execute(mock_ctx(mock_db)).await;assert!(result.is_err());}++// ── Seed CSV tests ────────────────────────────────────────++#[tokio::test]+async fn seed_creates_all_channels() {+ let id1 = uuid::Uuid::new_v4();+ let id2 = uuid::Uuid::new_v4();+ let csv = format!(+ "channel_id,channel_name,channel_type,participants\n\+ {id1},general,public,macro|[email protected];macro|[email protected]\n\+ {id2},,direct_message,macro|[email protected]\n"+ );+ let file = write_temp_csv(&csv);++ let mut mock_db = Db::default();+ mock_db+ .expect_seed_channel()+ .times(2)+ .returning(|opts| Ok(opts.channel_id));++ let args = SeedArgs {+ user_id: "macro|[email protected]".to_string(),+ };++ let result = seed_from_file(args, mock_ctx(mock_db), file.path()).await;+ assert!(result.is_ok());+}++#[tokio::test]+async fn seed_sets_user_id_as_owner_and_appends_to_participants() {+ let id = uuid::Uuid::new_v4();+ let csv = format!(+ "channel_id,channel_name,channel_type,participants\n\+ {id},general,public,macro|[email protected]\n"+ );+ let file = write_temp_csv(&csv);++ let mut mock_db = Db::default();+ mock_db+ .expect_seed_channel()+ .times(1)+ .withf(|opts| {+ opts.owner_id == "macro|[email protected]"+ && opts+ .participants+ .contains(&"macro|[email protected]".to_string())+ && opts+ .participants+ .contains(&"macro|[email protected]".to_string())+ })+ .returning(|opts| Ok(opts.channel_id));++ let args = SeedArgs {+ user_id: "macro|[email protected]".to_string(),+ };++ let result = seed_from_file(args, mock_ctx(mock_db), file.path()).await;+ assert!(result.is_ok());+}++#[tokio::test]+async fn seed_does_not_duplicate_user_in_participants() {+ let id = uuid::Uuid::new_v4();+ let csv = format!(+ "channel_id,channel_name,channel_type,participants\n\+ {id},general,public,macro|[email protected];macro|[email protected]\n"+ );+ let file = write_temp_csv(&csv);++ let mut mock_db = Db::default();+ mock_db+ .expect_seed_channel()+ .times(1)+ .withf(|opts| {+ opts.participants+ .iter()+ .filter(|p| *p == "macro|[email protected]")+ .count()+ == 1+ })+ .returning(|opts| Ok(opts.channel_id));++ let args = SeedArgs {+ user_id: "macro|[email protected]".to_string(),+ };++ let result = seed_from_file(args, mock_ctx(mock_db), file.path()).await;+ assert!(result.is_ok());+}++#[tokio::test]+async fn seed_empty_csv_fails() {+ let csv = "channel_id,channel_name,channel_type,participants\n";+ let file = write_temp_csv(csv);++ let mock_db = Db::default();++ let args = SeedArgs {+ user_id: "macro|[email protected]".to_string(),+ };++ let result = seed_from_file(args, mock_ctx(mock_db), file.path()).await;+ let err = result.unwrap_err();+ assert!(err.to_string().contains("no channels found"));+}++#[tokio::test]+async fn seed_continues_on_failure() {+ let id1 = uuid::Uuid::new_v4();+ let id2 = uuid::Uuid::new_v4();+ let id3 = uuid::Uuid::new_v4();+ let csv = format!(+ "channel_id,channel_name,channel_type,participants\n\+ {id1},good-1,public,\n\+ {id2},bad,public,\n\+ {id3},good-2,private,\n"+ );+ let file = write_temp_csv(&csv);++ let mut mock_db = Db::default();+ mock_db.expect_seed_channel().times(3).returning(|opts| {+ if opts.name.as_deref() == Some("bad") {+ Err(anyhow::anyhow!("db error"))+ } else {+ Ok(opts.channel_id)+ }+ });++ let args = SeedArgs {+ user_id: "macro|[email protected]".to_string(),+ };++ let result = seed_from_file(args, mock_ctx(mock_db), file.path()).await;+ assert!(result.is_ok());+}diff --git a/rust/cloud-storage/seed_cli/src/entity/channel_message/mod.rs b/rust/cloud-storage/seed_cli/src/entity/channel_message/mod.rsindex 5ec431edb0..5c25009e1c 100644--- a/rust/cloud-storage/seed_cli/src/entity/channel_message/mod.rs+++ b/rust/cloud-storage/seed_cli/src/entity/channel_message/mod.rs@@ -8,6 +8,7 @@ use std::path::Path;use anyhow::Context;use clap::{Args, Subcommand};use comms_db_client::messages::create_message::CreateMessageOptions;+use comms_db_client::messages::seed_message::SeedMessageOptions;use serde::Deserialize;use uuid::Uuid;@@ -28,6 +29,23 @@ pub enum ChannelMessageCommand {Create(CreateArgs),/// Bulk create multiple channel messagesBulkCreate(BulkCreateArgs),+ /// Seed channel messages from a fixed CSV file with pre-defined UUIDs+ Seed,+}++/// A row in the seed CSV file.+#[derive(Debug, Deserialize)]+struct CsvSeedMessageRow {+ /// Pre-defined message UUID.+ message_id: Uuid,+ /// The channel ID to post the message to.+ channel_id: Uuid,+ /// The user ID of the message sender.+ sender_id: String,+ /// The message content.+ content: String,+ /// Optional thread ID if this is a reply.+ thread_id: Option<Uuid>,}/// Arguments for creating a single channel message.@@ -74,6 +92,7 @@ impl ChannelMessageArgs {match self.command {ChannelMessageCommand::Create(args) => create(args, ctx).await,ChannelMessageCommand::BulkCreate(args) => bulk_create(args, ctx).await,+ ChannelMessageCommand::Seed => seed(ctx).await,}}}@@ -144,3 +163,58 @@ async fn bulk_create(args: BulkCreateArgs, ctx: SeedCliContext) -> anyhow::ResulOk(())}++#[tracing::instrument(skip(ctx), err)]+async fn seed(ctx: SeedCliContext) -> anyhow::Result<()> {+ seed_from_file(ctx, Path::new("seed/channel_messages.csv")).await+}++async fn seed_from_file(ctx: SeedCliContext, path: &Path) -> anyhow::Result<()> {+ tracing::info!("seeding channel messages");++ let content = std::fs::read_to_string(path)+ .with_context(|| format!("failed to read csv file: {}", path.display()))?;++ let mut reader = csv::Reader::from_reader(content.as_bytes());+ let rows: Vec<CsvSeedMessageRow> = reader+ .deserialize()+ .collect::<Result<Vec<_>, _>>()+ .context("failed to parse csv")?;++ if rows.is_empty() {+ anyhow::bail!("no messages found in csv file");+ }++ println!("Found {} messages to seed", rows.len());++ let mut created = 0;+ let mut failed = 0;++ for row in rows {+ let message_label = format!("channel={} sender={}", row.channel_id, row.sender_id);++ let options = SeedMessageOptions {+ message_id: row.message_id,+ channel_id: row.channel_id,+ sender_id: row.sender_id,+ content: row.content,+ thread_id: row.thread_id,+ };++ match ctx.db.seed_message(options).await {+ Ok(message_id) => {+ println!("Seeded message {message_label} with id {message_id}");+ created += 1;+ }+ Err(e) => {+ tracing::error!(error=?e, message = message_label, "failed to seed message");+ println!("Failed to seed message {message_label}: {e}");+ failed += 1;+ }+ }+ }++ println!("\nSeed complete: {created} created, {failed} failed");++ Ok(())+}diff --git a/rust/cloud-storage/seed_cli/src/entity/channel_message/test.rs b/rust/cloud-storage/seed_cli/src/entity/channel_message/test.rsindex c59b09a112..3629e19af1 100644--- a/rust/cloud-storage/seed_cli/src/entity/channel_message/test.rs+++ b/rust/cloud-storage/seed_cli/src/entity/channel_message/test.rs@@ -11,6 +11,21 @@ use crate::service::db::Db;use super::*;+// ── Parsing tests (seed) ──────────────────────────────────++#[test]+fn parse_channel_message_seed() {+ let cli = Cli::try_parse_from(["seed_cli", "channel-message", "seed"]).unwrap();++ match cli.command {+ crate::entity::EntityCommand::ChannelMessage(args) => match args.command {+ ChannelMessageCommand::Seed => {}+ other => panic!("expected Seed, got {other:?}"),+ },+ other => panic!("expected ChannelMessage, got {other:?}"),+ }+}+// ── Parsing tests ──────────────────────────────────────────#[test]@@ -391,3 +406,109 @@ async fn bulk_create_invalid_csv_fails() {let result = args.execute(mock_ctx(mock_db)).await;assert!(result.is_err());}++// ── Seed CSV tests ────────────────────────────────────────++#[tokio::test]+async fn seed_creates_all_messages() {+ let msg1 = Uuid::new_v4();+ let msg2 = Uuid::new_v4();+ let channel_id = Uuid::new_v4();+ let csv = format!(+ "message_id,channel_id,sender_id,content,thread_id\n\+ {msg1},{channel_id},macro|[email protected],Hello world,\n\+ {msg2},{channel_id},macro|[email protected],Hi there,\n"+ );+ let file = write_temp_csv(&csv);++ let mut mock_db = Db::default();+ mock_db+ .expect_seed_message()+ .times(2)+ .returning(|opts| Ok(opts.message_id));++ let result = seed_from_file(mock_ctx(mock_db), file.path()).await;+ assert!(result.is_ok());+}++#[tokio::test]+async fn seed_uses_provided_message_id() {+ let msg_id = Uuid::new_v4();+ let channel_id = Uuid::new_v4();+ let csv = format!(+ "message_id,channel_id,sender_id,content,thread_id\n\+ {msg_id},{channel_id},macro|[email protected],Test message,\n"+ );+ let file = write_temp_csv(&csv);++ let mut mock_db = Db::default();+ mock_db+ .expect_seed_message()+ .times(1)+ .withf(move |opts| opts.message_id == msg_id && opts.channel_id == channel_id)+ .returning(|opts| Ok(opts.message_id));++ let result = seed_from_file(mock_ctx(mock_db), file.path()).await;+ assert!(result.is_ok());+}++#[tokio::test]+async fn seed_with_thread_id() {+ let msg_id = Uuid::new_v4();+ let channel_id = Uuid::new_v4();+ let thread_id = Uuid::new_v4();+ let csv = format!(+ "message_id,channel_id,sender_id,content,thread_id\n\+ {msg_id},{channel_id},macro|[email protected],Thread reply,{thread_id}\n"+ );+ let file = write_temp_csv(&csv);++ let mut mock_db = Db::default();+ mock_db+ .expect_seed_message()+ .times(1)+ .withf(move |opts| opts.thread_id == Some(thread_id))+ .returning(|opts| Ok(opts.message_id));++ let result = seed_from_file(mock_ctx(mock_db), file.path()).await;+ assert!(result.is_ok());+}++#[tokio::test]+async fn seed_empty_csv_fails() {+ let csv = "message_id,channel_id,sender_id,content,thread_id\n";+ let file = write_temp_csv(csv);++ let mock_db = Db::default();++ let result = seed_from_file(mock_ctx(mock_db), file.path()).await;+ let err = result.unwrap_err();+ assert!(err.to_string().contains("no messages found"));+}++#[tokio::test]+async fn seed_continues_on_failure() {+ let msg1 = Uuid::new_v4();+ let msg2 = Uuid::new_v4();+ let msg3 = Uuid::new_v4();+ let channel_id = Uuid::new_v4();+ let csv = format!(+ "message_id,channel_id,sender_id,content,thread_id\n\+ {msg1},{channel_id},macro|[email protected],Good 1,\n\+ {msg2},{channel_id},macro|[email protected],Bad,\n\+ {msg3},{channel_id},macro|[email protected],Good 2,\n"+ );+ let file = write_temp_csv(&csv);++ let mut mock_db = Db::default();+ mock_db.expect_seed_message().times(3).returning(|opts| {+ if opts.sender_id == "macro|[email protected]" {+ Err(anyhow::anyhow!("db error"))+ } else {+ Ok(opts.message_id)+ }+ });++ let result = seed_from_file(mock_ctx(mock_db), file.path()).await;+ assert!(result.is_ok());+}diff --git a/rust/cloud-storage/seed_cli/src/service/db/mod.rs b/rust/cloud-storage/seed_cli/src/service/db/mod.rsindex 1699ec2bf9..146f6e538e 100644--- a/rust/cloud-storage/seed_cli/src/service/db/mod.rs+++ b/rust/cloud-storage/seed_cli/src/service/db/mod.rs@@ -9,7 +9,9 @@ pub use SeedDb as Db;use mockall::automock;use comms_db_client::channels::create_channel::CreateChannelOptions;+use comms_db_client::channels::seed_channel::SeedChannelOptions;use comms_db_client::messages::create_message::CreateMessageOptions;+use comms_db_client::messages::seed_message::SeedMessageOptions;/// Wrapper around the database connection pool.pub struct SeedDb {@@ -35,6 +37,14 @@ impl SeedDb {Ok(id)}+ /// Seed a channel with a pre-defined UUID.+ #[tracing::instrument(skip(self), err)]+ pub async fn seed_channel(&self, options: SeedChannelOptions) -> anyhow::Result<uuid::Uuid> {+ let id =+ comms_db_client::channels::seed_channel::seed_channel(&self.inner, options).await?;+ Ok(id)+ }+/// Create a message in the database.#[tracing::instrument(skip(self), err)]pub async fn create_message(@@ -45,4 +55,12 @@ impl SeedDb {comms_db_client::messages::create_message::create_message(&self.inner, options).await?;Ok(message.id)}++ /// Seed a message with a pre-defined UUID.+ #[tracing::instrument(skip(self), err)]+ pub async fn seed_message(&self, options: SeedMessageOptions) -> anyhow::Result<uuid::Uuid> {+ let message =+ comms_db_client::messages::seed_message::seed_message(&self.inner, options).await?;+ Ok(message.id)+ }}