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