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
fix(channels): delete channel endpoint broken (#6180)
Will Hutchinsond4d13aa0dda5
diff --git a/crates/channels/src/outbound/pg_channels_repo/tests.rs b/crates/channels/src/outbound/pg_channels_repo/tests.rsindex 0b0af16f7d..d3fccad37d 100644--- a/crates/channels/src/outbound/pg_channels_repo/tests.rs+++ b/crates/channels/src/outbound/pg_channels_repo/tests.rs@@ -2988,3 +2988,55 @@ async fn bot_profiles_includes_soft_deleted_bots(pool: Pool<Postgres>) -> anyhowassert!(!profiles.contains_key(&missing));Ok(())}++#[sqlx::test(migrator = "MACRO_DB_MIGRATIONS")]+async fn delete_channel_cascades_contacts_backfill_outbox_rows(pool: Pool<Postgres>) {+ let repo = repo(pool.clone());+ let created = repo+ .create_channel(+ macro_user_id(USER_A),+ None,+ CreateChannelRequest {+ name: Some("delete-with-outbox".to_string()),+ channel_type: ChannelType::Private,+ team_id: None,+ auto_join_team: false,+ participants: HashSet::new(),+ },+ )+ .await+ .unwrap();++ sqlx::query!(+ "INSERT INTO contacts_backfill_outbox (comms_channel_id, user_ids) \+ VALUES ($1, '[\"macro|[email protected]\"]'::jsonb)",+ created.id,+ )+ .execute(&pool)+ .await+ .unwrap();++ repo.delete_channel(created.id, USER_A.to_string())+ .await+ .expect("channel delete must succeed when contacts_backfill_outbox references the channel");++ let channel_count = sqlx::query_scalar!(+ "SELECT count(*) FROM comms_channels WHERE id = $1",+ created.id,+ )+ .fetch_one(&pool)+ .await+ .unwrap()+ .unwrap();+ assert_eq!(channel_count, 0);++ let outbox_count = sqlx::query_scalar!(+ "SELECT count(*) FROM contacts_backfill_outbox WHERE comms_channel_id = $1",+ created.id,+ )+ .fetch_one(&pool)+ .await+ .unwrap()+ .unwrap();+ assert_eq!(outbox_count, 0);+}diff --git a/crates/macro_db_client/migrations/20260903174515_cascade_contacts_backfill_outbox_on_channel_delete.sql b/crates/macro_db_client/migrations/20260903174515_cascade_contacts_backfill_outbox_on_channel_delete.sqlnew file mode 100644index 0000000000..1fcb2bac9f--- /dev/null+++ b/crates/macro_db_client/migrations/20260903174515_cascade_contacts_backfill_outbox_on_channel_delete.sql@@ -0,0 +1,6 @@+ALTER TABLE contacts_backfill_outbox+ DROP CONSTRAINT contacts_backfill_outbox_comms_channel_id_fkey;++ALTER TABLE contacts_backfill_outbox+ ADD CONSTRAINT contacts_backfill_outbox_comms_channel_id_fkey+ FOREIGN KEY (comms_channel_id) REFERENCES comms_channels(id) ON DELETE CASCADE;