diff options
author | Fire Demon <firedemon@creature.cafe> | 2020-07-21 23:40:01 -0500 |
---|---|---|
committer | Fire Demon <firedemon@creature.cafe> | 2020-08-30 05:44:01 -0500 |
commit | c752a46c457759149c14ae0e4d501d5ef2ce478a (patch) | |
tree | 5066a3b5cf73ba06d16a8b494bc3e91a094f807b /db/migrate | |
parent | 03338243d28df8ecca77785c77214260ca0c32c9 (diff) |
[Privacy] Implement thread ownership and visibility
Diffstat (limited to 'db/migrate')
4 files changed, 46 insertions, 0 deletions
diff --git a/db/migrate/20200721202723_add_account_id_to_conversations.rb b/db/migrate/20200721202723_add_account_id_to_conversations.rb new file mode 100644 index 000000000..afddf4823 --- /dev/null +++ b/db/migrate/20200721202723_add_account_id_to_conversations.rb @@ -0,0 +1,9 @@ +class AddAccountIdToConversations < ActiveRecord::Migration[5.2] + disable_ddl_transaction! + + def change + safety_assured do + add_reference :conversations, :account, foreign_key: true, index: {algorithm: :concurrently} + end + end +end diff --git a/db/migrate/20200721212401_backfill_account_id_on_conversations.rb b/db/migrate/20200721212401_backfill_account_id_on_conversations.rb new file mode 100644 index 000000000..595fd8e52 --- /dev/null +++ b/db/migrate/20200721212401_backfill_account_id_on_conversations.rb @@ -0,0 +1,15 @@ +class BackfillAccountIdOnConversations < ActiveRecord::Migration[5.2] + disable_ddl_transaction! + + def up + Rails.logger.info('Backfilling owners of conversation threads...') + safety_assured do + Conversation.left_outer_joins(:statuses).where(statuses: { id: nil }).in_batches.destroy_all + execute('UPDATE conversations SET account_id = s.account_id FROM (SELECT account_id, conversation_id 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/20200721221427_add_public_to_conversations.rb b/db/migrate/20200721221427_add_public_to_conversations.rb new file mode 100644 index 000000000..392bd7418 --- /dev/null +++ b/db/migrate/20200721221427_add_public_to_conversations.rb @@ -0,0 +1,7 @@ +class AddPublicToConversations < ActiveRecord::Migration[5.2] + def change + safety_assured do + add_column :conversations, :public, :boolean, default: false, null: false + end + end +end diff --git a/db/migrate/20200721221659_backfill_conversation_visibility.rb b/db/migrate/20200721221659_backfill_conversation_visibility.rb new file mode 100644 index 000000000..93394b825 --- /dev/null +++ b/db/migrate/20200721221659_backfill_conversation_visibility.rb @@ -0,0 +1,15 @@ +class BackfillConversationVisibility < ActiveRecord::Migration[5.2] + disable_ddl_transaction! + + def up + Rails.logger.info('Backfilling thread visibility...') + + safety_assured do + execute('UPDATE conversations SET public = true FROM (SELECT account_id, conversation_id FROM statuses WHERE NOT reply AND visibility IN (0, 1)) AS s WHERE conversations.id = s.conversation_id') + end + end + + def down + true + end +end |