From 9d4f18b984d6699bdf96e5f5963edfe80063426c Mon Sep 17 00:00:00 2001 From: Fire Demon Date: Sat, 27 Jun 2020 14:22:30 -0500 Subject: Monsterfork v2 Kaiju Commit 2020.06.27.1 - 2020.09.05.5 --- .../20200816200239_backfill_root_to_conversations.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 db/migrate/20200816200239_backfill_root_to_conversations.rb (limited to 'db/migrate/20200816200239_backfill_root_to_conversations.rb') 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 -- cgit