Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

[38671] Reset all notifications, remove previous migration attempts

Oliver Günthere4381a441a70
diff --git a/db/migrate/20210618132206_add_notification_settings.rb b/db/migrate/20210618132206_add_notification_settings.rb
index 92086c36c94..97ad8dc26b6 100644
--- a/db/migrate/20210618132206_add_notification_settings.rb
+++ b/db/migrate/20210618132206_add_notification_settings.rb
@@ -22,10 +22,6 @@ class AddNotificationSettings < ActiveRecord::Migration[6.1]
name: 'index_notification_settings_unique_project'
end
- insert_project_specific_channel
- insert_default_mail_channel
- insert_default_in_app_channel
-
remove_column :members, :mail_notification
end
@@ -33,95 +29,6 @@ class AddNotificationSettings < ActiveRecord::Migration[6.1]
add_column :members, :mail_notification, :boolean, default: false, null: false
add_column :users, :mail_notification, :string, default: '', null: false
- update_mail_notifications
-
drop_table :notification_settings
end
-
- def insert_default_mail_channel
- execute <<~SQL
- INSERT INTO
- notification_settings
- (user_id,
- channel,
- watched,
- involved,
- mentioned,
- "all")
- SELECT
- id,
- 1,
- mail_notification = 'only_my_events',
- mail_notification = 'only_my_events' OR mail_notification = 'only_assigned',
- NOT mail_notification = 'all' AND NOT mail_notification = 'NONE',
- mail_notification = 'all'
- FROM
- users
- WHERE
- mail_notification IS NOT NULL
- SQL
- end
-
- def insert_project_specific_channel
- execute <<~SQL
- INSERT INTO
- notification_settings
- (project_id,
- user_id,
- channel,
- "all")
- SELECT
- project_id,
- user_id,
- 1,
- true
- FROM
- members
- WHERE
- mail_notification
- SQL
- end
-
- def insert_default_in_app_channel
- execute <<~SQL
- INSERT INTO
- notification_settings
- (user_id,
- channel,
- involved,
- mentioned,
- watched)
- SELECT
- id,
- 0,
- true,
- true,
- true
- FROM
- users
- WHERE
- type = 'User'
- SQL
- end
-
- def update_mail_notifications
- # We cannot reconstruct the settings completely
- execute <<~SQL
- UPDATE
- users
- SET
- mail_notification = CASE
- WHEN notification_settings.all
- THEN 'all'
- WHEN notification_settings.watched
- THEN 'only_my_events'
- WHEN notification_settings.involved
- THEN 'only_assigned'
- ELSE 'none'
- FROM
- notification_settings
- WHERE
- notification_settings.user_id = users.id
- SQL
- end
end
diff --git a/db/migrate/20211104151329_default_notification_setting.rb b/db/migrate/20211104151329_default_notification_setting.rb
new file mode 100644
index 00000000000..51e717bb5e4
--- /dev/null
+++ b/db/migrate/20211104151329_default_notification_setting.rb
@@ -0,0 +1,19 @@
+class DefaultNotificationSetting < ActiveRecord::Migration[6.1]
+ def up
+ NotificationSetting.delete_all
+
+ execute <<~SQL.squish
+ INSERT INTO
+ notification_settings
+ (user_id, watched, involved, mentioned)
+ SELECT
+ id, true, true, true
+ FROM
+ users
+ SQL
+ end
+
+ def down
+ # No data to revert
+ end
+end