canvas-lms/db/migrate/20110830152834_conversation...

22 lines
568 B
Ruby

class ConversationsCountFix < ActiveRecord::Migration
tag :predeploy
def self.up
update "UPDATE #{ConversationParticipant.quoted_table_name} SET workflow_state = 'read' WHERE workflow_state = 'unread' AND last_message_at IS NULL"
update <<-SQL
UPDATE #{User.quoted_table_name}
SET unread_conversations_count = (
SELECT COUNT(*)
FROM #{ConversationParticipant.quoted_table_name}
WHERE workflow_state = 'unread'
AND last_message_at IS NOT NULL
AND user_id = users.id
)
SQL
end
def self.down
end
end