FIX: Migrations tried to change frozen string

Also, makes the migration work with locales which use more than just the "one" and "other" keys.
This commit is contained in:
Gerhard Schlager 2019-07-22 22:16:43 +02:00
parent 845fd42153
commit a8cdd68518
2 changed files with 10 additions and 7 deletions

View File

@ -4,7 +4,7 @@ class AddUncategorizedCategory < ActiveRecord::Migration[4.2]
def up def up
result = execute "SELECT 1 FROM categories WHERE lower(name) = 'uncategorized'" result = execute "SELECT 1 FROM categories WHERE lower(name) = 'uncategorized'"
name = 'Uncategorized' name = +'Uncategorized'
if result.count > 0 if result.count > 0
name << SecureRandom.hex name << SecureRandom.hex
end end

View File

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