From b1e6e6957e62f3da3857f42ec6c343cb9660434d Mon Sep 17 00:00:00 2001 From: Fire Demon Date: Sun, 16 Aug 2020 23:18:38 -0500 Subject: [Federation] Include and dereference URI to the root post of threads; dynamically update thread permissions --- .../20200816200108_add_root_to_conversations.rb | 7 +++++++ .../20200816200239_backfill_root_to_conversations.rb | 19 +++++++++++++++++++ .../20200817003033_add_defaults_to_conversations.rb | 8 ++++++++ 3 files changed, 34 insertions(+) create mode 100644 db/migrate/20200816200108_add_root_to_conversations.rb create mode 100644 db/migrate/20200816200239_backfill_root_to_conversations.rb create mode 100644 db/migrate/20200817003033_add_defaults_to_conversations.rb (limited to 'db/migrate') diff --git a/db/migrate/20200816200108_add_root_to_conversations.rb b/db/migrate/20200816200108_add_root_to_conversations.rb new file mode 100644 index 000000000..f45a3b476 --- /dev/null +++ b/db/migrate/20200816200108_add_root_to_conversations.rb @@ -0,0 +1,7 @@ +class AddRootToConversations < ActiveRecord::Migration[5.2] + def change + safety_assured do + add_column :conversations, :root, :string, index: true + end + end +end diff --git a/db/migrate/20200816200239_backfill_root_to_conversations.rb b/db/migrate/20200816200239_backfill_root_to_conversations.rb new file mode 100644 index 000000000..2056e0765 --- /dev/null +++ b/db/migrate/20200816200239_backfill_root_to_conversations.rb @@ -0,0 +1,19 @@ +class BackfillRootToConversations < ActiveRecord::Migration[5.2] + disable_ddl_transaction! + + def up + Rails.logger.info("Adding URI to statuses without one...") + Status.where(uri: nil).or(Status.where(uri: '')).find_each do |status| + status.update(uri: ActivityPub::TagManager.instance.uri_for(status)) + end + + Rails.logger.info('Setting root of all conversations...') + safety_assured do + execute('UPDATE conversations SET root = s.uri FROM (SELECT conversation_id, uri FROM statuses WHERE NOT reply) AS s WHERE conversations.id = s.conversation_id') + end + end + + def down + true + end +end diff --git a/db/migrate/20200817003033_add_defaults_to_conversations.rb b/db/migrate/20200817003033_add_defaults_to_conversations.rb new file mode 100644 index 000000000..fc3c0ceee --- /dev/null +++ b/db/migrate/20200817003033_add_defaults_to_conversations.rb @@ -0,0 +1,8 @@ +class AddDefaultsToConversations < ActiveRecord::Migration[5.2] + def change + safety_assured do + change_column :conversations, :account_id, :bigint, default: nil + change_column :conversations, :root, :string, default: nil + end + end +end -- cgit