55 lines
1.8 KiB
Python
55 lines
1.8 KiB
Python
#!/usr/bin/env python3
|
|
import pymysql
|
|
from dotenv import load_dotenv
|
|
import os
|
|
|
|
load_dotenv()
|
|
|
|
config = {
|
|
'host': os.getenv('DB_HOST'),
|
|
'user': os.getenv('DB_USER'),
|
|
'password': os.getenv('DB_PASSWORD'),
|
|
'database': os.getenv('DB_NAME'),
|
|
'port': int(os.getenv('DB_PORT', 3306)),
|
|
}
|
|
|
|
conn = pymysql.connect(**config)
|
|
cursor = conn.cursor()
|
|
|
|
# Check column type
|
|
cursor.execute("SHOW COLUMNS FROM arc_jsons WHERE Field = 'json'")
|
|
result = cursor.fetchone()
|
|
print(f"Current column type: {result[1]}")
|
|
|
|
# Check if we need to alter it
|
|
if 'text' in result[1].lower() and 'medium' not in result[1].lower() and 'long' not in result[1].lower():
|
|
print("\n⚠ Column is TEXT (max 65,535 bytes)")
|
|
print(" One file (4a21e3da.json) is ~69KB and failed to insert")
|
|
print("\nRecommended fix: ALTER TABLE arc_jsons MODIFY json MEDIUMTEXT;")
|
|
print(" MEDIUMTEXT supports up to 16MB")
|
|
|
|
response = input("\nApply fix now? (yes/no): ").strip().lower()
|
|
if response in ['yes', 'y']:
|
|
print("\nAltering column to MEDIUMTEXT...")
|
|
cursor.execute("ALTER TABLE arc_jsons MODIFY json MEDIUMTEXT")
|
|
conn.commit()
|
|
print("✓ Column altered successfully!")
|
|
|
|
# Now insert the failed record
|
|
print("\nRe-inserting failed record (4a21e3da)...")
|
|
with open('arc_data/evaluation/4a21e3da.json', 'r') as f:
|
|
json_content = f.read().strip()
|
|
|
|
cursor.execute("INSERT INTO arc_jsons (id, json) VALUES (%s, %s)", ('4a21e3da', json_content))
|
|
conn.commit()
|
|
print("✓ Record inserted successfully!")
|
|
|
|
# Final count
|
|
cursor.execute("SELECT COUNT(*) FROM arc_jsons")
|
|
count = cursor.fetchone()[0]
|
|
print(f"\n✓ Total records in database: {count}")
|
|
else:
|
|
print(f"✓ Column type is sufficient: {result[1]}")
|
|
|
|
conn.close()
|