about summary refs log tree commit diff
path: root/db/migrate
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2018-06-09 13:33:04 +0200
committerGitHub <noreply@github.com>2018-06-09 13:33:04 +0200
commit18e1de6a16f36c6cdcfa5e95c60c8873773529d2 (patch)
tree1f2e33d73cc27d927dba174d7a72e0d680c458ff /db/migrate
parent85470ec872a39c475d872f685dadeac849832a98 (diff)
Migrate old web push subscriptions to ensure deliveries (#7764)
Diffstat (limited to 'db/migrate')
-rw-r--r--db/migrate/20180609104432_migrate_web_push_subscriptions2.rb17
1 files changed, 17 insertions, 0 deletions
diff --git a/db/migrate/20180609104432_migrate_web_push_subscriptions2.rb b/db/migrate/20180609104432_migrate_web_push_subscriptions2.rb
new file mode 100644
index 000000000..510db64d2
--- /dev/null
+++ b/db/migrate/20180609104432_migrate_web_push_subscriptions2.rb
@@ -0,0 +1,17 @@
+class MigrateWebPushSubscriptions2 < ActiveRecord::Migration[5.2]
+  disable_ddl_transaction!
+
+  def up
+    Web::PushSubscription.where(user_id: nil).select(:id).includes(:session_activation).find_each do |subscription|
+      if subscription.session_activation.nil?
+        subscription.delete
+      else
+        subscription.update_attribute(:user_id, subscription.session_activation.user_id)
+      end
+    end
+  end
+
+  def down
+    # Nothing to do
+  end
+end