From 21920ad457b6cf58a1add772edafbbbebfaf0de3 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Sun, 16 Aug 2026 19:18:49 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20create=5Ftables.py=E5=8A=A0pipeline=5Fc?= =?UTF-8?q?ore/service=E5=B9=82=E7=AD=89=E5=BB=BA=E8=A1=A8(IF=20NOT=20EXIS?= =?UTF-8?q?TS=E4=B8=8DDROP,=E5=9B=BA=E5=8C=96skill=5Fproposals=E7=AD=89?= =?UTF-8?q?=E8=A1=A8)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/create_tables.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/scripts/create_tables.py b/scripts/create_tables.py index 661df3d..8f60728 100644 --- a/scripts/create_tables.py +++ b/scripts/create_tables.py @@ -6,7 +6,7 @@ 用法: py3/bin/python scripts/create_tables.py """ -import sys, os, asyncio, subprocess +import sys, os, re, asyncio, subprocess SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) ROOT_DIR = os.path.dirname(SCRIPT_DIR) @@ -20,6 +20,8 @@ from ahserver.serverenv import ServerEnv from ahserver.globalEnv import initEnv TABLE_MODULES = ['product_management', 'discount', 'pricing', 'unipay', 'smssend'] +# 幂等建表模块(不 DROP,用 IF NOT EXISTS,避免清空运行时数据如 llm/pipelines/skill_proposals/tasks 等) +IDEMPOTENT_MODULES = ['pipeline_core', 'pipeline-service'] # appbase 系统级配置表(幂等建表 + 默认参数,不 DROP 以免清空运行时数据) @@ -72,6 +74,26 @@ async def main(): n += 1 print(f' tables: {mod} created ({n} statements)') + # 幂等建表模块(去 DROP + IF NOT EXISTS,不清理运行时数据) + for mod in IDEMPOTENT_MODULES: + models_dir = os.path.join(ROOT_DIR, 'pkgs', mod, 'models') + if not os.path.isdir(models_dir): + print(f' skip {mod}: no models dir') + continue + r = subprocess.run([json2ddl, 'mysql', models_dir], capture_output=True, text=True) + if r.returncode != 0 or not r.stdout.strip(): + print(f' skip {mod}: json2ddl failed') + continue + n = 0 + for stmt in split_ddl(r.stdout): + s = re.sub(r'(?i)drop\s+table\s+if\s+exists\s+[\w`]+\s*;?', '', stmt) + s = re.sub(r'(?i)CREATE\s+TABLE\s+(`?\w+`?)', r'CREATE TABLE IF NOT EXISTS \1', s) + if not s.strip(): + continue + await sor.execute(s, {}) + n += 1 + print(f' tables: {mod} ensured ({n} statements, idempotent)') + # appbase params 表幂等建表 + 默认参数 try: await sor.execute(_PARAMS_DDL, {})