1
0
mirror of https://github.com/meineerde/redmine.git synced 2026-03-26 18:51:11 +00:00
redmine/db/migrate/098_set_topic_authors_as_watchers.rb
Go MAEDA 5861160ffc Add "frozen_string_literal: false" for all files (#26561).
This will be changed to true in the future.


git-svn-id: http://svn.redmine.org/redmine/trunk@17947 e93f8b46-1217-0410-a6f0-8f06a7374b81
2019-03-15 01:32:57 +00:00

18 lines
792 B
Ruby

# frozen_string_literal: false
class SetTopicAuthorsAsWatchers < ActiveRecord::Migration[4.2]
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
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")
end
def self.down
# Removes all message watchers
Watcher.where("watchable_type = 'Message'").delete_all
end
end