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
result = execute "SELECT 1 FROM categories WHERE lower(name) = 'uncategorized'"
name = 'Uncategorized'
name = +'Uncategorized'
if result.count > 0
name << SecureRandom.hex
end

View File

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