Chris@0: class SetTopicAuthorsAsWatchers < ActiveRecord::Migration Chris@0: def self.up Chris@0: # Sets active users who created/replied a topic as watchers of the topic Chris@0: # so that the new watch functionality at topic level doesn't affect notifications behaviour Chris@0: Message.connection.execute("INSERT INTO #{Watcher.table_name} (watchable_type, watchable_id, user_id)" + Chris@0: " SELECT DISTINCT 'Message', COALESCE(m.parent_id, m.id), m.author_id" + Chris@0: " FROM #{Message.table_name} m, #{User.table_name} u" + Chris@0: " WHERE m.author_id = u.id AND u.status = 1") Chris@0: end Chris@0: Chris@0: def self.down Chris@0: # Removes all message watchers Chris@0: Watcher.delete_all("watchable_type = 'Message'") Chris@0: end Chris@0: end