diff --git a/crates/channel/src/channel_store/channel_index.rs b/crates/channel/src/channel_store/channel_index.rs index e70b3e4c46..7e6ddd2970 100644 --- a/crates/channel/src/channel_store/channel_index.rs +++ b/crates/channel/src/channel_store/channel_index.rs @@ -94,14 +94,17 @@ impl<'a> Drop for ChannelPathsInsertGuard<'a> { fn channel_path_sorting_key<'a>( id: ChannelId, channels_by_id: &'a BTreeMap>, -) -> impl Iterator { +) -> impl Iterator { let (parent_path, name) = channels_by_id .get(&id) .map_or((&[] as &[_], None), |channel| { - (channel.parent_path.as_slice(), Some(channel.name.as_ref())) + ( + channel.parent_path.as_slice(), + Some((channel.name.as_ref(), channel.id)), + ) }); parent_path .iter() - .filter_map(|id| Some(channels_by_id.get(id)?.name.as_ref())) + .filter_map(|id| Some((channels_by_id.get(id)?.name.as_ref(), *id))) .chain(name) } diff --git a/crates/collab/migrations/20240226164505_unique_channel_names.sql b/crates/collab/migrations/20240226164505_unique_channel_names.sql new file mode 100644 index 0000000000..9e6a0d8761 --- /dev/null +++ b/crates/collab/migrations/20240226164505_unique_channel_names.sql @@ -0,0 +1,3 @@ +-- Add migration script here + +CREATE UNIQUE INDEX uix_channels_parent_path_name ON channels(parent_path, name) WHERE (parent_path IS NOT NULL);