OpenProject is the leading open source project management software.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
openproject/db/migrate/20210802114054_add_notifica...

35 lines
1.1 KiB

class AddNotificationSettingOptions < ActiveRecord::Migration[6.1]
def change
add_notification_settings_options
update_notified_events
# TODO: add index to all boolean fields
end
def add_notification_settings_options
change_table :notification_settings, bulk: true do |t|
t.boolean :work_package_commented, default: false
t.boolean :work_package_created, default: false
t.boolean :work_package_processed, default: false
t.boolean :work_package_prioritized, default: false
end
end
def update_notified_events
event_types = %w(work_package_added work_package_updated work_package_note_added status_updated work_package_priority_updated)
# rubocop:disable Rails/WhereExists
# The Setting.exists? method is overwritten
reversible do |dir|
dir.up do
Setting.notified_events = Setting.notified_events - event_types if Setting.where(name: 'notified_events').exists?
end
dir.down do
Setting.notified_events = Setting.notified_events + event_types if Setting.where(name: 'notified_events').exists?
end
end
# rubocop:enable Rails/WhereExists
end
end