def parse_pg_table(file_path, output_file): current_table = None with open(file_path, 'r', encoding='utf-8') as f: lines = f.readlines() for line in lines: line = line.strip() if not line or 'table_name' in line or 'column_name' in line: continue parts = [p.strip() for p in line.split('|')] if len(parts) < 4: continue table_name, column_name, data_type, is_nullable = parts[:4] if table_name != current_table: if current_table is not None: output_file.write('\n') output_file.write(f'### {table_name}\n') output_file.write('【表用途注释:】\n') output_file.write('| 字段名 | 数据类型 | 注释 |\n') output_file.write('|--------|----------|------|\n') current_table = table_name output_file.write(f'| {column_name} | {data_type} | |\n') def parse_mysql_table(file_path, output_file): current_table = None with open(file_path, 'r', encoding='utf-8') as f: lines = f.readlines() for line in lines: line = line.strip() if not line or 'TABLE_NAME' in line or 'COLUMN_NAME' in line: continue parts = [p.strip() for p in line.split('\t')] if len(parts) < 4: continue table_name, column_name, data_type, is_nullable = parts[:4] if table_name != current_table: if current_table is not None: output_file.write('\n') output_file.write(f'### {table_name}\n') output_file.write('【表用途注释:】\n') output_file.write('| 字段名 | 数据类型 | 注释 |\n') output_file.write('|--------|----------|------|\n') current_table = table_name output_file.write(f'| {column_name} | {data_type} | |\n') with open('/root/.openclaw/workspace/数据库表结构总览_完整版.md', 'w', encoding='utf-8') as f: f.write('# 瓦拉英语业务数据库表结构总览(完整版)\n') f.write('## 使用说明\n') f.write('- 每个表开头的【表用途注释】行可填写该表的业务用途说明\n') f.write('- 每个字段的【注释】列可填写该字段的业务含义说明\n') f.write('- 所有空注释位置均可直接编辑补充\n') f.write('---\n') f.write('## 一、线上PostgreSQL库(正式环境用户行为数据)\n') f.write('- **地址:** bj-postgres-16pob4sg.sql.tencentcdb.com:28591\n') f.write('- **库名:** vala_bi\n') f.write('- **权限:** 只读\n') f.write('---\n') parse_pg_table('/root/.openclaw/workspace/pg_online_full.txt', f) f.write('\n---\n') f.write('## 二、测试PostgreSQL库(测试环境行为数据)\n') f.write('- **地址:** bj-postgres-642mcico.sql.tencentcdb.com:21531\n') f.write('- **库名:** vala_bi\n') f.write('- **权限:** 只读\n') f.write('---\n') parse_pg_table('/root/.openclaw/workspace/pg_test_full.txt', f) f.write('\n---\n') f.write('## 三、线上MySQL库(线上版本配置/订单/用户数据)\n') f.write('- **地址:** bj-cdb-dh2fkqa0.sql.tencentcdb.com:27751\n') f.write('- **权限:** 只读\n') f.write('---\n') parse_mysql_table('/root/.openclaw/workspace/mysql_online_full.txt', f) f.write('\n---\n') f.write('## 四、测试MySQL库(测试环境配置/用户数据)\n') f.write('- **地址:** bj-cdb-8frbdwju.sql.tencentcdb.com:25413\n') f.write('- **权限:** 只读\n') f.write('---\n') parse_mysql_table('/root/.openclaw/workspace/mysql_test_full.txt', f) f.write('\n---\n') f.write('## 五、线上Elasticsearch(正式环境服务日志)\n') f.write('- **地址:** es-7vd7jcu9.public.tencentelasticsearch.com:9200\n') f.write('- **协议:** https\n') f.write('- **权限:** 只读\n') f.write('【说明:】ES为日志存储,索引结构可根据查询需求单独补充说明\n') f.write('---\n') f.write('## 六、测试Elasticsearch(测试环境服务日志)\n') f.write('- **地址:** es-o79jsx9i.public.tencentelasticsearch.com:9200\n') f.write('- **协议:** https\n') f.write('- **权限:** 只读\n') f.write('【说明:】ES为日志存储,索引结构可根据查询需求单独补充说明\n') print('生成完成!')