BigW Consortium Gitlab

20160328115649_migrate_new_notification_setting.rb 883 Bytes
Newer Older
1
# rubocop:disable all
2
# This migration will create one row of NotificationSetting for each Member row
3 4 5 6 7 8
# It can take long time on big instances.
#
# This migration can be done online but with following effects:
# - during migration some users will receive notifications based on their global settings (project/group settings will be ignored)
# - its possible to get duplicate records for notification settings since we don't create uniq index yet
#
9 10
class MigrateNewNotificationSetting < ActiveRecord::Migration
  def up
11
    timestamp = Time.now.strftime('%F %T')
12
    execute "INSERT INTO notification_settings ( user_id, source_id, source_type, level, created_at, updated_at ) SELECT user_id, source_id, source_type, notification_level, '#{timestamp}', '#{timestamp}' FROM members WHERE user_id IS NOT NULL"
13 14 15
  end

  def down
16
    execute "DELETE FROM notification_settings"
17 18
  end
end