about summary refs log tree commit diff
path: root/db
diff options
context:
space:
mode:
authorDavid Yip <yipdw@member.fsf.org>2018-06-12 18:13:30 -0500
committerGitHub <noreply@github.com>2018-06-12 18:13:30 -0500
commit5cff053944b4327477ca45882c9dd3b1a7a559e8 (patch)
tree83c564879534ea35f468ce319342e011773f24aa /db
parent99b2bc2668e79bacd7f8696315206872086ebf3a (diff)
parentf6bb50b6ece555af138df164680189b1ec57da4b (diff)
Merge branch 'master' into 454-allow-keyword-mutes-to-skip-mentions
Diffstat (limited to 'db')
-rw-r--r--db/migrate/20180608213548_reject_following_blocked_users.rb40
-rw-r--r--db/migrate/20180609104432_migrate_web_push_subscriptions2.rb17
-rw-r--r--db/schema.rb3
3 files changed, 59 insertions, 1 deletions
diff --git a/db/migrate/20180608213548_reject_following_blocked_users.rb b/db/migrate/20180608213548_reject_following_blocked_users.rb
new file mode 100644
index 000000000..302db6b68
--- /dev/null
+++ b/db/migrate/20180608213548_reject_following_blocked_users.rb
@@ -0,0 +1,40 @@
+class RejectFollowingBlockedUsers < ActiveRecord::Migration[5.2]
+  disable_ddl_transaction!
+
+  def up
+    blocked_follows = Follow.find_by_sql(<<-SQL)
+      select f.* from follows f
+      inner join blocks b on
+        f.account_id = b.target_account_id and
+        f.target_account_id = b.account_id
+    SQL
+
+    domain_blocked_follows = Follow.find_by_sql(<<-SQL)
+      select f.* from follows f
+      inner join accounts following on f.account_id = following.id
+      inner join account_domain_blocks b on
+        lower(b.domain) = lower(following.domain) and
+        f.target_account_id = b.account_id
+    SQL
+
+    follows = (blocked_follows + domain_blocked_follows).uniq
+    say "Destroying #{follows.size} blocked follow relationships..."
+
+    follows.each do |follow|
+      blocked_account = follow.account
+      followed_acccount = follow.target_account
+
+      next follow.destroy! if blocked_account.local?
+
+      reject_follow_json = Oj.dump(ActivityPub::LinkedDataSignature.new(ActiveModelSerializers::SerializableResource.new(follow, serializer: ActivityPub::RejectFollowSerializer, adapter: ActivityPub::Adapter).as_json).sign!(followed_acccount))
+
+      ActivityPub::DeliveryWorker.perform_async(reject_follow_json, followed_acccount, blocked_account.inbox_url)
+
+      follow.destroy!
+    end
+  end
+
+  def down
+    raise ActiveRecord::IrreversibleMigration
+  end
+end
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
diff --git a/db/schema.rb b/db/schema.rb
index 4f2c00099..b1e586944 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,8 +10,9 @@
 #
 # It's strongly recommended that you check this file into your version control system.
 
-ActiveRecord::Schema.define(version: 2018_06_04_000556) 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"