20240808124338_migrate_notifications_policy_v2.rb 1.1 KB

1234567891011121314151617181920212223242526
  1. # frozen_string_literal: true
  2. class MigrateNotificationsPolicyV2 < ActiveRecord::Migration[7.1]
  3. disable_ddl_transaction!
  4. # Dummy classes, to make migration possible across version changes
  5. class NotificationPolicy < ApplicationRecord; end
  6. def up
  7. NotificationPolicy.in_batches.update_all(<<~SQL.squish)
  8. for_not_following = CASE filter_not_following WHEN true THEN 1 ELSE 0 END,
  9. for_not_followers = CASE filter_not_following WHEN true THEN 1 ELSE 0 END,
  10. for_new_accounts = CASE filter_new_accounts WHEN true THEN 1 ELSE 0 END,
  11. for_private_mentions = CASE filter_private_mentions WHEN true THEN 1 ELSE 0 END
  12. SQL
  13. end
  14. def down
  15. NotificationPolicy.in_batches.update_all(<<~SQL.squish)
  16. filter_not_following = CASE for_not_following WHEN 0 THEN false ELSE true END,
  17. filter_not_following = CASE for_not_followers WHEN 0 THEN false ELSE true END,
  18. filter_new_accounts = CASE for_new_accounts WHEN 0 THEN false ELSE true END,
  19. filter_private_mentions = CASE for_private_mentions WHEN 0 THEN false ELSE true END
  20. SQL
  21. end
  22. end