import sys,json from pathlib import Path from datetime import datetime sys.stdout.reconfigure(encoding='utf-8') sys.path.insert(0,str(Path(__file__).parent/'iqc-import-20261012/deps')) import pymysql out=Path(__file__).parent/'feedback-equipment-20261015' out.mkdir(exist_ok=True) with pymysql.connect(host='36.213.150.237',port=10000,user='root',password=sys.stdin.readline().strip(),database='mom-hm',charset='utf8mb4',connect_timeout=15,cursorclass=pymysql.cursors.DictCursor) as c: with c.cursor() as q: q.execute('SELECT DATABASE() db');assert q.fetchone()['db']=='mom-hm' q.execute('SHOW CREATE TABLE mes_pro_feedback');before=q.fetchone() (out/('schema-before-'+datetime.now().strftime('%Y%m%d%H%M%S')+'.json')).write_text(json.dumps(before,ensure_ascii=False,indent=2),encoding='utf-8') q.execute("SELECT COLUMN_NAME,DATA_TYPE,CHARACTER_MAXIMUM_LENGTH FROM information_schema.columns WHERE table_schema=DATABASE() AND table_name='mes_pro_feedback' AND column_name='machinery_ids'") column=q.fetchone() added=column is None if added: q.execute("ALTER TABLE mes_pro_feedback ADD COLUMN machinery_ids VARCHAR(2048) NULL COMMENT '首次提交时关联设备编号快照,逗号分隔;历史记录可为空'") q.execute("SELECT DATA_TYPE,CHARACTER_MAXIMUM_LENGTH,IS_NULLABLE FROM information_schema.columns WHERE table_schema=DATABASE() AND table_name='mes_pro_feedback' AND column_name='machinery_ids'") column=q.fetchone();assert column['DATA_TYPE']=='varchar' and column['CHARACTER_MAXIMUM_LENGTH']>=2048 and column['IS_NULLABLE']=='YES' q.execute('SELECT COUNT(*) total,SUM(machinery_ids IS NOT NULL) snapshots FROM mes_pro_feedback') counts={k:int(v or 0) for k,v in q.fetchone().items()} result={'database':'mom-hm','added':added,'column':column,'counts':counts,'historicalSnapshotsBackfilled':False,'equipmentStatusesModified':False} (out/'schema-result.json').write_text(json.dumps(result,ensure_ascii=False,indent=2),encoding='utf-8') print(json.dumps(result,ensure_ascii=False))