Ran for less than 5 seconds, finished .
# frozen_string_literal: true
class Maintenance::AddMissingCountriesTask < MaintenanceTasks::Task
include DatadogTrace
ALL_SCOPES_BITFIELD = (1 << 0) | (1 << 1) | (1 << 2) # gds | serving | customer_entity
# Countries added here have no DefaultGdsToCountry row, so GdsProfile creation
# during the ATOM company import would resolve a nil default GDS and fail with
# "gds must exist". Seed a default GDS alongside the country to keep imports green.
DEFAULT_GDS_NAME = 'AMADEUS'
COUNTRIES = {
'SI' => 'Slovenia',
'BY' => 'Belarus',
'GE' => 'Georgia',
'MK' => 'North Macedonia'
}.freeze
def collection
COUNTRIES.to_a
end
def process(entry)
code, display_name = entry
country = Country.find_or_create_by_code!(code)
country.update!(display_name: display_name, scopes: ALL_SCOPES_BITFIELD)
ensure_default_gds(country)
end
private
def ensure_default_gds(country)
return if country.default_gds
# Gds normalizes `name` (parameterize -> lowercase), so look up the normalized
# form; otherwise a rerun would fail the name uniqueness validation.
gds = Gds.find_or_create_by!(name: DEFAULT_GDS_NAME.downcase.strip)
country.create_default_gds_to_country!(default_gds: gds)
end
end
Processed 4 out of 4 items (100%).
Ran for less than 5 seconds, finished .
-1