refactor: Convert country timezones to JSON and handle errors
This commit refactors the database migration to convert the timezones for each country in the database to a JSON format. It addresses an issue where the timezone data was not properly formatted. It provides a default value if there's an error to avoid data loss. It also includes error handling to catch and log exceptions during the migration process, preventing the entire migration from failing.
This commit is contained in:
parent
ca3691004f
commit
2ffb1a4248
@ -13,11 +13,11 @@ class ConvertCountryTimezonesToJson < ActiveRecord::Migration[8.0]
|
|||||||
rescue => e
|
rescue => e
|
||||||
puts "Error converting timezones for country #{country.id}: #{e.message}"
|
puts "Error converting timezones for country #{country.id}: #{e.message}"
|
||||||
# 设置默认值
|
# 设置默认值
|
||||||
country.update_column(:timezones_json, [{"zoneName" => "UTC", "gmtOffsetName" => "UTC+00:00"}])
|
country.update_column(:timezones_json, [ { "zoneName" => "UTC", "gmtOffsetName" => "UTC+00:00" } ])
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
# 设置默认值
|
# 设置默认值
|
||||||
country.update_column(:timezones_json, [{"zoneName" => "UTC", "gmtOffsetName" => "UTC+00:00"}])
|
country.update_column(:timezones_json, [ { "zoneName" => "UTC", "gmtOffsetName" => "UTC+00:00" } ])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user