A platform for community discussion. Free, open, simple.
FIX: move post_search_data migration into onceoff job (#11851)
Régis Hanolcd3d24ed8c2a
diff --git a/app/jobs/onceoff/fix_post_search_data_after_default_locale_rename.rb b/app/jobs/onceoff/fix_post_search_data_after_default_locale_rename.rbnew file mode 100644index 00000000000..76e0b10d247--- /dev/null+++ b/app/jobs/onceoff/fix_post_search_data_after_default_locale_rename.rb@@ -0,0 +1,22 @@+# frozen_string_literal: true++module Jobs+ class FixPostSearchDataAfterDefaultLocaleRename < ::Jobs::Onceoff+ def execute_onceoff(args)+ return if SearchIndexer::POST_INDEX_VERSION != 4++ sql = <<~SQL+ UPDATE post_search_data+ SET locale = 'en'+ WHERE post_id IN (+ SELECT post_id+ FROM post_search_data+ WHERE locale = 'en_US'+ LIMIT 100000+ )+ SQL++ loop { break if DB.exec(sql) == 0 }+ end+ end+enddiff --git a/db/post_migrate/20210125100452_migrate_search_data_after_default_locale_rename.rb b/db/post_migrate/20210125100452_migrate_search_data_after_default_locale_rename.rbindex 407dfd8bb58..5d3f6e6d010 100644--- a/db/post_migrate/20210125100452_migrate_search_data_after_default_locale_rename.rb+++ b/db/post_migrate/20210125100452_migrate_search_data_after_default_locale_rename.rb@@ -4,7 +4,7 @@ class MigrateSearchDataAfterDefaultLocaleRename < ActiveRecord::Migration[6.0]disable_ddl_transaction!def up- %w{category tag topic post user}.each { |model| fix_search_data(model) }+ %w{category tag topic user}.each { |model| fix_search_data(model) }enddef down@@ -17,6 +17,8 @@ class MigrateSearchDataAfterDefaultLocaleRename < ActiveRecord::Migration[6.0]key = "#{model}_id"table = "#{model}_search_data"+ puts "Migrating #{table} to new locale."+sql = <<~SQLUPDATE #{table}SET locale = 'en'@@ -24,7 +26,7 @@ class MigrateSearchDataAfterDefaultLocaleRename < ActiveRecord::Migration[6.0]SELECT #{key}FROM #{table}WHERE locale = 'en_US'- LIMIT 500000+ LIMIT 100000)SQL