2011-08-31 00:06:37 +08:00
|
|
|
class ConversationsCountFix < ActiveRecord::Migration
|
2015-11-05 05:38:51 +08:00
|
|
|
tag :predeploy
|
|
|
|
|
2011-08-31 00:06:37 +08:00
|
|
|
def self.up
|
2015-09-01 02:09:52 +08:00
|
|
|
update "UPDATE #{ConversationParticipant.quoted_table_name} SET workflow_state = 'read' WHERE workflow_state = 'unread' AND last_message_at IS NULL"
|
2011-08-31 00:06:37 +08:00
|
|
|
|
2015-09-01 02:09:52 +08:00
|
|
|
update <<-SQL
|
|
|
|
UPDATE #{User.quoted_table_name}
|
2011-08-31 00:06:37 +08:00
|
|
|
SET unread_conversations_count = (
|
|
|
|
SELECT COUNT(*)
|
2015-09-01 02:09:52 +08:00
|
|
|
FROM #{ConversationParticipant.quoted_table_name}
|
2011-08-31 00:06:37 +08:00
|
|
|
WHERE workflow_state = 'unread'
|
|
|
|
AND last_message_at IS NOT NULL
|
|
|
|
AND user_id = users.id
|
|
|
|
)
|
|
|
|
SQL
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.down
|
|
|
|
end
|
|
|
|
end
|