about summary refs log tree commit diff
path: root/db
diff options
context:
space:
mode:
authorFire Demon <firedemon@creature.cafe>2020-07-21 23:40:01 -0500
committerFire Demon <firedemon@creature.cafe>2020-08-30 05:44:01 -0500
commitc752a46c457759149c14ae0e4d501d5ef2ce478a (patch)
tree5066a3b5cf73ba06d16a8b494bc3e91a094f807b /db
parent03338243d28df8ecca77785c77214260ca0c32c9 (diff)
[Privacy] Implement thread ownership and visibility
Diffstat (limited to 'db')
-rw-r--r--db/migrate/20200721202723_add_account_id_to_conversations.rb9
-rw-r--r--db/migrate/20200721212401_backfill_account_id_on_conversations.rb15
-rw-r--r--db/migrate/20200721221427_add_public_to_conversations.rb7
-rw-r--r--db/migrate/20200721221659_backfill_conversation_visibility.rb15
-rw-r--r--db/schema.rb6
5 files changed, 51 insertions, 1 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
diff --git a/db/schema.rb b/db/schema.rb
index 674ff8ab6..901c13c76 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: 2020_07_21_195456) do
+ActiveRecord::Schema.define(version: 2020_07_21_221659) do
 
   # These are extensions that must be enabled in order to support this database
   enable_extension "plpgsql"
@@ -286,6 +286,9 @@ ActiveRecord::Schema.define(version: 2020_07_21_195456) do
     t.string "uri"
     t.datetime "created_at", null: false
     t.datetime "updated_at", null: false
+    t.bigint "account_id"
+    t.boolean "public", default: false, null: false
+    t.index ["account_id"], name: "index_conversations_on_account_id"
     t.index ["uri"], name: "index_conversations_on_uri", unique: true
   end
 
@@ -964,6 +967,7 @@ ActiveRecord::Schema.define(version: 2020_07_21_195456) do
   add_foreign_key "bookmarks", "statuses", on_delete: :cascade
   add_foreign_key "conversation_mutes", "accounts", name: "fk_225b4212bb", on_delete: :cascade
   add_foreign_key "conversation_mutes", "conversations", on_delete: :cascade
+  add_foreign_key "conversations", "accounts"
   add_foreign_key "custom_filters", "accounts", on_delete: :cascade
   add_foreign_key "devices", "accounts", on_delete: :cascade
   add_foreign_key "devices", "oauth_access_tokens", column: "access_token_id", on_delete: :cascade