#!/bin/bash
# =============================================================================
# 步骤 2：将全量 kg_snapshot.json 导入迁移目标机的 Neo4j
# 在【迁移目标机】上执行本脚本
# 配置项请修改 migration_config.sh
# =============================================================================

SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
source "${SCRIPT_DIR}/migration_config.sh"

SNAPSHOT_PATH="${DST_CODE_DIR}/kg_snapshot.json"
PYTHON="docker exec ${KGRAG_CONTAINER} python3"

set -e

echo "=========================================="
echo "  kgrag Neo4j 导入脚本 - 步骤 2（全量）"
echo "  快照文件: ${SNAPSHOT_PATH}"
echo "=========================================="

if [ ! -f "${SNAPSHOT_PATH}" ]; then
    echo "错误：快照文件不存在: ${SNAPSHOT_PATH}"
    echo "请先执行步骤 1 迁移文件。"
    exit 1
fi

echo ""
echo "快照文件大小: $(du -sh ${SNAPSHOT_PATH} | cut -f1)"
echo ""

cd "${DST_CODE_DIR}"
${PYTHON} ${CONTAINER_APP_DIR}/batch_kg_build.py \
    --phase load_snapshot \
    --snapshot_path "${CONTAINER_APP_DIR}/kg_snapshot.json"

echo ""
echo "=========================================="
echo "  Neo4j 导入完成！"
echo "  下一步：执行 bash 02b_rebuild_index.sh"
echo "=========================================="
