diff options
Diffstat (limited to 'db/migrate')
3 files changed, 34 insertions, 0 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 |