add fk columns for ax modifiers and befoulments, replace has_ax_skills with augment_type
This commit is contained in:
parent
f30deea5d7
commit
9074f7301f
4 changed files with 135 additions and 0 deletions
64
db/data/20251230000002_migrate_ax_modifiers_to_fk.rb
Normal file
64
db/data/20251230000002_migrate_ax_modifiers_to_fk.rb
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class MigrateAxModifiersToFk < ActiveRecord::Migration[8.0]
|
||||
def up
|
||||
# Build lookup cache: game_skill_id -> weapon_stat_modifier.id
|
||||
modifier_lookup = WeaponStatModifier.pluck(:game_skill_id, :id).to_h
|
||||
|
||||
# Migrate CollectionWeapon ax_modifier1
|
||||
CollectionWeapon.where.not(ax_modifier1: nil).find_each do |cw|
|
||||
modifier_id = modifier_lookup[cw.ax_modifier1]
|
||||
if modifier_id
|
||||
cw.update_columns(ax_modifier1_ref_id: modifier_id)
|
||||
else
|
||||
Rails.logger.warn "[MigrateAxModifiers] Unknown ax_modifier1=#{cw.ax_modifier1} on CollectionWeapon##{cw.id}"
|
||||
end
|
||||
end
|
||||
|
||||
# Migrate CollectionWeapon ax_modifier2
|
||||
CollectionWeapon.where.not(ax_modifier2: nil).find_each do |cw|
|
||||
modifier_id = modifier_lookup[cw.ax_modifier2]
|
||||
if modifier_id
|
||||
cw.update_columns(ax_modifier2_ref_id: modifier_id)
|
||||
else
|
||||
Rails.logger.warn "[MigrateAxModifiers] Unknown ax_modifier2=#{cw.ax_modifier2} on CollectionWeapon##{cw.id}"
|
||||
end
|
||||
end
|
||||
|
||||
# Migrate GridWeapon ax_modifier1
|
||||
GridWeapon.where.not(ax_modifier1: nil).find_each do |gw|
|
||||
modifier_id = modifier_lookup[gw.ax_modifier1]
|
||||
if modifier_id
|
||||
gw.update_columns(ax_modifier1_ref_id: modifier_id)
|
||||
else
|
||||
Rails.logger.warn "[MigrateAxModifiers] Unknown ax_modifier1=#{gw.ax_modifier1} on GridWeapon##{gw.id}"
|
||||
end
|
||||
end
|
||||
|
||||
# Migrate GridWeapon ax_modifier2
|
||||
GridWeapon.where.not(ax_modifier2: nil).find_each do |gw|
|
||||
modifier_id = modifier_lookup[gw.ax_modifier2]
|
||||
if modifier_id
|
||||
gw.update_columns(ax_modifier2_ref_id: modifier_id)
|
||||
else
|
||||
Rails.logger.warn "[MigrateAxModifiers] Unknown ax_modifier2=#{gw.ax_modifier2} on GridWeapon##{gw.id}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
# Reverse: copy FK back to integer columns
|
||||
WeaponStatModifier.find_each do |modifier|
|
||||
next unless modifier.game_skill_id
|
||||
|
||||
CollectionWeapon.where(ax_modifier1_ref_id: modifier.id)
|
||||
.update_all(ax_modifier1: modifier.game_skill_id)
|
||||
CollectionWeapon.where(ax_modifier2_ref_id: modifier.id)
|
||||
.update_all(ax_modifier2: modifier.game_skill_id)
|
||||
GridWeapon.where(ax_modifier1_ref_id: modifier.id)
|
||||
.update_all(ax_modifier1: modifier.game_skill_id)
|
||||
GridWeapon.where(ax_modifier2_ref_id: modifier.id)
|
||||
.update_all(ax_modifier2: modifier.game_skill_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
25
db/migrate/20251230000002_add_weapon_stat_modifier_fks.rb
Normal file
25
db/migrate/20251230000002_add_weapon_stat_modifier_fks.rb
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AddWeaponStatModifierFks < ActiveRecord::Migration[8.0]
|
||||
def change
|
||||
# collection_weapons - add FK columns
|
||||
add_reference :collection_weapons, :ax_modifier1_ref,
|
||||
foreign_key: { to_table: :weapon_stat_modifiers }
|
||||
add_reference :collection_weapons, :ax_modifier2_ref,
|
||||
foreign_key: { to_table: :weapon_stat_modifiers }
|
||||
add_reference :collection_weapons, :befoulment_modifier,
|
||||
foreign_key: { to_table: :weapon_stat_modifiers }
|
||||
add_column :collection_weapons, :befoulment_strength, :float
|
||||
add_column :collection_weapons, :exorcism_level, :integer, default: 0
|
||||
|
||||
# grid_weapons - same pattern
|
||||
add_reference :grid_weapons, :ax_modifier1_ref,
|
||||
foreign_key: { to_table: :weapon_stat_modifiers }
|
||||
add_reference :grid_weapons, :ax_modifier2_ref,
|
||||
foreign_key: { to_table: :weapon_stat_modifiers }
|
||||
add_reference :grid_weapons, :befoulment_modifier,
|
||||
foreign_key: { to_table: :weapon_stat_modifiers }
|
||||
add_column :grid_weapons, :befoulment_strength, :float
|
||||
add_column :grid_weapons, :exorcism_level, :integer, default: 0
|
||||
end
|
||||
end
|
||||
17
db/migrate/20251230000003_finalize_ax_modifier_columns.rb
Normal file
17
db/migrate/20251230000003_finalize_ax_modifier_columns.rb
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class FinalizeAxModifierColumns < ActiveRecord::Migration[8.0]
|
||||
def change
|
||||
# Remove old integer columns
|
||||
remove_column :collection_weapons, :ax_modifier1, :integer
|
||||
remove_column :collection_weapons, :ax_modifier2, :integer
|
||||
remove_column :grid_weapons, :ax_modifier1, :integer
|
||||
remove_column :grid_weapons, :ax_modifier2, :integer
|
||||
|
||||
# Rename new FK columns to the original names
|
||||
rename_column :collection_weapons, :ax_modifier1_ref_id, :ax_modifier1_id
|
||||
rename_column :collection_weapons, :ax_modifier2_ref_id, :ax_modifier2_id
|
||||
rename_column :grid_weapons, :ax_modifier1_ref_id, :ax_modifier1_id
|
||||
rename_column :grid_weapons, :ax_modifier2_ref_id, :ax_modifier2_id
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AddAugmentTypeToWeaponSeries < ActiveRecord::Migration[8.0]
|
||||
def up
|
||||
add_column :weapon_series, :augment_type, :integer, default: 0, null: false
|
||||
|
||||
# Migrate existing has_ax_skills: true to augment_type: 1 (ax)
|
||||
execute <<-SQL.squish
|
||||
UPDATE weapon_series
|
||||
SET augment_type = 1
|
||||
WHERE has_ax_skills = true
|
||||
SQL
|
||||
|
||||
remove_column :weapon_series, :has_ax_skills
|
||||
end
|
||||
|
||||
def down
|
||||
add_column :weapon_series, :has_ax_skills, :boolean, default: false, null: false
|
||||
|
||||
# Migrate augment_type: 1 (ax) back to has_ax_skills: true
|
||||
execute <<-SQL.squish
|
||||
UPDATE weapon_series
|
||||
SET has_ax_skills = true
|
||||
WHERE augment_type = 1
|
||||
SQL
|
||||
|
||||
remove_column :weapon_series, :augment_type
|
||||
end
|
||||
end
|
||||
Loading…
Reference in a new issue