add data migrations for artifacts and artifact_skills
This commit is contained in:
parent
c0f13c6b9c
commit
183641b842
2 changed files with 68 additions and 0 deletions
31
db/data/20251203205953_populate_artifacts.rb
Normal file
31
db/data/20251203205953_populate_artifacts.rb
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class PopulateArtifacts < ActiveRecord::Migration[8.0]
|
||||
def up
|
||||
require 'csv'
|
||||
|
||||
csv_path = Rails.root.join('lib', 'seeds', 'artifacts.csv')
|
||||
csv_text = File.read(csv_path)
|
||||
csv = CSV.parse(csv_text, headers: true, encoding: 'UTF-8')
|
||||
|
||||
puts 'Creating artifact records...'
|
||||
csv.each do |row|
|
||||
artifact = Artifact.find_or_initialize_by(granblue_id: row['granblue_id'])
|
||||
artifact.assign_attributes(
|
||||
name_en: row['name_en'],
|
||||
name_jp: row['name_jp'],
|
||||
proficiency: row['proficiency'].presence,
|
||||
rarity: row['rarity'],
|
||||
release_date: row['release_date']
|
||||
)
|
||||
artifact.save!
|
||||
puts " #{artifact.granblue_id}: #{artifact.name_en}"
|
||||
end
|
||||
|
||||
puts "\nCreated #{Artifact.count} artifact records"
|
||||
end
|
||||
|
||||
def down
|
||||
Artifact.delete_all
|
||||
end
|
||||
end
|
||||
37
db/data/20251203210023_populate_artifact_skills.rb
Normal file
37
db/data/20251203210023_populate_artifact_skills.rb
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class PopulateArtifactSkills < ActiveRecord::Migration[8.0]
|
||||
def up
|
||||
json_path = Rails.root.join('lib', 'seeds', 'artifact_skills.json')
|
||||
json_text = File.read(json_path)
|
||||
skills = JSON.parse(json_text)
|
||||
|
||||
puts 'Creating artifact skill records...'
|
||||
skills.each do |skill_data|
|
||||
skill = ArtifactSkill.find_or_initialize_by(
|
||||
skill_group: skill_data['skill_group'],
|
||||
modifier: skill_data['modifier']
|
||||
)
|
||||
skill.assign_attributes(
|
||||
name_en: skill_data['name_en'],
|
||||
name_jp: skill_data['name_jp'],
|
||||
base_values: skill_data['base_values'],
|
||||
growth: skill_data['growth'],
|
||||
suffix_en: skill_data['suffix_en'] || '',
|
||||
suffix_jp: skill_data['suffix_jp'] || '',
|
||||
polarity: skill_data['polarity']
|
||||
)
|
||||
skill.save!
|
||||
puts " Group #{skill_data['skill_group']}, Mod #{skill_data['modifier']}: #{skill.name_en}"
|
||||
end
|
||||
|
||||
# Clear cache after seeding
|
||||
ArtifactSkill.clear_cache!
|
||||
|
||||
puts "\nCreated #{ArtifactSkill.count} artifact skill records"
|
||||
end
|
||||
|
||||
def down
|
||||
ArtifactSkill.delete_all
|
||||
end
|
||||
end
|
||||
Loading…
Reference in a new issue