From 14991af1bf99276cfbf81bb9fb76662e83a50712 Mon Sep 17 00:00:00 2001 From: Xin Wang Date: Thu, 12 Feb 2026 18:51:27 +0800 Subject: [PATCH] Clean migrate code in init db --- api/init_db.py | 36 +----------------------------------- 1 file changed, 1 insertion(+), 35 deletions(-) diff --git a/api/init_db.py b/api/init_db.py index 2eff147..07e91c6 100644 --- a/api/init_db.py +++ b/api/init_db.py @@ -4,7 +4,6 @@ import argparse import os import sys from contextlib import contextmanager -from sqlalchemy import inspect, text # 添加路径 sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) @@ -57,39 +56,6 @@ def init_db(): print("✅ 数据库表创建完成") -def migrate_db_schema(): - """对现有数据库执行非破坏性 schema 迁移。""" - inspector = inspect(engine) - table_names = set(inspector.get_table_names()) - if "assistants" not in table_names: - print("ℹ️ assistants 表不存在,跳过增量迁移") - return - - columns = {col["name"] for col in inspector.get_columns("assistants")} - alter_statements = [] - if "generated_opener_enabled" not in columns: - alter_statements.append( - "ALTER TABLE assistants ADD COLUMN generated_opener_enabled BOOLEAN DEFAULT 0" - ) - if "first_turn_mode" not in columns: - alter_statements.append( - "ALTER TABLE assistants ADD COLUMN first_turn_mode VARCHAR(32) DEFAULT 'bot_first'" - ) - if "bot_cannot_be_interrupted" not in columns: - alter_statements.append( - "ALTER TABLE assistants ADD COLUMN bot_cannot_be_interrupted BOOLEAN DEFAULT 0" - ) - - if not alter_statements: - print("✅ Schema 迁移检查完成(无需变更)") - return - - with engine.begin() as conn: - for stmt in alter_statements: - conn.execute(text(stmt)) - print(f"✅ Schema 迁移完成(应用 {len(alter_statements)} 条 ALTER)") - - def rebuild_vector_store(reset_doc_status: bool = True): """重建知识库向量集合(按 DB 中的 KB 列表重建 collection 壳)。""" from app.vector_store import vector_store @@ -400,7 +366,7 @@ if __name__ == "__main__": if args.rebuild_db: init_db() else: - migrate_db_schema() + print("ℹ️ 跳过数据库结构变更(未指定 --rebuild-db)") if args.recreate_tool_db: init_default_tools(recreate=True)