1
0
Fork 0
forked from OpenNeo/impress

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.)
This commit is contained in:
Emi Matchu 2024-05-02 13:00:10 -07:00
parent 73c2d4327a
commit 0943e2dbba
3 changed files with 13 additions and 3 deletions

View file

@ -429,6 +429,8 @@ class Item < ApplicationRecord
species_support_strs = info['species_support'] || [] species_support_strs = info['species_support'] || []
self.species_support_ids = species_support_strs.map(&:to_i) 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.name = info['name']
self.description = info['description'] self.description = info['description']
self.thumbnail_url = info['thumbnail_url'] self.thumbnail_url = info['thumbnail_url']

View file

@ -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

View file

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # 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| create_table "alt_styles", charset: "utf8mb4", collation: "utf8mb4_unicode_520_ci", force: :cascade do |t|
t.integer "species_id", null: false t.integer "species_id", null: false
t.integer "color_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.column "modeling_status_hint", "enum('done','glitchy')"
t.boolean "is_manually_nc", default: false, null: false t.boolean "is_manually_nc", default: false, null: false
t.string "name", 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.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", "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" 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 end
create_table "modeling_logs", id: :integer, charset: "utf8mb4", collation: "utf8mb4_unicode_520_ci", force: :cascade do |t| 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.text "log_json", size: :long, null: false
t.string "pet_name", limit: 128, null: false t.string "pet_name", limit: 128, null: false
end end