From 75e33fd08fb4f926897490b6fa42890b393c0989 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sat, 12 Mar 2022 08:12:57 +0100 Subject: Fix null values being included in some indexes (#17711) * Fix null values being included in some indexes * Update lib/mastodon/migration_helpers.rb Co-authored-by: Claire * Add documentation link to corruption error message Co-authored-by: Claire --- ..._optimize_null_index_accounts_moved_to_account_id.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 db/post_migrate/20220310060722_optimize_null_index_accounts_moved_to_account_id.rb (limited to 'db/post_migrate/20220310060722_optimize_null_index_accounts_moved_to_account_id.rb') diff --git a/db/post_migrate/20220310060722_optimize_null_index_accounts_moved_to_account_id.rb b/db/post_migrate/20220310060722_optimize_null_index_accounts_moved_to_account_id.rb new file mode 100644 index 000000000..ec93a417a --- /dev/null +++ b/db/post_migrate/20220310060722_optimize_null_index_accounts_moved_to_account_id.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +require Rails.root.join('lib', 'mastodon', 'migration_helpers') + +class OptimizeNullIndexAccountsMovedToAccountId < ActiveRecord::Migration[5.2] + include Mastodon::MigrationHelpers + + disable_ddl_transaction! + + def up + update_index :accounts, 'index_accounts_on_moved_to_account_id', :moved_to_account_id, where: 'moved_to_account_id IS NOT NULL' + end + + def down + update_index :accounts, 'index_accounts_on_moved_to_account_id', :moved_to_account_id + end +end -- cgit