gaoluyang
14 小时以前 e40a608ef9bf51db294d8eefada6a8e2e80cebca
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import sys,json
from pathlib import Path
P=Path(__file__).parent
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,connect_timeout=10,read_timeout=60)
s={}
with c.cursor() as q:
    q.execute('SELECT DATABASE() db');assert q.fetchone()['db']=='mom-hm'
    for t in ['mes_md_product_bom','mes_md_item','mdm_item','mes_md_item_type','mdm_unit','mes_pro_route','mes_pro_route_process','mes_pro_route_product','mes_pro_route_product_bom']:
        q.execute('SELECT COUNT(*) n FROM information_schema.tables WHERE table_schema=DATABASE() AND table_name=%s',(t,))
        if not q.fetchone()['n']:continue
        q.execute('SHOW CREATE TABLE '+t);s[t+'_schema']=q.fetchone()
        q.execute('SELECT * FROM '+t+' WHERE deleted=0');s[t]=list(q.fetchall())
c.close()
(P/'before-binding-snapshot.json').write_text(json.dumps(s,ensure_ascii=False,default=str,indent=2),encoding='utf8')
print(json.dumps({k:len(v) for k,v in s.items() if isinstance(v,list)},ensure_ascii=False))
print(s['mes_md_product_bom_schema']['Create Table'])
print(json.dumps(s['mes_md_product_bom'][:5],ensure_ascii=False,default=str))