feat: add migration for converations with labels

This commit is contained in:
Shivam Mishra
2023-06-02 17:45:03 +05:30
parent 2815d0ce1b
commit 4be26f7470
2 changed files with 19 additions and 0 deletions
@@ -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
+11
View File
@@ -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;