From a23b1666d8a99503e75e995e67016ff3dd9da98c Mon Sep 17 00:00:00 2001 From: Jah Seng Lee Date: Sun, 31 Mar 2024 14:49:38 +0900 Subject: [PATCH] Safeguard rake task --- lib/tasks/countries.rake | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/tasks/countries.rake b/lib/tasks/countries.rake index 5ca0d4d..4d024d6 100644 --- a/lib/tasks/countries.rake +++ b/lib/tasks/countries.rake @@ -7,6 +7,12 @@ namespace :countries do next if country.locations.empty? if Rails.env.production? + # Skip if one already exists + next if VisaInformation.find_by( + country_id: country.id, + citizenship_id: nil + ).present? + VisaInformation.create!( country_id: country.id, citizenship_id: nil, @@ -86,6 +92,11 @@ namespace :countries do # This is a manually created list of "citzenship" countries # which will be initially excluded next if NON_SEED_CITIZENSHIPS.include?(citizenship.name) + # Skip if one already exists + next if VisaInformation.find_by( + country_id: country.id, + citizenship_id: citizenship.id + ).present? if country.id == citizenship.id VisaInformation.create!(