20190927124642_remove_invalid_web_push_subscription.rb 748 B

123456789101112131415161718
  1. # frozen_string_literal: true
  2. class RemoveInvalidWebPushSubscription < ActiveRecord::Migration[5.2]
  3. disable_ddl_transaction!
  4. def up
  5. invalid_web_push_subscriptions = Web::PushSubscription.where(endpoint: '')
  6. .or(Web::PushSubscription.where(key_p256dh: ''))
  7. .or(Web::PushSubscription.where(key_auth: ''))
  8. .preload(:session_activation)
  9. invalid_web_push_subscriptions.find_each do |web_push_subscription|
  10. web_push_subscription.session_activation&.update!(web_push_subscription_id: nil)
  11. web_push_subscription.destroy!
  12. end
  13. end
  14. def down; end
  15. end