FIX: move post_search_data migration into onceoff job (#11851)

And reduce the size of the batches to 100k.

That should hopefully make the migrations run smoother...
This commit is contained in:
Régis Hanol 2021-01-26 16:29:00 +01:00 committed by GitHub
parent 4228c7e7d1
commit cd3d24ed8c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 2 deletions

View File

@ -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
end

View File

@ -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) }
end
def 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 = <<~SQL
UPDATE #{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