Revamp notification policy options (#31343)

This commit is contained in:
Claire 2024-08-09 15:30:55 +02:00 committed by GitHub
parent e29c401f77
commit cbdd8edf68
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 442 additions and 109 deletions

View file

@ -0,0 +1,26 @@
# frozen_string_literal: true
class PostDeploymentMigrateNotificationsPolicyV2 < ActiveRecord::Migration[7.1]
disable_ddl_transaction!
# Dummy classes, to make migration possible across version changes
class NotificationPolicy < ApplicationRecord; end
def up
NotificationPolicy.in_batches.update_all(<<~SQL.squish)
for_not_following = CASE filter_not_following WHEN true THEN 1 ELSE 0 END,
for_not_followers = CASE filter_not_following WHEN true THEN 1 ELSE 0 END,
for_new_accounts = CASE filter_new_accounts WHEN true THEN 1 ELSE 0 END,
for_private_mentions = CASE filter_private_mentions WHEN true THEN 1 ELSE 0 END
SQL
end
def down
NotificationPolicy.in_batches.update_all(<<~SQL.squish)
filter_not_following = CASE for_not_following WHEN 0 THEN false ELSE true END,
filter_not_following = CASE for_not_followers WHEN 0 THEN false ELSE true END,
filter_new_accounts = CASE for_new_accounts WHEN 0 THEN false ELSE true END,
filter_private_mentions = CASE for_private_mentions WHEN 0 THEN false ELSE true END
SQL
end
end

View file

@ -0,0 +1,12 @@
# frozen_string_literal: true
class DropOldPoliciesFromNotificationsPolicy < ActiveRecord::Migration[7.1]
def change
safety_assured do
remove_column :notification_policies, :filter_not_following, :boolean, default: false, null: false
remove_column :notification_policies, :filter_not_followers, :boolean, default: false, null: false
remove_column :notification_policies, :filter_new_accounts, :boolean, default: false, null: false
remove_column :notification_policies, :filter_private_mentions, :boolean, default: true, null: false
end
end
end