From cbec0de81e1a774e1260d222dc3102f83c073494 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sat, 9 Jun 2018 13:33:04 +0200 Subject: [PATCH] Migrate old web push subscriptions to ensure deliveries (#7764) --- ...609104432_migrate_web_push_subscriptions2.rb | 17 +++++++++++++++++ db/schema.rb | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20180609104432_migrate_web_push_subscriptions2.rb 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 0000000000..510db64d23 --- /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 diff --git a/db/schema.rb b/db/schema.rb index c9d4e0fe7f..6564193a81 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2018_05_28_141303) do +ActiveRecord::Schema.define(version: 2018_06_09_104432) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql"