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:
parent
845fd42153
commit
a8cdd68518
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue