From febee58d0ae89660c937aba734045bb73629b348 Mon Sep 17 00:00:00 2001 From: songtianlun Date: Tue, 11 Feb 2025 10:18:24 +0800 Subject: [PATCH] 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. --- lib/tasks/sync_geo_data.rake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/tasks/sync_geo_data.rake b/lib/tasks/sync_geo_data.rake index fb0ca7f..482e191 100644 --- a/lib/tasks/sync_geo_data.rake +++ b/lib/tasks/sync_geo_data.rake @@ -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