From 18c7a34b8f894b366fd1b926feee83c369e07fb6 Mon Sep 17 00:00:00 2001 From: Emi Matchu Date: Tue, 27 Feb 2024 15:48:28 -0800 Subject: [PATCH] Update `series_name` for alt styles to be null, with a fallback string I considered this at first, but decided to keep it simple until it turned out to matter. Oops, it already matters, lol! I want the item search code to be able to easily tell if the series name is real or a placeholder, so we can decide whether to build the filter text in `fits:$series-$color-$species` form or `fits:alt-style-$id` form. So in this change, we keep it that `AltStyle#series_name` returns the placeholder string if none is set, but callers can explicitly ask whether it's a real series name or not. Will use this in our next change! --- app/models/alt_style.rb | 14 ++++++++++++++ ...43_change_default_for_alt_styles_series_name.rb | 6 ++++++ db/schema.rb | 4 ++-- 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20240227233743_change_default_for_alt_styles_series_name.rb diff --git a/app/models/alt_style.rb b/app/models/alt_style.rb index 4671c0dd..d437bd9b 100644 --- a/app/models/alt_style.rb +++ b/app/models/alt_style.rb @@ -17,6 +17,20 @@ class AltStyle < ApplicationRecord species_human_name: species.human_name) end + # If the series_name hasn't yet been set manually by support staff, show the + # string "" instead. But it won't be searchable by that string—that is, + # `fits:-faerie-draik` intentionally will not work, and the canonical + # filter name will be `fits:alt-style-IDNUMBER`, instead. + def series_name + self[:series_name] || "" + end + + # You can use this to check whether `series_name` is returning the actual + # value or its placeholder value. + def has_real_series_name? + self[:series_name].present? + end + def adjective_name "#{series_name} #{color.human_name}" end diff --git a/db/migrate/20240227233743_change_default_for_alt_styles_series_name.rb b/db/migrate/20240227233743_change_default_for_alt_styles_series_name.rb new file mode 100644 index 00000000..359f9524 --- /dev/null +++ b/db/migrate/20240227233743_change_default_for_alt_styles_series_name.rb @@ -0,0 +1,6 @@ +class ChangeDefaultForAltStylesSeriesName < ActiveRecord::Migration[7.1] + def change + change_column_null :alt_styles, :series_name, true + change_column_default :alt_styles, :series_name, from: "", to: nil + end +end diff --git a/db/schema.rb b/db/schema.rb index 81c41f62..d066d8d0 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,14 +10,14 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2024_02_27_231815) do +ActiveRecord::Schema[7.1].define(version: 2024_02_27_233743) do create_table "alt_styles", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| t.integer "species_id", null: false t.integer "color_id", null: false t.integer "body_id", null: false t.datetime "created_at", precision: nil, null: false t.datetime "updated_at", precision: nil, null: false - t.string "series_name", default: "", null: false + t.string "series_name" t.index ["color_id"], name: "index_alt_styles_on_color_id" t.index ["species_id"], name: "index_alt_styles_on_species_id" end