Add series_name database field to alt styles

Previously we did this hackily by comparing the ID to a hardcoded list
of IDs, but I think putting this in the database is clearer and more
robust, and it should also help with our upcoming item search stuff
that will filter by it!
This commit is contained in:
Emi Matchu 2024-02-27 15:28:05 -08:00
parent cd786ffcb1
commit 9f74e6020e
3 changed files with 34 additions and 13 deletions

View file

@ -6,23 +6,11 @@ class AltStyle < ApplicationRecord
has_many :swf_assets, through: :parent_swf_asset_relationships
has_many :contributions, as: :contributed, inverse_of: :contributed
SERIES_ID_RANGES = {
nostalgic: (87249..87503)
}
def name
I18n.translate('pet_types.human_name', color_human_name: color.human_name,
species_human_name: species.human_name)
end
def series_name
if SERIES_ID_RANGES[:nostalgic].include?(id)
"Nostalgic"
else
"???"
end
end
def adjective_name
"#{series_name} #{color.human_name}"
end

View file

@ -0,0 +1,18 @@
class AddSeriesNameToAltStyles < ActiveRecord::Migration[7.1]
def change
add_column :alt_styles, :series_name, :string, null: false,
default: "<New?>"
reversible do |direction|
direction.up do
# These IDs are determined by Neopets.com, so referencing them like
# this should be relatively stable! Backfill the series name
# "Nostalgic" for all alt styles in the Nostalgic ID range. (At time
# of writing, *all* alt styles are Nostalgic, but I'm writing it like
# this for clarity and future-proofing!)
AltStyle.where("id >= 87249 AND id <= 87503").update_all(
series_name: "Nostalgic")
end
end
end
end

View file

@ -10,13 +10,14 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.1].define(version: 2024_02_25_231346) do
ActiveRecord::Schema[7.1].define(version: 2024_02_27_231815) 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: "<New?>", null: false
t.index ["color_id"], name: "index_alt_styles_on_color_id"
t.index ["species_id"], name: "index_alt_styles_on_species_id"
end
@ -115,6 +116,20 @@ ActiveRecord::Schema[7.1].define(version: 2024_02_25_231346) do
t.index ["outfit_id", "is_worn"], name: "index_item_outfit_relationships_on_outfit_id_and_is_worn"
end
create_table "item_translations", id: :integer, charset: "latin1", collation: "latin1_swedish_ci", force: :cascade do |t|
t.integer "item_id"
t.string "locale"
t.string "name"
t.text "description"
t.string "rarity"
t.datetime "created_at", precision: nil
t.datetime "updated_at", precision: nil
t.index ["item_id", "locale"], name: "index_item_translations_on_item_id_and_locale"
t.index ["item_id"], name: "index_item_translations_on_item_id"
t.index ["locale"], name: "index_item_translations_on_locale"
t.index ["name"], name: "index_item_translations_name"
end
create_table "items", id: :integer, charset: "utf8mb3", collation: "utf8mb3_unicode_ci", force: :cascade do |t|
t.text "zones_restrict", null: false
t.text "thumbnail_url", size: :medium, null: false