diff options
author | Fire Demon <firedemon@creature.cafe> | 2020-08-16 23:18:38 -0500 |
---|---|---|
committer | Fire Demon <firedemon@creature.cafe> | 2020-08-30 05:45:18 -0500 |
commit | b1e6e6957e62f3da3857f42ec6c343cb9660434d (patch) | |
tree | e1305ef8cf98aabe10fa58c8bc27d0408c681066 /db | |
parent | af0b6f445c597b41e861da9e77f39b4caed3e753 (diff) |
[Federation] Include and dereference URI to the root post of threads; dynamically update thread permissions
Diffstat (limited to 'db')
-rw-r--r-- | db/migrate/20200816200108_add_root_to_conversations.rb | 7 | ||||
-rw-r--r-- | db/migrate/20200816200239_backfill_root_to_conversations.rb | 19 | ||||
-rw-r--r-- | db/migrate/20200817003033_add_defaults_to_conversations.rb | 8 | ||||
-rw-r--r-- | db/schema.rb | 5 |
4 files changed, 37 insertions, 2 deletions
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 diff --git a/db/schema.rb b/db/schema.rb index 7d3ec26d7..5d7bd5262 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_08_11_024642) do +ActiveRecord::Schema.define(version: 2020_08_17_003653) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -306,6 +306,7 @@ ActiveRecord::Schema.define(version: 2020_08_11_024642) do t.datetime "updated_at", null: false t.bigint "account_id" t.boolean "public", default: false, null: false + t.string "root" t.index ["account_id"], name: "index_conversations_on_account_id" t.index ["uri"], name: "index_conversations_on_uri", unique: true end @@ -818,7 +819,7 @@ ActiveRecord::Schema.define(version: 2020_08_11_024642) do end create_table "status_mutes", force: :cascade do |t| - t.integer "account_id", null: false + t.bigint "account_id", null: false t.bigint "status_id", null: false t.index ["account_id", "status_id"], name: "index_status_mutes_on_account_id_and_status_id", unique: true t.index ["account_id"], name: "index_status_mutes_on_account_id" |