add weapon_series and weapon_key_series tables and models
This commit is contained in:
parent
e944f93ca3
commit
9d6dd335ae
5 changed files with 79 additions and 0 deletions
8
app/models/weapon_key_series.rb
Normal file
8
app/models/weapon_key_series.rb
Normal file
|
|
@ -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
|
||||||
32
app/models/weapon_series.rb
Normal file
32
app/models/weapon_series.rb
Normal file
|
|
@ -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
|
||||||
20
db/migrate/20251203173627_create_weapon_series.rb
Normal file
20
db/migrate/20251203173627_create_weapon_series.rb
Normal file
|
|
@ -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
|
||||||
|
|
@ -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
|
||||||
12
db/migrate/20251203173746_create_weapon_key_series.rb
Normal file
12
db/migrate/20251203173746_create_weapon_key_series.rb
Normal file
|
|
@ -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
|
||||||
Loading…
Reference in a new issue