refactor: simplify region creation and update code attribute
Some checks are pending
Docker / docker (push) Waiting to run
CI / scan_ruby (push) Waiting to run
CI / lint (push) Waiting to run
CI / test (push) Waiting to run

- Change from find_or_initialize_by to find_or_create_by for
  regions.
- Set region code to the name instead of nil.

This refactor reduces complexity in how regions are created and
ensures the code attribute is properly populated with the
region's name, enhancing data consistency.
This commit is contained in:
songtianlun 2025-02-10 18:01:41 +08:00
parent 97330fef91
commit 29ad6be241

View File

@ -22,14 +22,12 @@ namespace :geo do
count = 1
regions.each do |data|
region = Region.find_or_initialize_by(name: data["name"]) do |r|
end
region = Region.find_or_create_by(name: data["name"])
puts "Sync Regions[#{count}/#{sum}]: [#{region.name}]"
count += 1
region.update(
name: data["name"],
code: nil,
code: data["name"],
translations: data["translations"],
flag: data["flag"] || true,
wiki_data_id: data["wikiDataId"]