hensei-api/db/data/20250115094623_populate_weapon_recruits.rb
Justin Edmund 0d46cb3833
Link Character and Weapon tables with granblue_id (#154)
* Add recruits column to weapons

* Populate recruits column with granblue_ids

* Remove recruits_id and index recruits
2025-01-15 02:11:06 -08:00

30 lines
762 B
Ruby

# frozen_string_literal: true
class PopulateWeaponRecruits < ActiveRecord::Migration[7.0]
def up
# Get all character mappings and convert to hash properly
results = execute(<<-SQL)
SELECT id, granblue_id
FROM characters
WHERE granblue_id IS NOT NULL
SQL
character_mapping = {}
results.each do |row|
character_mapping[row['id']] = row['granblue_id']
end
# Update weapons table using the mapping
character_mapping.each do |char_id, granblue_id|
execute(<<-SQL)
UPDATE weapons
SET recruits = #{connection.quote(granblue_id)}
WHERE recruits_id = #{connection.quote(char_id)}
SQL
end
end
def down
execute("UPDATE weapons SET recruits = NULL")
end
end