From 4c9868a5d921d82abd363fc231e71fa1801b949e Mon Sep 17 00:00:00 2001 From: vipg Date: Fri, 26 Dec 2025 16:40:20 +0800 Subject: [PATCH] add --- create/create_table.py | 27 +++++++++----------------- infra/postgres/sql/03_create_table.sql | 5 ----- 2 files changed, 9 insertions(+), 23 deletions(-) diff --git a/create/create_table.py b/create/create_table.py index ef40240..184f8fe 100644 --- a/create/create_table.py +++ b/create/create_table.py @@ -7,8 +7,8 @@ create.py - 动态生成PostgreSQL建表SQL语句 import os import re -# 从环境变量获取表名,如果没有设置则使用默认值 -table_name = os.environ.get('TABLE_NAME', 'cn_pmi_234_aaarecords') +# 1. 定义表名称变量,方便调整 +table_name = "cn_pmi_records" # 可以根据需要修改表名 # 2. 定义SQL模板 sql_template = f"""DO $$ @@ -69,23 +69,16 @@ def update_sql_file(): with open(sql_file_path, 'r', encoding='utf-8') as f: content = f.read() - # 查找插入位置:在"部署开始"和"部署完成"之间插入 - # 更简单的模式匹配 - start_pattern = r"(DO \$\$.*?RAISE NOTICE '🚀============ 数据库表部署开始 ============🚀'.*?END \$\$;)" - end_pattern = r"(DO \$\$.*?RAISE NOTICE '✅============ 数据库表部署完成 ============✅'.*?END \$\$;)" + # 查找插入位置(在\"部署完成\"日志前) + insert_pattern = r'(DO \$\$.*?RAISE NOTICE \'🚀============ 数据库表部署开始 ============🚀\'.*?END \$\$;)(.*?)(DO \$\$.*?RAISE NOTICE \'✅============ 数据库表部署完成 ============✅\'.*?END \$\$;)' - start_match = re.search(start_pattern, content, re.DOTALL) - end_match = re.search(end_pattern, content, re.DOTALL) + match = re.search(insert_pattern, content, re.DOTALL) - if start_match and end_match: - # 获取开始和结束位置 - start_end_pos = start_match.end() - end_start_pos = end_match.start() - + if match: # 分割内容 - before_insert = content[:start_end_pos] - existing_middle = content[start_end_pos:end_start_pos] - after_insert = content[end_start_pos:] + before_insert = match.group(1) + existing_middle = match.group(2) + after_insert = match.group(3) # 规范化空行 existing_middle = normalize_blank_lines(existing_middle) @@ -106,8 +99,6 @@ def update_sql_file(): else: print("❌ 无法找到插入位置,请检查文件格式") - print(f"调试信息 - 开始模式匹配: {bool(start_match)}") - print(f"调试信息 - 结束模式匹配: {bool(end_match)}") except FileNotFoundError: print(f"❌ 文件 {sql_file_path} 不存在") diff --git a/infra/postgres/sql/03_create_table.sql b/infra/postgres/sql/03_create_table.sql index e01f291..0bca33c 100644 --- a/infra/postgres/sql/03_create_table.sql +++ b/infra/postgres/sql/03_create_table.sql @@ -31,11 +31,6 @@ BEGIN END IF; END $$; -DO $$ -BEGIN - RAISE NOTICE '🚀============ 数据库表部署开始 ============🚀'; -END $$; - DO $$ BEGIN RAISE NOTICE '✅============ 数据库表部署完成 ============✅';