_diff_tables.py 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import pymysql
  2. from pathlib import Path
  3. planned = {
  4. 'ado_intg_system','ado_intg_connector','ado_intg_field_mapping','ado_intg_code_mapping','ado_intg_sync_checkpoint','ado_intg_event_raw',
  5. 'ado_md_customer','ado_md_supplier','ado_md_item','ado_md_work_center','ado_md_process_route','ado_md_process_route_step','ado_md_calendar',
  6. 'ado_s1_sales_order','ado_s1_sales_order_line','ado_s1_delivery_promise','ado_s1_delivery_change',
  7. 'ado_s2_mps_plan','ado_s2_work_order','ado_s2_work_order_op','ado_s2_capacity_snapshot',
  8. 'ado_s3_mrp_result','ado_s3_material_kit_status','ado_s3_supplier_delivery_perf',
  9. 'ado_s4_purchase_order','ado_s4_purchase_order_line','ado_s4_receipt','ado_s4_return',
  10. 'ado_s5_inventory_balance','ado_s5_inventory_txn','ado_s5_iqc_result',
  11. 'ado_s6_report_work','ado_s6_ipqc_result','ado_s6_equipment_oee',
  12. 'ado_s7_fg_inbound','ado_s7_fg_outbound','ado_s7_oqc_result','ado_s7_trace_serial',
  13. 'ado_s8_rule_model','ado_s8_rule_condition','ado_s8_rule_scope','ado_s8_alert_model','ado_s8_alert_channel','ado_s8_alert_record',
  14. 'ado_s8_incident','ado_s8_incident_dispatch','ado_s8_incident_action','ado_s8_incident_verify','ado_s8_rule_eval_log','ado_s8_rule_hit_fact',
  15. 'ado_s9_kpi_def','ado_s9_kpi_relation','ado_s9_kpi_page_binding','ado_s9_kpi_formula','ado_s9_kpi_value_l1_day','ado_s9_kpi_value_l2_day','ado_s9_kpi_value_l3_day',
  16. 'ado_s9_dashboard_snapshot','ado_s9_drilldown_cache','ado_s9_calc_task','ado_s9_calc_log','ado_s9_chatbi_semantic','ado_s9_chatbi_query_log',
  17. 'ado_mobile_kpi_snapshot','ado_mobile_sync_cursor','ado_mobile_alert_ack','ado_mobile_incident_action'
  18. }
  19. conn = pymysql.connect(host='106.14.73.46', port=3306, user='aidopremote', password='AidOp#Remote2026$Secure', charset='utf8mb4', autocommit=True)
  20. try:
  21. with conn.cursor() as cur:
  22. cur.execute("SELECT table_name FROM information_schema.tables WHERE table_schema='aidopcore' AND table_name LIKE 'ado\\_%'")
  23. existing = {r[0] for r in cur.fetchall()}
  24. finally:
  25. conn.close()
  26. extra = sorted(existing - planned)
  27. missing = sorted(planned - existing)
  28. matched = sorted(existing & planned)
  29. out = Path(r'd:/Projects/Ai-DOP/SourceCode/ai-dop-platform/docs/db/aidopcore_新增与历史表差异清单.md')
  30. with out.open('w', encoding='utf-8') as f:
  31. f.write('# aidopcore 新增与历史表差异清单\n\n')
  32. f.write(f'- 方案目标表数: {len(planned)}\n')
  33. f.write(f'- 远端 ado_* 实际表数: {len(existing)}\n')
  34. f.write(f'- 命中方案表数: {len(matched)}\n')
  35. f.write(f'- 额外历史表数: {len(extra)}\n')
  36. f.write(f'- 缺失方案表数: {len(missing)}\n\n')
  37. f.write('## 额外历史表(非本次方案)\n')
  38. if extra:
  39. for t in extra:
  40. f.write(f'- `{t}`\n')
  41. else:
  42. f.write('- 无\n')
  43. f.write('\n## 缺失方案表\n')
  44. if missing:
  45. for t in missing:
  46. f.write(f'- `{t}`\n')
  47. else:
  48. f.write('- 无\n')
  49. f.write('\n## 已命中方案表\n')
  50. for t in matched:
  51. f.write(f'- `{t}`\n')
  52. print(out)
  53. print('extra=', len(extra), 'missing=', len(missing), 'matched=', len(matched))