This commit is contained in:
runny committed 2026-05-12 19:53:10 +08:00
1 parent 10d0f5bad8
commit fcb70b85f4
3 files changed
+40 -13

No files matched your search

+5 -4
View File
@@ -1,4 +1,4 @@
FROM python:3.12-slim-bookworm FROM python:3.12-slim-bookworm
WORKDIR /app WORKDIR /app
@@ -10,11 +10,12 @@ RUN apt-get update \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
# Install Python dependencies # Install Python dependencies
COPY requirements.txt . COPY backend/requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt RUN pip install --no-cache-dir -r requirements.txt
# Copy application code # Copy backend code and bundled Text2SQL schema docs
COPY . . COPY backend/ .
COPY docs /app/docs
ENV ORACLE_HOME=/app/oracle_client/instantclient_19_31 ENV ORACLE_HOME=/app/oracle_client/instantclient_19_31
ENV LD_LIBRARY_PATH=/app/oracle_client/instantclient_19_31:/app/oracle_client:${LD_LIBRARY_PATH} ENV LD_LIBRARY_PATH=/app/oracle_client/instantclient_19_31:/app/oracle_client:${LD_LIBRARY_PATH}
+32 -6
View File
@@ -154,15 +154,41 @@ class Text2SQLService:
@classmethod @classmethod
def get_schema(cls): def get_schema(cls):
if cls._schema_text is None: if cls._schema_text is None:
schema_filename = '(表+字段).md'
env_path = (os.getenv("TEXT2SQL_SCHEMA_PATH") or "").strip()
candidate_paths = []
if env_path:
candidate_paths.append(env_path)
candidate_paths.extend([
os.path.join(cls._backend_dir(), 'docs', schema_filename),
os.path.join(cls._project_root(), 'docs', schema_filename),
os.path.join(os.getcwd(), 'docs', schema_filename),
])
unique_paths = []
seen = set()
for path in candidate_paths:
normalized = os.path.normpath(path)
if normalized not in seen:
seen.add(normalized)
unique_paths.append(path)
for doc_path in unique_paths:
try: try:
# docs is at the project root: c:\Users\PC\Desktop\HX工作目录\hxops\hxops\docs if not os.path.exists(doc_path):
# This file is in backend/app/services/text2sql.py continue
base_dir = cls._project_root()
doc_path = os.path.join(base_dir, 'docs', '(表+字段).md')
with open(doc_path, 'r', encoding='utf-8') as f: with open(doc_path, 'r', encoding='utf-8') as f:
cls._schema_text = f.read() cls._schema_text = f.read()
except Exception as e: cls._log("info", f"Loaded Text2SQL schema from {doc_path}")
cls._schema_text = f"Failed to load schema: {e}" break
except Exception as exc:
cls._log("warning", f"Failed to load Text2SQL schema from {doc_path}: {exc}")
if cls._schema_text is None:
tried = ", ".join(unique_paths)
cls._schema_text = f"Failed to load schema: schema file not found. Tried: {tried}"
cls._log("warning", cls._schema_text)
return cls._schema_text return cls._schema_text
@staticmethod @staticmethod
+3 -3
View File
@@ -1,12 +1,12 @@
services: services:
# ============================================================================== # ==============================================================================
# hxops-backend: Flask 后端服务 (端口: 5000) # hxops-backend: Flask 后端服务 (端口: 5000)
# ============================================================================== # ==============================================================================
hxops-backend: hxops-backend:
image: ${BACKEND_IMAGE:-hxops-backend:local} image: ${BACKEND_IMAGE:-hxops-backend:local}
build: build:
context: ./backend context: .
dockerfile: Dockerfile dockerfile: backend/Dockerfile
container_name: hxops-backend container_name: hxops-backend
restart: always restart: always
# 与 scripts/deploy_compose.sh 使用的 .env.<ENV_NAME> 对齐(通过 COMPOSE_ENV_BASENAME) # 与 scripts/deploy_compose.sh 使用的 .env.<ENV_NAME> 对齐(通过 COMPOSE_ENV_BASENAME)