Skip to content

Commit d185402

Browse files
committed
fix(deploy): support legacy data layout for runtime assets
1 parent a18ca4e commit d185402

4 files changed

Lines changed: 29 additions & 7 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ jobs:
1717
cd /root/cross-subject-knowledge
1818
git pull origin main
1919
mkdir -p data/index state/logs state/cache state/tmp state/batch
20-
if [ ! -f data/textbook_chunks.index ]; then
21-
echo "ERROR: missing required runtime asset data/textbook_chunks.index"
20+
if [ ! -f data/textbook_chunks.index ] && [ ! -f data/index/textbook_chunks.index ]; then
21+
echo "ERROR: missing required runtime asset textbook_chunks.index (checked data/ and data/index/)"
2222
exit 1
2323
fi
2424
docker build -t textbook-knowledge .

backend/main.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,19 @@
3636
for d in ("logs", "cache", "tmp", "batch"):
3737
(STATE_ROOT / d).mkdir(parents=True, exist_ok=True)
3838

39-
DB_PATH = DATA_ROOT / "index/textbook_mineru_fts.db"
39+
def _resolve_data_asset(filename: str) -> Path:
40+
primary = DATA_ROOT / "index" / filename
41+
legacy = DATA_ROOT / filename
42+
if primary.exists():
43+
return primary
44+
if legacy.exists():
45+
return legacy
46+
return primary
47+
48+
49+
DB_PATH = _resolve_data_asset("textbook_mineru_fts.db")
4050
FRONTEND = Path(__file__).parent.parent / "frontend"
41-
FAISS_INDEX_PATH = DATA_ROOT / "index/textbook_chunks.index"
51+
FAISS_INDEX_PATH = _resolve_data_asset("textbook_chunks.index")
4252

4353
app = FastAPI(title="跨学科教材知识平台", version="0.1.0")
4454
app.add_middleware(CORSMiddleware, allow_origins=["*"], allow_methods=["*"], allow_headers=["*"])

backend/preflight.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@
1212
from pathlib import Path
1313

1414

15+
def _resolve_data_asset(data_root: Path, filename: str) -> Path:
16+
primary = data_root / "index" / filename
17+
legacy = data_root / filename
18+
if primary.exists():
19+
return primary
20+
if legacy.exists():
21+
return legacy
22+
return primary
23+
24+
1525
def main() -> int:
1626
project_root = Path(os.getenv("PROJECT_ROOT", Path(__file__).resolve().parents[1])).expanduser().resolve()
1727
default_data_root = project_root / "data"
@@ -26,8 +36,8 @@ def main() -> int:
2636
d.mkdir(parents=True, exist_ok=True)
2737

2838
required_files = [
29-
data_root / "index" / "textbook_mineru_fts.db",
30-
data_root / "index" / "textbook_chunks.index",
39+
_resolve_data_asset(data_root, "textbook_mineru_fts.db"),
40+
_resolve_data_asset(data_root, "textbook_chunks.index"),
3141
]
3242

3343
missing = [str(p) for p in required_files if not p.exists()]

backend/sync_db.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
if not (_DEFAULT_DATA_ROOT / "index").exists() and (_ALT_DATA_ROOT / "index").exists():
99
_DEFAULT_DATA_ROOT = _ALT_DATA_ROOT
1010
DATA_ROOT = Path(os.getenv("DATA_ROOT", _DEFAULT_DATA_ROOT)).expanduser().resolve()
11-
DB_PATH = DATA_ROOT / "index/textbook_mineru_fts.db"
11+
DB_PATH_PRIMARY = DATA_ROOT / "index" / "textbook_mineru_fts.db"
12+
DB_PATH_LEGACY = DATA_ROOT / "textbook_mineru_fts.db"
13+
DB_PATH = DB_PATH_PRIMARY if DB_PATH_PRIMARY.exists() or not DB_PATH_LEGACY.exists() else DB_PATH_LEGACY
1214

1315
def download_db():
1416
print(f"Checking for DB updates from {DB_URL}...")

0 commit comments

Comments
 (0)