sage_datamart/build.sh
yumoqing eccd6e8f04 feat: add models/ with 3 data mart table definitions (dm_model_call_fact, dm_model_perf_daily, dm_provider_cost_daily)
- dm_model_call_fact: LLM调用明细事实表 (23 fields)
- dm_model_perf_daily: 模型性能日汇总表 (25 fields)
- dm_provider_cost_daily: 供应商成本日汇总表 (11 fields)
- build.sh: generate DDL from models/*.json via json2ddl
- .gitignore: exclude generated mysql.ddl.sql
2026-07-20 12:58:17 +08:00

41 lines
1.0 KiB
Bash

#!/bin/bash
# Sage_datamart module build script
# Generates DDL from models and links wwwroot to Sage
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Find Sage root
SAGE_ROOT=""
for candidate in "$SCRIPT_DIR/../.." "$HOME/repos/sage" "$HOME/sage"; do
if [ -d "$candidate/wwwroot" ] && [ -d "$candidate/py3/bin" ]; then
SAGE_ROOT="$(cd "$candidate" && pwd)"
break
fi
done
if [ -z "$SAGE_ROOT" ]; then
echo "ERROR: Sage root not found"
exit 1
fi
echo "Sage root: $SAGE_ROOT"
# Generate DDL from models if present
if [ -d "$SCRIPT_DIR/models" ]; then
echo "Generating DDL from models..."
cd "$SCRIPT_DIR/models"
if ls *.json 1>/dev/null 2>&1; then
"$SAGE_ROOT/py3/bin/json2ddl" mysql . > mysql.ddl.sql
echo "DDL generated: models/mysql.ddl.sql"
fi
fi
# Link wwwroot to Sage
echo "Linking wwwroot to Sage..."
rm -f "$SAGE_ROOT/wwwroot/sage_datamart"
ln -sf "$SCRIPT_DIR/wwwroot" "$SAGE_ROOT/wwwroot/sage_datamart"
echo "[sage_datamart] build done"