Populate recruits column with granblue_ids
This commit is contained in:
parent
eb44c04eb5
commit
2ff6cd233a
2 changed files with 31 additions and 1 deletions
30
db/data/20250115094623_populate_weapon_recruits.rb
Normal file
30
db/data/20250115094623_populate_weapon_recruits.rb
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
# 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
|
||||||
|
|
@ -1 +1 @@
|
||||||
DataMigrate::Data.define(version: 20231119051223)
|
DataMigrate::Data.define(version: 20250115094623)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue