Skip to content

Commit f3084e8

Browse files
committed
fix: script
1 parent 35ecca3 commit f3084e8

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

bin/scripts/sync/import_json_to_mysql.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def prepare_value(self, value: Any, field_name: str) -> Any:
161161
"""Prepare JSON value for MySQL insertion"""
162162
if value is None:
163163
# Provide default timestamp for created_at if missing (new records)
164-
# Note: updated_at is left as None so MySQL can use its DEFAULT CURRENT_TIMESTAMP
164+
# Note: updated_at is excluded from INSERT (in skip_fields) so MySQL uses DEFAULT CURRENT_TIMESTAMP
165165
if field_name == 'created_at':
166166
return datetime.now().strftime('%Y-%m-%d %H:%M:%S')
167167
return None
@@ -205,7 +205,7 @@ def import_table(self, table_name: str, json_file: str):
205205

206206
# Define fields to skip during import
207207
# These are auto-managed by MySQL or redundant relationship fields
208-
skip_fields = {'flag'} # Only flag is auto-managed; preserve created_at/updated_at from JSON
208+
skip_fields = {'flag', 'updated_at'} # flag and updated_at are auto-managed by MySQL; preserve created_at from JSON
209209
if table_name == 'cities':
210210
skip_fields.update({'country_name', 'state_name'})
211211
elif table_name == 'states':
@@ -333,7 +333,7 @@ def import_cities(self):
333333

334334
# Define fields to skip during import
335335
# These are auto-managed by MySQL or redundant relationship fields
336-
skip_fields = {'flag', 'country_name', 'state_name'} # Only flag is auto-managed; preserve created_at/updated_at from JSON
336+
skip_fields = {'flag', 'updated_at', 'country_name', 'state_name'} # flag and updated_at are auto-managed by MySQL; preserve created_at from JSON
337337

338338
# Build final insert column list:
339339
# Include all columns from database except skip_fields

0 commit comments

Comments
 (0)