fix: correct state syncing logic

- Change output to include country name during state syncing
- Update record creation from `find_or_initialize_by!` to `find_or_create_by!`

This fix ensures that when syncing state data, the output provides
better context by showing the associated country name, and it also
ensures that states are created if they do not already exist, thus
eliminating potential issues with duplicate state entries.
This commit is contained in:
songtianlun 2025-02-11 10:18:24 +08:00
parent f67ff92ba8
commit febee58d0a

View File

@ -122,10 +122,10 @@ namespace :geo do
count = 1
states.each do |data|
puts "Syncing State[#{count}/#{sum}] [#{data["name"]}] "
puts "Syncing State[#{count}/#{sum}] [#{data["name"]}] country:[#{data["country_name"]}]"
count += 1
state = State.find_or_initialize_by!(name: data["name"]) do |s|
state = State.find_or_create_by!(name: data["name"]) do |s|
s.country_id = data["country_id"]
end