This commit is contained in:
vipg
2025-12-26 16:40:20 +08:00
parent 17f9c1e90f
commit 4c9868a5d9
2 changed files with 9 additions and 23 deletions

View File

@@ -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)
if start_match and end_match:
# 获取开始和结束位置
start_end_pos = start_match.end()
end_start_pos = end_match.start()
match = re.search(insert_pattern, content, re.DOTALL)
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} 不存在")

View File

@@ -31,11 +31,6 @@ BEGIN
END IF;
END $$;
DO $$
BEGIN
RAISE NOTICE '🚀============ 数据库表部署开始 ============🚀';
END $$;
DO $$
BEGIN
RAISE NOTICE '✅============ 数据库表部署完成 ============✅';