From d7d421b88f1a1cf1ee5c8d5347691f27cd84a8b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Sun, 17 May 2020 23:12:06 +0200 Subject: [PATCH] Rename columns with a slash in their names These columns were causing Rails 5.2 to throw a warning when ordering by them, as if they weren't valid column names: DEPRECATION WARNING: Dangerous query method (method whose arguments are used as raw SQL) called with non-attribute argument(s): :"budget/investments_count". Non-attribute arguments will be disallowed in Rails 6.0. This method should not be called with user-provided values, such as request parameters or model attributes. Known-safe values can be passed by wrapping them in Arel.sql(). This change also makes their names consistent with the rest of our tables and columns. --- app/models/tag_cloud.rb | 2 +- config/initializers/acts_as_taggable_on.rb | 2 +- ...519120717_rename_columns_with_slash_characters.rb | 9 +++++++++ db/schema.rb | 12 ++++++------ 4 files changed, 17 insertions(+), 8 deletions(-) create mode 100644 db/migrate/20200519120717_rename_columns_with_slash_characters.rb diff --git a/app/models/tag_cloud.rb b/app/models/tag_cloud.rb index f76275558..2008685b3 100644 --- a/app/models/tag_cloud.rb +++ b/app/models/tag_cloud.rb @@ -31,6 +31,6 @@ class TagCloud end def table_name - resource_model.to_s.downcase.pluralize.gsub("::", "/") + resource_model.to_s.tableize.tr("/", "_") end end diff --git a/config/initializers/acts_as_taggable_on.rb b/config/initializers/acts_as_taggable_on.rb index f1cff9c31..df1453908 100644 --- a/config/initializers/acts_as_taggable_on.rb +++ b/config/initializers/acts_as_taggable_on.rb @@ -79,7 +79,7 @@ module ActsAsTaggableOn private def custom_counter_field_name_for(taggable_type) - "#{taggable_type.underscore.pluralize}_count" + "#{taggable_type.tableize.tr("/", "_")}_count" end end end diff --git a/db/migrate/20200519120717_rename_columns_with_slash_characters.rb b/db/migrate/20200519120717_rename_columns_with_slash_characters.rb new file mode 100644 index 000000000..0884c421a --- /dev/null +++ b/db/migrate/20200519120717_rename_columns_with_slash_characters.rb @@ -0,0 +1,9 @@ +class RenameColumnsWithSlashCharacters < ActiveRecord::Migration[5.1] + def change + change_table :tags do |t| + t.rename :"budget/investments_count", :budget_investments_count + t.rename :"legislation/proposals_count", :legislation_proposals_count + t.rename :"legislation/processes_count", :legislation_processes_count + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 57012aa3c..573774563 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20191108173350) do +ActiveRecord::Schema.define(version: 20200519120717) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -1407,12 +1407,12 @@ ActiveRecord::Schema.define(version: 20191108173350) do t.integer "debates_count", default: 0 t.integer "proposals_count", default: 0 t.string "kind" - t.integer "budget/investments_count", default: 0 - t.integer "legislation/proposals_count", default: 0 - t.integer "legislation/processes_count", default: 0 + t.integer "budget_investments_count", default: 0 + t.integer "legislation_proposals_count", default: 0 + t.integer "legislation_processes_count", default: 0 t.index ["debates_count"], name: "index_tags_on_debates_count" - t.index ["legislation/processes_count"], name: "index_tags_on_legislation/processes_count" - t.index ["legislation/proposals_count"], name: "index_tags_on_legislation/proposals_count" + t.index ["legislation_processes_count"], name: "index_tags_on_legislation_processes_count" + t.index ["legislation_proposals_count"], name: "index_tags_on_legislation_proposals_count" t.index ["name"], name: "index_tags_on_name", unique: true t.index ["proposals_count"], name: "index_tags_on_proposals_count" end