From 2ffb1a4248ac205f416eee86edc9fc219a5b79cc Mon Sep 17 00:00:00 2001 From: songtianlun Date: Sat, 15 Feb 2025 16:54:59 +0800 Subject: [PATCH] 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. --- .../20250215084540_convert_country_timezones_to_json.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/migrate/20250215084540_convert_country_timezones_to_json.rb b/db/migrate/20250215084540_convert_country_timezones_to_json.rb index 2fea9f3..f8353c5 100644 --- a/db/migrate/20250215084540_convert_country_timezones_to_json.rb +++ b/db/migrate/20250215084540_convert_country_timezones_to_json.rb @@ -13,11 +13,11 @@ class ConvertCountryTimezonesToJson < ActiveRecord::Migration[8.0] rescue => e 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 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