diff options
author | Sean McGivern <sean@gitlab.com> | 2017-06-08 17:10:35 +0100 |
---|---|---|
committer | Sean McGivern <sean@gitlab.com> | 2017-06-15 15:15:13 +0100 |
commit | e94c1028c1e829f899b0d0f56313cc62df6f9a0a (patch) | |
tree | d69f40f69e1ed69ce5c2c6d7fe2367ccca7cdce1 /db | |
parent | f4b5fcbca100769b89e6b06e0df180012d16a7a8 (diff) | |
download | gitlab-ce-e94c1028c1e829f899b0d0f56313cc62df6f9a0a.tar.gz |
Deserialise existing custom notification settingsdeserialize-custom-notifications
Create a post-deployment migration to update all existing notification settings
with at least one custom level enabled to the new format. Also handle the same
conversion when updating settings, to catch any stragglers.
Diffstat (limited to 'db')
-rw-r--r-- | db/post_migrate/20170607121233_convert_custom_notification_settings_to_columns.rb | 55 | ||||
-rw-r--r-- | db/schema.rb | 2 |
2 files changed, 56 insertions, 1 deletions
diff --git a/db/post_migrate/20170607121233_convert_custom_notification_settings_to_columns.rb b/db/post_migrate/20170607121233_convert_custom_notification_settings_to_columns.rb new file mode 100644 index 00000000000..9abda6a1d73 --- /dev/null +++ b/db/post_migrate/20170607121233_convert_custom_notification_settings_to_columns.rb @@ -0,0 +1,55 @@ +class ConvertCustomNotificationSettingsToColumns < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + class NotificationSetting < ActiveRecord::Base + self.table_name = 'notification_settings' + + store :events, coder: JSON + end + + EMAIL_EVENTS = [ + :new_note, + :new_issue, + :reopen_issue, + :close_issue, + :reassign_issue, + :new_merge_request, + :reopen_merge_request, + :close_merge_request, + :reassign_merge_request, + :merge_merge_request, + :failed_pipeline, + :success_pipeline + ] + + # We only need to migrate (up or down) rows where at least one of these + # settings is set. + def up + NotificationSetting.where("events LIKE '%true%'").find_each do |notification_setting| + EMAIL_EVENTS.each do |event| + notification_setting[event] = notification_setting.events[event] + end + + notification_setting[:events] = nil + notification_setting.save! + end + end + + def down + NotificationSetting.where(EMAIL_EVENTS.join(' OR ')).find_each do |notification_setting| + events = {} + + EMAIL_EVENTS.each do |event| + events[event] = !!notification_setting.public_send(event) + notification_setting[event] = nil + end + + notification_setting[:events] = events + notification_setting.save! + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 4e897e44f53..956ca2278f4 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170606202615) do +ActiveRecord::Schema.define(version: 20170607121233) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" |