mirror of
https://github.com/discourse/discourse.git
synced 2025-01-18 20:03:15 +08:00
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:
parent
4228c7e7d1
commit
cd3d24ed8c
|
@ -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
|
|
@ -4,7 +4,7 @@ class MigrateSearchDataAfterDefaultLocaleRename < ActiveRecord::Migration[6.0]
|
||||||
disable_ddl_transaction!
|
disable_ddl_transaction!
|
||||||
|
|
||||||
def up
|
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
|
end
|
||||||
|
|
||||||
def down
|
def down
|
||||||
|
@ -17,6 +17,8 @@ class MigrateSearchDataAfterDefaultLocaleRename < ActiveRecord::Migration[6.0]
|
||||||
key = "#{model}_id"
|
key = "#{model}_id"
|
||||||
table = "#{model}_search_data"
|
table = "#{model}_search_data"
|
||||||
|
|
||||||
|
puts "Migrating #{table} to new locale."
|
||||||
|
|
||||||
sql = <<~SQL
|
sql = <<~SQL
|
||||||
UPDATE #{table}
|
UPDATE #{table}
|
||||||
SET locale = 'en'
|
SET locale = 'en'
|
||||||
|
@ -24,7 +26,7 @@ class MigrateSearchDataAfterDefaultLocaleRename < ActiveRecord::Migration[6.0]
|
||||||
SELECT #{key}
|
SELECT #{key}
|
||||||
FROM #{table}
|
FROM #{table}
|
||||||
WHERE locale = 'en_US'
|
WHERE locale = 'en_US'
|
||||||
LIMIT 500000
|
LIMIT 100000
|
||||||
)
|
)
|
||||||
SQL
|
SQL
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user