From 0943e2dbbabfc7f26691dd82e1a2077087c111c9 Mon Sep 17 00:00:00 2001 From: Matchu Date: Thu, 2 May 2024 13:00:10 -0700 Subject: [PATCH] Fix broken default value in schema for item description Idk how we got into this state, or if it's environment-dependent or MySQL-version-dependent or what, but setting up the dev environment on my macOS machine is complaining that `TEXT` columns can't have default values. Well, in that case, let's just have it be a non-nullable field, and add a note to our code that missing fields *can* cause item saving to fail! (This was always true, but I'm just extra-noting it because it's becoming *more* true.) --- app/models/item.rb | 2 ++ ...40502195157_fix_default_value_for_items_description.rb | 8 ++++++++ db/schema.rb | 6 +++--- 3 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20240502195157_fix_default_value_for_items_description.rb diff --git a/app/models/item.rb b/app/models/item.rb index 1587ca21..582d9e0b 100644 --- a/app/models/item.rb +++ b/app/models/item.rb @@ -429,6 +429,8 @@ class Item < ApplicationRecord species_support_strs = info['species_support'] || [] self.species_support_ids = species_support_strs.map(&:to_i) + # NOTE: If some of these fields are missing, it could cause saving the item + # to fail, because many of these columns are non-nullable. self.name = info['name'] self.description = info['description'] self.thumbnail_url = info['thumbnail_url'] diff --git a/db/migrate/20240502195157_fix_default_value_for_items_description.rb b/db/migrate/20240502195157_fix_default_value_for_items_description.rb new file mode 100644 index 00000000..174fdbf9 --- /dev/null +++ b/db/migrate/20240502195157_fix_default_value_for_items_description.rb @@ -0,0 +1,8 @@ +class FixDefaultValueForItemsDescription < ActiveRecord::Migration[7.1] + def change + # Idk why, but this column's default value is specified in our schema as + # an empty string, but setting up the dev environment on my macOS machine + # is saying on latest MariaDB that this isn't allowed. + change_column_default :items, :description, from: "", to: nil + end +end diff --git a/db/schema.rb b/db/schema.rb index 7a52309e..50954354 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[7.1].define(version: 2024_04_21_033509) do +ActiveRecord::Schema[7.1].define(version: 2024_05_02_195157) do create_table "alt_styles", charset: "utf8mb4", collation: "utf8mb4_unicode_520_ci", force: :cascade do |t| t.integer "species_id", null: false t.integer "color_id", null: false @@ -132,7 +132,7 @@ ActiveRecord::Schema[7.1].define(version: 2024_04_21_033509) do t.column "modeling_status_hint", "enum('done','glitchy')" t.boolean "is_manually_nc", default: false, null: false t.string "name", null: false - t.text "description", size: :medium, default: "", null: false + t.text "description", size: :medium, null: false t.string "rarity", default: "", null: false t.index ["modeling_status_hint", "created_at", "id"], name: "items_modeling_status_hint_and_created_at_and_id" t.index ["modeling_status_hint", "created_at"], name: "items_modeling_status_hint_and_created_at" @@ -149,7 +149,7 @@ ActiveRecord::Schema[7.1].define(version: 2024_04_21_033509) do end create_table "modeling_logs", id: :integer, charset: "utf8mb4", collation: "utf8mb4_unicode_520_ci", force: :cascade do |t| - t.datetime "created_at", precision: nil, default: -> { "current_timestamp()" }, null: false + t.datetime "created_at", precision: nil, default: -> { "CURRENT_TIMESTAMP" }, null: false t.text "log_json", size: :long, null: false t.string "pet_name", limit: 128, null: false end