feat: add migration for converations with labels
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
class CreateConversationWithLabels < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
create_view :conversation_with_labels
|
||||
|
||||
add_index :conversation_with_labels, :id, unique: true
|
||||
add_index :conversation_with_labels, :account_id
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,11 @@
|
||||
SELECT
|
||||
conversations.*,
|
||||
array_agg(tags.name) as labels_array
|
||||
FROM
|
||||
conversations
|
||||
LEFT JOIN taggings ON taggings.taggable_id = conversations.id
|
||||
AND taggings.taggable_type = 'Conversation'
|
||||
AND taggings.context = 'labels'
|
||||
LEFT JOIN tags ON tags.id = taggings.tag_id
|
||||
GROUP BY
|
||||
conversations.id;
|
||||
Reference in New Issue
Block a user