Follow-up for 89efcfcf to properly fix nested arrays

This commit is contained in:
Régis Hanol 2019-07-23 10:29:18 +02:00
parent f364317625
commit afe2be4f62
1 changed files with 10 additions and 10 deletions

View File

@ -4,20 +4,20 @@ class MigrateAutoClosePosts < ActiveRecord::Migration[4.2]
def up
I18n.overrides_disabled do
strings = []
%w(days hours lastpost_days lastpost_hours lastpost_minutes).map do |k|
strings += I18n.t("topic_statuses.autoclosed_enabled_#{k}").values.map { |s| s.sub("%{count}", "\\d+") }
%w(days hours lastpost_days lastpost_hours lastpost_minutes).each do |k|
I18n.t("topic_statuses.autoclosed_enabled_#{k}").values.each do |s|
strings << s.sub("%{count}", "\\d+")
end
end
sql = <<~SQL
execute <<~SQL
UPDATE posts
SET action_code = 'autoclosed.enabled',
post_type = 3
WHERE post_type = 2 AND (
#{strings.map { |s| "raw ~* #{ActiveRecord::Base.connection.quote(s)}" }.join(' OR ')}
)
SET action_code = 'autoclosed.enabled'
, post_type = 3
WHERE post_type = 2
AND (#{strings.map { |s| "raw ~* #{ActiveRecord::Base.connection.quote(s)}" }.join(' OR ')})
SQL
execute sql
end
end
end