From 31ba0014822fb97abacfa19174a0732ac9a03c6e Mon Sep 17 00:00:00 2001 From: ymq Date: Tue, 18 Aug 2026 16:02:19 +0800 Subject: [PATCH] =?UTF-8?q?refactor(init):=20=E7=A7=BB=E9=99=A4=20=5Finit?= =?UTF-8?q?=5Fv2=5Ftables=20=E5=90=AF=E5=8A=A8=E6=9C=9F=E5=BB=BA=E8=A1=A8/?= =?UTF-8?q?=E5=8A=A0=E5=88=97=EF=BC=8Cschema=20=E5=8F=98=E6=9B=B4=E7=BB=9F?= =?UTF-8?q?=E4=B8=80=E8=B5=B0=E9=83=A8=E7=BD=B2=E6=9C=9F=20create=5Ftables?= =?UTF-8?q?.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pipeline_service/init.py | 71 ++-------------------------------------- 1 file changed, 2 insertions(+), 69 deletions(-) diff --git a/pipeline_service/init.py b/pipeline_service/init.py index bb78b56..db25766 100644 --- a/pipeline_service/init.py +++ b/pipeline_service/init.py @@ -787,75 +787,8 @@ def load_pipeline_service(): add_startup(_failed_poller) - # v2 DDL auto-init: create tables and columns at startup - async def _init_v2_tables(app): - from sqlor.dbpools import DBPools as _DBP2 - from appPublic.log import debug as _debug - try: - _db = _DBP2() - async with _db.sqlorContext("pipeline") as sor: - await sor.sqlExe( - "CREATE TABLE IF NOT EXISTS pipeline_user_memory (" - "id varchar(32) NOT NULL, memory_key varchar(64) NOT NULL," - "content text NOT NULL, category varchar(32) NOT NULL DEFAULT 'memory'," - "priority int NOT NULL DEFAULT 0, access_count int NOT NULL DEFAULT 0," - "created_at datetime NOT NULL DEFAULT CURRENT_TIMESTAMP," - "updated_at datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP," - "PRIMARY KEY (id), UNIQUE KEY uk_memory (memory_key, category)," - "KEY idx_category_priority (category, priority)" - ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", {}) - _debug("pipeline_user_memory table ready") - # 应用部署主机逻辑账号表 - await sor.sqlExe( - "CREATE TABLE IF NOT EXISTS sd_deploy_accounts (" - "id varchar(32) NOT NULL, user_id varchar(32) NOT NULL," - "account_name varchar(64) NOT NULL, deploy_dir varchar(500) NOT NULL," - "status varchar(20) NOT NULL DEFAULT 'active'," - "sandbox_config text," - "created_at datetime NOT NULL DEFAULT CURRENT_TIMESTAMP," - "updated_at datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP," - "PRIMARY KEY (id), UNIQUE KEY uk_account_name (account_name)," - "UNIQUE KEY uk_user_id (user_id), KEY idx_status (status)" - ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", {}) - _debug("sd_deploy_accounts table ready") - # 工作环境表(沙箱本地/远程切换) - await sor.sqlExe( - "CREATE TABLE IF NOT EXISTS sd_work_envs (" - "id varchar(32) NOT NULL, owner_type varchar(10) NOT NULL," - "owner_id varchar(32) NOT NULL, mode varchar(10) NOT NULL DEFAULT 'local'," - "remote_host varchar(200), remote_port int DEFAULT 22," - "remote_user varchar(100), remote_key_path varchar(500), remote_dir varchar(500)," - "created_at datetime NOT NULL DEFAULT CURRENT_TIMESTAMP," - "updated_at datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP," - "PRIMARY KEY (id), UNIQUE KEY uk_owner (owner_type, owner_id)" - ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", {}) - _debug("sd_work_envs table ready") - # agent_config columns - try: - await sor.sqlExe("ALTER TABLE pipelines ADD COLUMN agent_config text", {}) - _debug("pipelines.agent_config column added") - except Exception: - pass - try: - await sor.sqlExe("ALTER TABLE sd_org_settings ADD COLUMN agent_config text", {}) - _debug("sd_org_settings.agent_config column added") - except Exception: - pass - # failed 任务重试计数 + 失败原因 - try: - await sor.sqlExe("ALTER TABLE pipeline_tasks ADD COLUMN retry_count int NOT NULL DEFAULT 0", {}) - _debug("pipeline_tasks.retry_count column added") - except Exception: - pass - try: - await sor.sqlExe("ALTER TABLE pipeline_tasks ADD COLUMN last_error text", {}) - _debug("pipeline_tasks.last_error column added") - except Exception: - pass - except Exception as e: - _debug(f"v2 DDL init: {e}") - - add_startup(_init_v2_tables) + # 铁律:运行期不做任何 schema 变更。v2 引擎的建表/加列已全部迁到 + # 部署期 scripts/create_tables.py(build.sh 会调用),此处不再启动时建表。 debug(f"[{MODULE_NAME}] v{MODULE_VERSION} loaded — pipeline engine with role-agent + question loop") return True