From 9d6dd335ae38858537605cb3bc05c2cb787dfc87 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Wed, 3 Dec 2025 10:45:25 -0800 Subject: [PATCH] add weapon_series and weapon_key_series tables and models --- app/models/weapon_key_series.rb | 8 +++++ app/models/weapon_series.rb | 32 +++++++++++++++++++ .../20251203173627_create_weapon_series.rb | 20 ++++++++++++ ...3173721_add_weapon_series_id_to_weapons.rb | 7 ++++ ...20251203173746_create_weapon_key_series.rb | 12 +++++++ 5 files changed, 79 insertions(+) create mode 100644 app/models/weapon_key_series.rb create mode 100644 app/models/weapon_series.rb create mode 100644 db/migrate/20251203173627_create_weapon_series.rb create mode 100644 db/migrate/20251203173721_add_weapon_series_id_to_weapons.rb create mode 100644 db/migrate/20251203173746_create_weapon_key_series.rb diff --git a/app/models/weapon_key_series.rb b/app/models/weapon_key_series.rb new file mode 100644 index 0000000..9d5fd72 --- /dev/null +++ b/app/models/weapon_key_series.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +class WeaponKeySeries < ApplicationRecord + belongs_to :weapon_key + belongs_to :weapon_series + + validates :weapon_key_id, uniqueness: { scope: :weapon_series_id } +end diff --git a/app/models/weapon_series.rb b/app/models/weapon_series.rb new file mode 100644 index 0000000..54cd116 --- /dev/null +++ b/app/models/weapon_series.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +class WeaponSeries < ApplicationRecord + has_many :weapons, dependent: :restrict_with_error + has_many :weapon_key_series, dependent: :destroy + has_many :weapon_keys, through: :weapon_key_series + + validates :name_en, presence: true + validates :name_jp, presence: true + validates :slug, presence: true, uniqueness: true + validates :order, numericality: { only_integer: true } + + scope :ordered, -> { order(:order) } + scope :extra_allowed, -> { where(extra: true) } + scope :element_changeable, -> { where(element_changeable: true) } + scope :with_weapon_keys, -> { where(has_weapon_keys: true) } + scope :with_awakening, -> { where(has_awakening: true) } + scope :with_ax_skills, -> { where(has_ax_skills: true) } + + # Slug constants for commonly referenced series + DARK_OPUS = 'dark-opus' + DRACONIC = 'draconic' + DRACONIC_PROVIDENCE = 'draconic-providence' + REVENANT = 'revenant' + ULTIMA = 'ultima' + SUPERLATIVE = 'superlative' + CLASS_CHAMPION = 'class-champion' + + def blueprint + WeaponSeriesBlueprint + end +end diff --git a/db/migrate/20251203173627_create_weapon_series.rb b/db/migrate/20251203173627_create_weapon_series.rb new file mode 100644 index 0000000..a1fea2c --- /dev/null +++ b/db/migrate/20251203173627_create_weapon_series.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +class CreateWeaponSeries < ActiveRecord::Migration[8.0] + def change + create_table :weapon_series, id: :uuid do |t| + t.string :name_en, null: false + t.string :name_jp, null: false + t.string :slug, null: false + t.integer :order, default: 0, null: false + t.boolean :extra, default: false, null: false + t.boolean :element_changeable, default: false, null: false + t.boolean :has_weapon_keys, default: false, null: false + t.boolean :has_awakening, default: false, null: false + t.boolean :has_ax_skills, default: false, null: false + end + + add_index :weapon_series, :slug, unique: true + add_index :weapon_series, :order + end +end diff --git a/db/migrate/20251203173721_add_weapon_series_id_to_weapons.rb b/db/migrate/20251203173721_add_weapon_series_id_to_weapons.rb new file mode 100644 index 0000000..73627ac --- /dev/null +++ b/db/migrate/20251203173721_add_weapon_series_id_to_weapons.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddWeaponSeriesIdToWeapons < ActiveRecord::Migration[8.0] + def change + add_reference :weapons, :weapon_series, type: :uuid, foreign_key: true, index: true + end +end diff --git a/db/migrate/20251203173746_create_weapon_key_series.rb b/db/migrate/20251203173746_create_weapon_key_series.rb new file mode 100644 index 0000000..bb80a76 --- /dev/null +++ b/db/migrate/20251203173746_create_weapon_key_series.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +class CreateWeaponKeySeries < ActiveRecord::Migration[8.0] + def change + create_table :weapon_key_series, id: :uuid do |t| + t.references :weapon_key, type: :uuid, null: false, foreign_key: true + t.references :weapon_series, type: :uuid, null: false, foreign_key: true + end + + add_index :weapon_key_series, %i[weapon_key_id weapon_series_id], unique: true + end +end