1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
| import sys,json
| from pathlib import Path
| P=Path(__file__).parent
| sys.stdout.reconfigure(encoding='utf8')
| sys.path.insert(0,str(P.parent/'iqc-import-20261012/deps'))
| import pymysql
| c=pymysql.connect(host='36.213.150.237',port=10000,user='root',password=sys.stdin.readline().strip(),database='mom-hm',charset='utf8mb4',cursorclass=pymysql.cursors.DictCursor)
| s={}
| with c.cursor() as q:
| for t in ['mes_dv_machinery_type','mes_dv_machinery']:
| q.execute('SHOW CREATE TABLE '+t);ddl=q.fetchone()['Create Table'];q.execute('SELECT * FROM '+t+' WHERE deleted=0 ORDER BY id');rs=q.fetchall();s[t]={'ddl':ddl,'rows':rs}
| print(ddl)
| if t.endswith('_type'):print(json.dumps(rs,ensure_ascii=False,default=str))
| else:print(json.dumps([{k:v for k,v in x.items() if k in ['id','code','name','machinery_type_id','specification','remark','workshop_id','workstation_id']} for x in rs],ensure_ascii=False,default=str))
| q.execute("SELECT table_name,column_name FROM information_schema.columns WHERE table_schema=DATABASE() AND (column_name LIKE '%machinery_type%' OR column_name LIKE '%equipment_type%')");print('类型引用',q.fetchall())
| (P/'before.json').write_text(json.dumps(s,ensure_ascii=False,default=str,indent=2),encoding='utf8')
| c.close()
|
|