From a8cdd68518eafff4a9d955ed6f085994d50b0231 Mon Sep 17 00:00:00 2001 From: Gerhard Schlager Date: Mon, 22 Jul 2019 22:16:43 +0200 Subject: [PATCH] FIX: Migrations tried to change frozen string Also, makes the migration work with locales which use more than just the "one" and "other" keys. --- .../20131022045114_add_uncategorized_category.rb | 2 +- .../20150729150523_migrate_auto_close_posts.rb | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/db/migrate/20131022045114_add_uncategorized_category.rb b/db/migrate/20131022045114_add_uncategorized_category.rb index 14b17d10f0..cb362fb0c3 100644 --- a/db/migrate/20131022045114_add_uncategorized_category.rb +++ b/db/migrate/20131022045114_add_uncategorized_category.rb @@ -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 diff --git a/db/migrate/20150729150523_migrate_auto_close_posts.rb b/db/migrate/20150729150523_migrate_auto_close_posts.rb index 5b48992214..78508d7038 100644 --- a/db/migrate/20150729150523_migrate_auto_close_posts.rb +++ b/db/migrate/20150729150523_migrate_auto_close_posts.rb @@ -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