init: RAG 知识库服务初始提交
- 后端 API(Flask + Gunicorn) - RAG 引擎(混合检索 + 云端 Reranker + 引用溯源) - 文档解析(MinerU + 多格式支持) - Docker 生产部署配置 - 排除前端项目、敏感配置、模型文件
This commit is contained in:
44
scripts/migrate_add_metadata.py
Normal file
44
scripts/migrate_add_metadata.py
Normal file
@@ -0,0 +1,44 @@
|
||||
"""
|
||||
数据库迁移脚本:为 messages 表添加 metadata 列
|
||||
|
||||
运行方式:
|
||||
python scripts/migrate_add_metadata.py
|
||||
"""
|
||||
|
||||
import sqlite3
|
||||
import os
|
||||
|
||||
DB_PATH = os.path.join(os.path.dirname(os.path.dirname(__file__)), "data", "rag_core.db")
|
||||
|
||||
def migrate():
|
||||
"""添加 metadata 列到 messages 表"""
|
||||
if not os.path.exists(DB_PATH):
|
||||
print(f"数据库不存在: {DB_PATH}")
|
||||
return
|
||||
|
||||
conn = sqlite3.connect(DB_PATH)
|
||||
cursor = conn.cursor()
|
||||
|
||||
try:
|
||||
# 检查列是否已存在
|
||||
cursor.execute("PRAGMA table_info(messages)")
|
||||
columns = [row[1] for row in cursor.fetchall()]
|
||||
|
||||
if 'metadata' in columns:
|
||||
print("✓ metadata 列已存在,无需迁移")
|
||||
return
|
||||
|
||||
# 添加 metadata 列
|
||||
print("正在添加 metadata 列...")
|
||||
cursor.execute("ALTER TABLE messages ADD COLUMN metadata TEXT")
|
||||
conn.commit()
|
||||
print("✓ 迁移完成!")
|
||||
|
||||
except Exception as e:
|
||||
print(f"✗ 迁移失败: {e}")
|
||||
conn.rollback()
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
if __name__ == "__main__":
|
||||
migrate()
|
||||
Reference in New Issue
Block a user