2017-07-23 13:26:04 +02:00
|
|
|
class SetTopicAuthorsAsWatchers < ActiveRecord::Migration[4.2]
|
2008-09-19 17:32:52 +02:00
|
|
|
def self.up
|
|
|
|
# Sets active users who created/replied a topic as watchers of the topic
|
|
|
|
# so that the new watch functionality at topic level doesn't affect notifications behaviour
|
2009-02-08 18:24:39 +01:00
|
|
|
Message.connection.execute("INSERT INTO #{Watcher.table_name} (watchable_type, watchable_id, user_id)" +
|
|
|
|
" SELECT DISTINCT 'Message', COALESCE(m.parent_id, m.id), m.author_id" +
|
|
|
|
" FROM #{Message.table_name} m, #{User.table_name} u" +
|
|
|
|
" WHERE m.author_id = u.id AND u.status = 1")
|
2008-09-19 17:32:52 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.down
|
|
|
|
# Removes all message watchers
|
2016-07-16 12:30:45 +02:00
|
|
|
Watcher.where("watchable_type = 'Message'").delete_all
|
2008-09-19 17:32:52 +02:00
|
|
|
end
|
|
|
|
end
|